Problem with constructor routine in ID shared library
Sandeep Kumar Singh
Sandeep.Singh2 at kpitcummins.com
Thu Dec 15 06:28:03 UTC 2011
I am a new comer to uClibc domain.
I am working on CR16 architecture and using uClinux toolchain for library
source code compilation, kernel compilation and application compilation.
Version details of my toolchain sources are:
uClibc-0.9.30.1 (with CR16 support added)
I have a problem with the constructor routines defined inside my ID shared
library source code. Mine is a "C" application and library source is also a
My sample library code is:
static int val = 1 ;
void init( void ) __attribute__((constructor));
val = 13 ;
printf( "\nEntering constructor\n") ;
printf( "\nEntering %s, Value is %d\n", __FUNCTION__, val ) ;
return val ;
Here, when lib_func() is called from main(), I expected it to print value of
"val" as 13. However, it prints it as 1.
I use the following compilation command for id shared library:
cr16-uclinux-gcc -c -mint32 -mcr16cplus -mdata-model=far -O2 \
-mid-shared-library -fPIC -o lib.o -c lib.c
cr16-uclinux-ar cru libmy_lib.a lib.o
cr16-uclinux-gcc -mint32 -mcr16cplus -mdata-model=far \
-Wl,-elf2flt=-k -L./ -mid-shared-library -Wl,--no-relax -fPIC \
-o libmy_lib_so -nostartfiles \
-Wl,--whole-archive,libmy_lib.a -Wl,--no-whole-archive -Wl,-M=lib.map
In lib.map file, I can see an entry under '.ctors' section as:
.ctors 0x03005bec 0x4 libmy_lib.a(lib.o)
However, there is no entry under '.init_array'. Is this a problem? However,
even if I assign this routine to section '.init_array' explicitly, it still
does not get called before main.
In uClibc/libc/sysdeps/linux/cr16/crt1.S, __shared_flat_init() is passed as
fourth argument to __uClibc_main(). Therefore, I believe this function must
be responsible for initializing the library constructor routines. Hence, in
uClibc/libc/misc/internals/shared_flat_initfini.c, I tried putting printf
statements inside __shared_flat_init() function. However, with this change,
uClinux kernel crashes on hardware while executing sample application. What
way I could verify/debug the ID shared library initialization flow inside
If I compile same library source as Static Library, everything works fine.
Thanks in advance.
[KPIT Cummins, Pune]
More information about the uClibc