AnsweredAssumed Answered

How to use Shared FLAT with pthread ?

Question asked by ronaldo-moura on Apr 1, 2013
Latest reply on May 3, 2013 by Aaronwu

Hi,

 

  I need to create a shared flat library.  I  successfully created a shared flat following the instructions in http://docs.blackfin.uclinux.org/doku.php?id=toolchain:creating_libraries .

 

  But a "null pointer" occurs in pthread_create() if I compile any codes with Shared FLAT flag -mid-shared-library.  This problem does not occur with static flat.

 

  Inspecting the uClibc/libpthead source i found  the problem in line 545 of pthread.c: __pthread_initialize_manager() .  The code   *__libc_multiple_threads_ptr = 1;   set an uninitialized variable.     A similar problem was reported in http://lists.uclibc.org/pipermail/uclibc/2009-October/043120.html

 

   I 'm using the following distribution files and versions:

* blackfin-linux-dist-2011R1-RC3.tar.bz2

* blackfin-toolchain-2011R1-RC4.i386.tar.bz2,

* blackfin-toolchain-uclibc-full-2011R1-RC4.i386.tar.bz2.

* uClinux Version =  Linux blackfin 3.0.8-ADI-2011R1

* gcc Version = bfin-uclinux-gcc (ADI-2011R1-RC4) 4.3.5

 

 

The commands to replicate the problem:

 

1) Sample code thread.c

#include <stdio.h>

#include <pthread.h>

 

void * run (void * arg) {

   fprintf(stderr,"Thread running\n");

   return 0;

}

 

int main() {

   pthread_t th;

   pthread_create(&th,NULL,run,NULL);

   pthread_join(th,NULL);

   return 0;

}

 

 

2) Static Flat. Runs correctly

$ bfin-uclinux-gcc  thread.c -o thread_static -lpthread

$ bfin-uclinux-flthdr thread_static

Magic:        bFLT

    Rev:          4

    Build Date:   Mon Apr  1 21:23:20 2013

    Entry:        0x44

    Data Start:   0xe100

    Data End:     0x105c4

    BSS End:      0x16c60

    Stack Size:   0x1000

    Reloc Start:  0x105c4

    Reloc Count:  0x6d9

    Flags:        0x1 ( Load-to-Ram )

 

root:/> ./thread_static

 

Thread running

 

3) Shared Flat (depends on /lib/lib1.so), results in "Null Pointer"  reported below

$ bfin-uclinux-gcc  thread.c -o  thread_shared -lpthread  -mid-shared-library

$ bfin-uclinux-flthdr thread_shared
thread_shared
Magic:        bFLT
Rev:          4
Build Date:   Mon Apr  1 21:24:11 2013
Entry:        0x44
Data Start:   0x4400
Data End:     0x4d00
BSS End:      0xaec0
Stack Size:   0x1000
Reloc Start:  0x4d00
Reloc Count:  0x39
Flags:        0x2 ( Has-PIC-GOT )

 

 

root:/> ./thread_shared

NULL pointer access

Deferred Exception context

CURRENT PROCESS:

COMM=thread_shared PID=428  CPU=0

TEXT = 0x02930040-0x029343a0        DATA = 0x02b50020-0x02b508c0

BSS = 0x02b508c0-0x02b56a80  USER-STACK = 0x02b57f40

 

return address: [0x02932d9e]; contents of:

0x02932d70:  6008  6002  0062  e52a  00c4  e428  002b  6001

0x02932d80:  0062  e801  0000  05ab  0010  0000  05fb  e800

0x02932d90:  002b  e52d  ffff  6008  e52a  002f  9152 [9310]

0x02932da0:  e52a  008f  9110  0c00  1404  e52a  002c  0062

 

ADSP-BF537-0.3 500(MHz CCLK) 125(MHz SCLK) (mpu off)

Linux version 3.0.8-ADI-2011R1 (ronaldo@pulse) (gcc version 4.3.5 (ADI-2011R1-RC4) ) #684 Mon Apr 1 17:42:03 BRT 2013

 

SEQUENCER STATUS:               Not tainted

