Discussion:
Problem with shared library
Naveen H. S
2011-11-04 12:28:04 UTC
Permalink
Hi,

We are implementing uclibc port for CR16 target with shared library
support. However, there was an issue observed during testing the port
with shared library.

The following link was referred to compile the applications with static
and shared libraries:-
http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

The application contains a main.c file which calls lib_func function
in lib.c file.
=======================================================================
static int val = 1 ;
static void init( void )
{
val = 13 ;
}
int lib_func( const char* s )
{
printf( "\tEntering %s, called from %s\n\n", __FUNCTION__, s ) ;
return val ;
}
=======================================================================

The application with static library generates correct output "13" by
calling init function init(). However, with shared library; it does
not seem to call init() and generates wrong output "1" as follows:-
==================================================
Starting ./test.out...
Entering lib_func, called from ./test.out
lib_func() returned 1
==================================================

Please find attached the command file "command" which shows exact
commands used for application and library compilation. On investigation,
the problem seem to be due to the incorrect calling of initialization
routines in crt files. It was observed that the shared library calls
"shared_flat_add_library" in crt1.S file. The same routine is used in
bfin and m68k code. Please find attached the initialization files
crt1.S file present in uClibc/libc/sysdeps/linux/cr16 folder.

Please let us know if anything else should be done for the proper
functioning of initialization code in shared libraries.

Thanks & Regards,
Naveen
Naveen H. S
2011-11-04 13:39:10 UTC
Permalink
Hi,

The original message attachment has been quarantined.
Hence please find the attached command file
Naveen H. S
2011-11-04 13:47:59 UTC
Permalink
Hi,

The original message attachment has been quarantined.
Hence please find the attached command file "command.txt".

Thanks & Regards,
Naveen
Khem Raj
2011-11-24 06:18:24 UTC
Permalink
Post by Naveen H. S
Hi,
We are implementing uclibc port for CR16 target with shared library
support. However, there was an issue observed during testing the port
with shared library.
and what changes did you make how do we know ?
Post by Naveen H. S
The following link was referred to compile the applications with static
and shared libraries:-
http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
The application contains a main.c file which calls lib_func function
in lib.c file.
=======================================================================
static int val = 1 ;
static void init( void )
{
       val = 13 ;
}
int lib_func( const char* s )
{
printf( "\tEntering %s, called from %s\n\n", __FUNCTION__, s ) ;
       return val ;
}
=======================================================================
The application with static library generates correct output "13" by
calling init function init(). However, with shared library; it does
not seem to call init() and generates wrong output "1" as follows:-
==================================================
Starting ./test.out...
       Entering lib_func, called from ./test.out
lib_func() returned 1
==================================================
Please find attached the command file "command" which shows exact
commands used for application and library compilation. On investigation,
the problem seem to be due to the incorrect calling of initialization
routines in crt files. It was observed that the shared library calls
"shared_flat_add_library" in crt1.S file. The same routine is used in
bfin and m68k code. Please find attached the initialization files
crt1.S file present in uClibc/libc/sysdeps/linux/cr16 folder.
Please let us know if anything else should be done for the proper
functioning of initialization code in shared libraries.
Thanks & Regards,
Naveen
_______________________________________________
uClibc mailing list
http://lists.busybox.net/mailman/listinfo/uclibc
Naveen H. S
2012-01-04 06:59:33 UTC
Permalink
Post by Khem Raj
Post by Naveen H. S
We are implementing uclibc port for CR16 target with shared library
support. However, there was an issue observed during testing the port
with shared library.
and what changes did you make how do we know ?
Hi,

Thanks for reviewing the mail and sending your feedback.

We are working on the uClibc port for CR16 architecture. Please find
attached the patch "uclibc-cr16.patch" for CR16 port. It has some
target specific changes in generic files. However, we are working
on stabilizing the port first. The version of the uClibc used is
0.9.30.1 and uClinux Kernel- 2.6.19-uc1.

Currently we are facing a problem with the ID shared library routines
declared with __attribute__ ((constructor)). These routines are not
getting called before user main function, as expected.

e.g. A shared library with ID 3 is created from the following source
code.
=======================================================================
static int val = 1 ;

void lib_init ( void ) __attribute__((constructor)); void lib_init( void )
{ printf(“\n Entering constructor
”);
val = 13 ; }

int lib_func ( const char* s )
{ printf( "\t Entering %s, called from %s\n\n", __FUNCTION__, s ) ;
return val ; }
=======================================================================

From the user main() application, lib_func() is called.
When user application is executed on hardware, lib_func() is expected to
return value 13 here. However, it returns value 1. This is happening
because the constructor routine lib_init() is not getting called before
user main().

In the map file generated while compiling library source code, I can see
a correct entry under the “.ctors” section. I even tried placing an
entry under ‘__init_array_start’ manually. Still it failed.

With some fprintf statements, I can see ‘__shared_flat_init()’ is
getting called before user main(). However, I can't see which
initialization routine this function is calling for my test library.
How can I see it?

I got one more doubt. In file shared_flat_add_library.c, I can see a
structure ‘this_lib’ (of type struct shared_flat_lib) is associated with
each shared library being used. I think ‘_init’ element of this
structure should get populated with lib_init() address in my test case.
Is it correct?
In that case, who is expected to assign this value to this element?

Thanks & Regards,
Naveen

Loading...