SEQSTAT: 00060027  IPEND: 0008  IMASK: ffff  SYSCFG: 0006

  EXCAUSE   : 0x27

  physical IVG3 asserted : <0x0000a6b0> { _trap + 0x0 }

RETE: <0x00000000> /* Maybe null pointer? */

RETN: <0x0295a000> /* kernel dynamic memory */

RETX: <0x00000480> /* Maybe fixed code section */

RETS: <0x02932f7c> [ /thread_shared + 0x2f3c ]

PC  : <0x02932d9e> [ /thread_shared + 0x2d5e ]

DCPLB_FAULT_ADDR: <0x00000000> /* Maybe null pointer? */

ICPLB_FAULT_ADDR: <0x02932d9e> [ /thread_shared + 0x2d5e ]

PROCESSOR STATE:

R0 : 00000001    R1 : 00000000    R2 : 0293014c    R3 : 02932f5c

R4 : 00000000    R5 : 02b57eec    R6 : 0293014c    R7 : 00000000

P0 : 02ac4d08    P1 : 02ac75c8    P2 : 00000000    P3 : 02b57f48

P4 : 00000001    P5 : 02b50020    FP : 02b57e04    SP : 02959f24

LB0: 0281402d    LT0: 0281402c    LC0: 00000000

LB1: 02822463    LT1: 02822458    LC1: 00000000

B0 : 00000000    L0 : 00000000    M0 : 00000001    I0 : 02ac4d08

B1 : 02919a1b    L1 : 00000000    M1 : 00000000    I1 : 029886e0

B2 : 00000000    L2 : 00000000    M2 : 00000000    I2 : 00000000

B3 : 00000000    L3 : 00000000    M3 : 00000000    I3 : 00000001

A0.w: 00000000   A0.x: 00000000   A1.w: 00000000   A1.x: 00000000

USP : 02b57d58  ASTAT: 02001026

 

Hardware Trace:

   0 Target : <0x000042ac> { _trap_c + 0x0 }

     Source : <0x0000a644> { _exception_to_level5 + 0xa4 } JUMP.L

   1 Target : <0x0000a5a0> { _exception_to_level5 + 0x0 }

     Source : <0x0000a454> { _bfin_return_from_exception + 0x18 } RTX

   2 Target : <0x0000a43c> { _bfin_return_from_exception + 0x0 }

     Source : <0x0000a4f8> { _ex_trap_c + 0x74 } JUMP.S

   3 Target : <0x0000a484> { _ex_trap_c + 0x0 }

     Source : <0x0000a70a> { _trap + 0x5a } JUMP (P4)

   4 Target : <0x0000a6b0> { _trap + 0x0 }

      FAULT : <0x02932d9e> [ /thread_shared + 0x2d5e ] [P2] = R0

     Source : <0x02932d9c> [ /thread_shared + 0x2d5c ] P2 = [P2]

   5 Target : <0x02932d8c> [ /thread_shared + 0x2d4c ]

     Source : <0x02932f7a> [ /thread_shared + 0x2f3a ] CALL (P2)

   6 Target : <0x02932f5c> [ /thread_shared + 0x2f1c ]

     Source : <0x0293019e> [ /thread_shared + 0x15e ] CALL (P2)

   7 Target : <0x0293017c> [ /thread_shared + 0x13c ]

     Source : <0x02826bd2> [ /lib/lib1.so + 0x26bd2 ] CALL (P2)

   8 Target : <0x02826bc0> [ /lib/lib1.so + 0x26bc0 ]

     Source : <0x02806258> [ /lib/lib1.so + 0x6258 ] RTS

   9 Target : <0x02806244> [ /lib/lib1.so + 0x6244 ]

     Source : <0x02826bbe> [ /lib/lib1.so + 0x26bbe ] CALL (P2)

  10 Target : <0x02826bb0> [ /lib/lib1.so + 0x26bb0 ]

     Source : <0x02806240> [ /lib/lib1.so + 0x6240 ] RTS

  11 Target : <0x0280622c> [ /lib/lib1.so + 0x622c ]

     Source : <0x02826bae> [ /lib/lib1.so + 0x26bae ] CALL (P2)

  12 Target : <0x02826ba6> [ /lib/lib1.so + 0x26ba6 ]

     Source : <0x02826c36> [ /lib/lib1.so + 0x26c36 ] RTS

  13 Target : <0x02826c24> [ /lib/lib1.so + 0x26c24 ]

     Source : <0x02826c1c> [ /lib/lib1.so + 0x26c1c ] JUMP.S

  14 Target : <0x02826c16> [ /lib/lib1.so + 0x26c16 ]

     Source : <0x0293437c> [ /thread_shared + 0x433c ] RTS

  15 Target : <0x02934376> [ /thread_shared + 0x4336 ]

     Source : <0x02934344> [ /thread_shared + 0x4304 ] RTS

Userspace Stack

Stack info:

SP: [0x02b57d58] <0x02b57d58> [ thread_shared + 0x7d58 ]

FP: (0x02b57e04)

Memory from 0x02b57d50 to 02b58000

02b57d50: 00000000  00000000 [00000000] 00000000  00000000  00000000  00000000  00000000

02b57d70: 00000000  00000000  00000000  00000000  00000001  00000000  00000000  00000000

02b57d90: 00000000  00000000  00000000  00000000  00000000  00000000  00000000  00000000

02b57db0: 00000000  00000000  00000000  00000000  00000000  00000000  00000000  00000000

02b57dd0: 00000000  00000000  00000000  00000000  00000000  00000000  00000000  00000000

02b57df0: 00000000  00000000  00000000  00000000  00000000 (02b57ebc)<02932f7c> 02b50020

02b57e10: 00000001  02b57f48  00000000  00000000  00000000  00000000  00000000  00000000

02b57e30: 00000000  00000000  00000000  00000000  00000000  00000000  00000000  00000000

02b57e50: 00000000  00000000  00000000  00000000  00000000  00000000  00000000  00000000

02b57e70: 00000000  00000000  00000000  00000000  02b57e9c  02b57eb0

02b50020

02b57e90: 02b508a8  02b50880  02ac4d88  02826bd8  0293017c  02b50020  00000016  00000000

02b57eb0: 02b57ecc

02b50020 (02b57ef0)<029301a0> 02b50020  00000001  02b57f48

02b57ed0: 02b57f6b  02826bd8  0293017c  02b57f08  02826b68  02b57f08  00000000  02ac0020

02b57ef0:(02b57f08)<02826bd4> 02ac0020  00000000  00000000  00000000 (00000000) 0293005a

02b57f10: 02b50020  02988cec  02988d2c  00000000  02988cec  00000000  00000000  00000000

02b57f30: 00000000  02826bd8  02826c38  00000000  02ac80d8  00000001  02b57f6b  00000000

02b57f50: 02b57f7b  02b57f86  02b57fa9  02b57fbd  02b57fc3  00000000  2e000000  7268742f

02b57f70: 5f646165  72616873  54006465  3d4d5245  756e696c  41500078  2f3d4854  3a6e6962

02b57f90: 7273752f  6e69622f  62732f3a  2f3a6e69  2f727375  6e696273  53554800  45565f48

02b57fb0: 4f495352  2e313d4e  342e3831  44575000  54002f3d  52423d5a  42322b54  332b5452

02b57fd0: 2e324d2c  2f302e34  303a3230  314d2c30  2e332e30  32302f30  0030303a  68742f2e

02b57ff0: 64616572  6168735f  00646572  00000000

Return addresses in stack:

   frame  1 : <0x02932f7c> [ /thread_shared + 0x2f3c ]

    address : <0x02934338> [ /thread_shared + 0x42f8 ]

    address : <0x02934376> [ /thread_shared + 0x4336 ]

   frame  2 : <0x029301a0> [ /thread_shared + 0x160 ]

   frame  3 : <0x02826bd4> [ /lib/lib1.so + 0x26bd4 ]

SEGV

 

 

 

Best Regards,

Ronaldo Moura

Outcomes