2010-02-05 15:01:44     version-script problem with gcc 4.3.3

Document created by Aaronwu Employee on Sep 26, 2013
Version 1Show Document
  • View in full screen mode

2010-02-05 15:01:44     version-script problem with gcc 4.3.3

Doug Bailey (UNITED STATES)

Message: 85711   

 

I am having problems with the gcc 4.3.3 linker --version-script directive.  I am

using the toolchain built from the toolchain_09r1_rc9 toolchain tag.  When I

specify an export file, the symbols that should set for export are not showing

up in the resulting file.

 

For example:

The following is the compilation of the asterisk res_adsi.so shared library:

 

bfin-linux-uclibc-gcc --version

bfin-linux-uclibc-gcc (ADI/svn-3473) 4.3.3

Copyright (C) 2008 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

Object Compilation

================================================

bfin-linux-uclibc-gcc -o res_adsi.o -c res_adsi.c -MD -MT res_adsi.o -MF .res_adsi.o.d -MP -pthread -I/usr/src/aa50staging/asterisk/include -pipe -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -g3   -Os -fPIC -DAST_MODULE=\"res_adsi\"  -mfdpic

 

There are two link invokations, one with the version-script directive and one

without it.  I am able to load and run asterisk when I use the code built when I

don't specify the version-script.  When I run asterisk built with the

version-script directive, I encounter a "asterisk: can't resolve symbol

'_ast_adsi_print'" error.

================================================

bfin-linux-uclibc-gcc  -o res_adsi.so -pthread  -shared  -mfdpic  res_adsi.o

 

bfin-linux-uclibc-gcc  -o res_adsi.so -pthread  -shared -Wl,--version-script,res_adsi.exports -mfdpic  res_adsi.o

 

================================================

cat ../asterisk/res/res_adsi.exports

{

    global:

        ast_adsi_available;

        ast_adsi_begin_download;

        ast_adsi_channel_restore;

        ast_adsi_clear_screen;

        ast_adsi_clear_soft_keys;

        ast_adsi_connect_session;

        ast_adsi_data_mode;

        ast_adsi_disconnect_session;

        ast_adsi_display;

        ast_adsi_download_connect;

        ast_adsi_download_disconnect;

        ast_adsi_end_download;

        ast_adsi_get_cpeid;

        ast_adsi_get_cpeinfo;

        ast_adsi_input_control;

        ast_adsi_input_format;

        ast_adsi_load_session;

        ast_adsi_load_soft_key;

        ast_adsi_print;

        ast_adsi_query_cpeid;

        ast_adsi_query_cpeinfo;

        ast_adsi_read_encoded_dtmf;

        ast_adsi_set_keys;

        ast_adsi_set_line;

        ast_adsi_transmit_message;

        ast_adsi_transmit_message_full;

        ast_adsi_unload_session;

        ast_adsi_voice_mode;

    local:

        *;

};

 

 

Symbols without specifying version-script

===========================================

nm -D ../asterisk/res/res_adsi.so

         w __Jv_RegisterClasses

0000578c R __ROFIXUP_END__

00005788 R __ROFIXUP_LIST__

         U ___ast_lin2mu

00009b98 A ___bss_start

         w ___cxa_finalize

         w ___deregister_frame_info

         U ___errno_location

         w ___register_frame_info

000015d4 T ___self_reloc

00009b98 A __edata

00009f0c A __end

00004f48 T __fini

0000130c T __init

00001ae0 T _ast_adsi_available

0000428c T _ast_adsi_begin_download

00003ee4 T _ast_adsi_channel_restore

00001aa0 T _ast_adsi_clear_screen

00001a84 T _ast_adsi_clear_soft_keys

00001950 T _ast_adsi_connect_session

00001a68 T _ast_adsi_data_mode

00001a14 T _ast_adsi_disconnect_session

00001b10 T _ast_adsi_display

00001994 T _ast_adsi_download_connect

00001af4 T _ast_adsi_download_disconnect

00004250 T _ast_adsi_end_download

00004168 T _ast_adsi_get_cpeid

00003f70 T _ast_adsi_get_cpeinfo

00001bd4 T _ast_adsi_input_control

00001c2c T _ast_adsi_input_format

00003d00 T _ast_adsi_load_session

00001874 T _ast_adsi_load_soft_key

00003e34 T _ast_adsi_print

00001a30 T _ast_adsi_query_cpeid

00001a4c T _ast_adsi_query_cpeinfo

00001fa8 T _ast_adsi_read_encoded_dtmf

00001cdc T _ast_adsi_set_keys

00001d14 T _ast_adsi_set_line

00004238 T _ast_adsi_transmit_message

00003a74 T _ast_adsi_transmit_message_full

00003ca8 T _ast_adsi_unload_session

00001abc T _ast_adsi_voice_mode

         U _ast_channel_defer_dtmf

         U _ast_channel_undefer_dtmf

         U _ast_config_destroy

         U _ast_config_load

         U _ast_copy_string

         U _ast_frame_free

         U _ast_gen_cas

         U _ast_log

         U _ast_module_register

         U _ast_module_unregister

         U _ast_read

         U _ast_readstring

         U _ast_safe_sleep

         U _ast_set_read_format

         U _ast_set_write_format

         U _ast_stopstream

         U _ast_variable_browse

         U _ast_waitfor

         U _ast_waitfordigit

         U _ast_write

         U _atoi

         U _cid_di

         U _cid_dr

         U _clidsb

         U _memset

         U _rint

         U _strcasecmp

         U _strcmp

         U _strlen

         U _strncasecmp

         U _strsep

 

Symbols without specifying version-script

===========================================

nm -D ../asterisk/res/res_adsi.so

         w __Jv_RegisterClasses

         U ___ast_lin2mu

         w ___cxa_finalize

         w ___deregister_frame_info

         U ___errno_location

         w ___register_frame_info

         U _ast_channel_defer_dtmf

         U _ast_channel_undefer_dtmf

         U _ast_config_destroy

         U _ast_config_load

         U _ast_copy_string

         U _ast_frame_free

         U _ast_gen_cas

         U _ast_log

         U _ast_module_register

         U _ast_module_unregister

         U _ast_read

         U _ast_readstring

         U _ast_safe_sleep

         U _ast_set_read_format

         U _ast_set_write_format

         U _ast_stopstream

         U _ast_variable_browse

         U _ast_waitfor

         U _ast_waitfordigit

         U _ast_write

         U _atoi

         U _cid_di

         U _cid_dr

         U _clidsb

         U _memset

         U _rint

         U _strcasecmp

         U _strcmp

         U _strlen

         U _strncasecmp

         U _strsep

 

NOTE:  When I compile this natively on my machine with gcc 4.3.3, I get the

following symbol output:

===========================================

                 w _Jv_RegisterClasses

                 U __ast_lin2mu

                 w __cxa_finalize

                 U __errno_location

                 w __gmon_start__

                 U __stack_chk_fail

0000000000001c70 T ast_adsi_available

0000000000004bd0 T ast_adsi_begin_download

0000000000004f80 T ast_adsi_channel_restore

0000000000001c40 T ast_adsi_clear_screen

0000000000001c30 T ast_adsi_clear_soft_keys

0000000000001ae0 T ast_adsi_connect_session

0000000000001c20 T ast_adsi_data_mode

0000000000001bf0 T ast_adsi_disconnect_session

0000000000001c90 T ast_adsi_display

0000000000001b30 T ast_adsi_download_connect

0000000000001c80 T ast_adsi_download_disconnect

0000000000004b60 T ast_adsi_end_download

0000000000005380 T ast_adsi_get_cpeid

0000000000005080 T ast_adsi_get_cpeinfo

0000000000001d60 T ast_adsi_input_control

0000000000001db0 T ast_adsi_input_format

0000000000004d50 T ast_adsi_load_session

0000000000001960 T ast_adsi_load_soft_key

0000000000004a10 T ast_adsi_print

0000000000001c00 T ast_adsi_query_cpeid

0000000000001c10 T ast_adsi_query_cpeinfo

0000000000001f50 T ast_adsi_read_encoded_dtmf

0000000000001e60 T ast_adsi_set_keys

0000000000001ee0 T ast_adsi_set_line

0000000000004b50 T ast_adsi_transmit_message

0000000000004650 T ast_adsi_transmit_message_full

0000000000004ca0 T ast_adsi_unload_session

0000000000001c50 T ast_adsi_voice_mode

                 U ast_channel_defer_dtmf

                 U ast_channel_undefer_dtmf

                 U ast_config_destroy

                 U ast_config_load

                 U ast_frame_free

                 U ast_gen_cas

                 U ast_log

                 U ast_module_register

                 U ast_module_unregister

                 U ast_read

                 U ast_readstring

                 U ast_register_file_version

                 U ast_safe_sleep

                 U ast_set_read_format

                 U ast_set_write_format

                 U ast_stopstream

                 U ast_unregister_file_version

                 U ast_variable_browse

                 U ast_waitfor

                 U ast_waitfordigit

                 U ast_write

                 U cid_di

                 U cid_dr

                 U clidsb

                 U rint

                 U strcasecmp

                 U strchr

                 U strlen

                 U strncasecmp

                 U strtol

QuoteReplyEditDelete

 

 

2010-02-05 15:10:44     Re: version-script problem with gcc 4.3.3

Mike Frysinger (UNITED STATES)

Message: 85712   

 

symbols in version scripts are the linker-visible symbols, not the C-visible symbols.  you need to use the ABI prefix in the linker script.

QuoteReplyEditDelete

 

 

2010-02-05 15:28:43     Re: version-script problem with gcc 4.3.3

Doug Bailey (UNITED STATES)

Message: 85713   

 

I am ignorant when it comes to many of the gcc linker switches.  Please bear with me.

 

The symbols I want to see are linker symbols that are fixed when the modules are loaded via dlopen.  Would these not be the type of symbol I need to publish in the module?

 

I am also not sure what the ABI prefix you mention.  What do I actually need to specify in the script file?

QuoteReplyEditDelete

 

 

2010-02-05 15:33:34     Re: version-script problem with gcc 4.3.3

Mike Frysinger (UNITED STATES)

Message: 85714   

 

gcc is the compiler, it isnt the linker.

 

dlopen() uses C-visible symbols, so no, they wont match what is put into the linker script.

 

you have the exact list of symbol names -- you posted it from the output of `nm`.

QuoteReplyEditDelete

 

 

2010-02-05 17:06:59     Re: version-script problem with gcc 4.3.3

Doug Bailey (UNITED STATES)

Message: 85716   

 

I have created a small project (attached) which has a main that dynamically

loads a library that has a call back to the main program.  (In the end, this is

what I need.)

 

I have compiled each one with and without version-script directive

(CC=bfin-linux-uclibc-gcc CFLAG="-mfdpic " ./mk).  I have run all 4 combinations

on my blackfin and only the combination compiled without version-script

directive runs.

 

Output of tests:

==========================

root:/bin> ./dltestNS libtestNS.so

DlOpen test for library libtestNS.so

Library opened, handle=0x308ca8

Symbol found

testing return of func = 60

 

root:/bin> ./dltestNS libtest.so

DlOpen test for library libtest.so

Library opened, handle=0x308ca8

 

Punting on symbol lookup, NULL ptestfunc

 

root:/bin> ./dltest libtest.so

DlOpen test for library libtest.so

Library opened, handle=0x308ca8

 

Punting on symbol lookup, NULL ptestfunc

 

root:/bin> ./dltest libtestNS.so

DlOpen test for library libtestNS.so

Library opened, handle=0x308ca8

Symbol found

./dltest: can't resolve symbol '_testcallback'

 

 

If I build this for for my PC (CC=gcc CFLAG="-fPIC " ./mk) all combinations run

fine.

 

Is the problem:

- uclibc dlopen is not reading the symbols correctly?

- The linker (version 2.17) is not contructing the dynamic relocation correctly?

- I have built the exports file incorrectly?

- Something to which I am totally ignorant?

 

 

FYI: The bfin-linux-uclibc-nm reports the following for the blackfin compiled modules:

 

bfin-linux-uclibc-nm dltest dltestNS libtest.so libtestNS.so

 

dltest:

00004e00 A ___bss_start

00004e00 b _completed.4837

00004c54 d ___CTOR_END__

00004c50 d ___CTOR_LIST__

         w ___deregister_frame_info@@GCC_3.0

         U _dlclose

         U _dlerror

         U _dlopen

         U _dlsym

00000ad4 t ___do_global_ctors_aux

0000086c t ___do_global_dtors_aux

00004d34 D ___dso_handle

00004c5c D ___DTOR_END__

00004e04 b _dtor_idx.4839

00004c58 d ___DTOR_LIST__

00004c64 d _DYNAMIC

00004e00 A __edata

00000c4c r ___EH_FRAME_BEGIN__

00004e20 A __end

         U _exit

00000b04 T __fini

         U _fputs

000008d8 t _frame_dummy

00000c4c r ___FRAME_END__

00004d90 d __GLOBAL_OFFSET_TABLE_

00000558 T __init

00004c60 d ___JCR_END__

00004c60 d ___JCR_LIST__

         w __Jv_RegisterClasses

0000093c T _main

00004e08 b _object.4859

         U _printf

         U _puts

         w ___register_frame_info@@GCC_3.0

00000c4c R __ROFIXUP_END__

00000c00 R __ROFIXUP_LIST__

00000694 T ___self_reloc

         U _sleep

         U _snprintf

00020000 A __stacksize

00000630 T __start

         U _stderr

00000920 T _testcallback

         U ___uClibc_main

00000ab4 t ___udivsi3

00000aa8 t ___umodsi3

 

dltestNS:

00004e68 A ___bss_start

00004e68 b _completed.4837

00004cb8 d ___CTOR_END__

00004cb4 d ___CTOR_LIST__

         w ___deregister_frame_info@@GCC_3.0

         U _dlclose

         U _dlerror

         U _dlopen

         U _dlsym

00000b38 t ___do_global_ctors_aux

000008d0 t ___do_global_dtors_aux

00004d98 d ___dso_handle T ___self_reloc

         U _sleep

         U _snprintf

00020000 A __stacksize

00000694 T __start

         U _stderr

00000984 T _testcallback

         U ___uClibc_main

00000b18 t ___udivsi3

00000b0c t ___umodsi3

 

libtest.so:

00004828 a ___bss_start

00004828 b _completed.4837

000046fc d ___CTOR_END__

000046f8 d ___CTOR_LIST__

         w ___cxa_finalize

         w ___deregister_frame_info@@GCC_3.0

000006ac t ___do_global_ctors_aux

000005c4 t ___do_global_dtors_aux

000047dc d ___dso_handle

00004704 d ___DTOR_END__

0000482c b _dtor_idx.4839

00004700 d ___DTOR_LIST__

0000470c d _DYNAMIC

00004828 a __edata

000006f4 r ___EH_FRAME_BEGIN__

00004848 a __end

000006dc t __fini

00000644 t _frame_dummy

000006f4 r ___FRAME_END__

000047e8 d __GLOBAL_OFFSET_TABLE_

000003b4 t __init

00004708 d ___JCR_END__

00004708 d ___JCR_LIST__

         w __Jv_RegisterClasses

00004830 b _object.4860

         w ___register_frame_info@@GCC_3.0

000006f4 r __ROFIXUP_END__

000006f0 r __ROFIXUP_LIST__

000003ec t ___self_reloc

00020000 A __stacksize

         U _testcallback

0000068c t _testfunc

 

libtestNS.so:

00004958 A ___bss_start

00004958 b _completed.4837

00004828 d ___CTOR_END__

00004824 d ___CTOR_LIST__

         w ___cxa_finalize

         w ___deregister_frame_info@@GCC_3.0

000007d8 t ___do_global_ctors_aux

000006f0 t ___do_global_dtors_aux

00004908 d ___dso_handle

00004830 d ___DTOR_END__

0000495c b _dtor_idx.4839

0000482c d ___DTOR_LIST__

00004838 d _DYNAMIC

00004958 A __edata

00000820 r ___EH_FRAME_BEGIN__

00004978 A __end

00000808 T __fini

00000770 t _frame_dummy

00000820 r ___FRAME_END__

00004918 d __GLOBAL_OFFSET_TABLE_

000004e0 T __init

00004834 d ___JCR_END__

00004834 d ___JCR_LIST__

         w __Jv_RegisterClasses

00004960 b _object.4860

         w ___register_frame_info@@GCC_3.0

00000820 R __ROFIXUP_END__

0000081c R __ROFIXUP_LIST__

00000518 T ___self_reloc

00020000 A __stacksize

         U _testcallback

000007b8 T _testfunc

 

00004cc0 d ___DTOR_END__

00004e6c b _dtor_idx.4839

00004cbc d ___DTOR_LIST__

00004cc8 d _DYNAMIC

00004e68 A __edata

00000cb0 r ___EH_FRAME_BEGIN__

00004e88 A __end

         U _exit

00000b68 T __fini

         U _fputs

0000093c t _frame_dummy

00000cb0 r ___FRAME_END__

00004df8 d __GLOBAL_OFFSET_TABLE_

000005bc T __init

00004cc4 d ___JCR_END__

00004cc4 d ___JCR_LIST__

         w __Jv_RegisterClasses

000009a0 T _main

00004e70 b _object.4859

         U _printf

         U _puts

         w ___register_frame_info@@GCC_3.0

00000cb0 R __ROFIXUP_END__

00000c64 R __ROFIXUP_LIST__

000006f8 T ___self_reloc

         U _sleep

         U _snprintf

00020000 A __stacksize

00000694 T __start

         U _stderr

00000984 T _testcallback

         U ___uClibc_main

00000b18 t ___udivsi3

00000b0c t ___umodsi3

 

libtest.so:

00004828 a ___bss_start

00004828 b _completed.4837

000046fc d ___CTOR_END__

000046f8 d ___CTOR_LIST__

         w ___cxa_finalize

         w ___deregister_frame_info@@GCC_3.0

000006ac t ___do_global_ctors_aux

000005c4 t ___do_global_dtors_aux

000047dc d ___dso_handle

00004704 d ___DTOR_END__

0000482c b _dtor_idx.4839

00004700 d ___DTOR_LIST__

0000470c d _DYNAMIC

00004828 a __edata

000006f4 r ___EH_FRAME_BEGIN__

00004848 a __end

000006dc t __fini

00000644 t _frame_dummy

000006f4 r ___FRAME_END__

000047e8 d __GLOBAL_OFFSET_TABLE_

000003b4 t __init

00004708 d ___JCR_END__

00004708 d ___JCR_LIST__

         w __Jv_RegisterClasses

00004830 b _object.4860

         w ___register_frame_info@@GCC_3.0

000006f4 r __ROFIXUP_END__

000006f0 r __ROFIXUP_LIST__

000003ec t ___self_reloc

00020000 A __stacksize

         U _testcallback

0000068c t _testfunc

 

libtestNS.so:

00004958 A ___bss_start

00004958 b _completed.4837

00004828 d ___CTOR_END__

00004824 d ___CTOR_LIST__

         w ___cxa_finalize

         w ___deregister_frame_info@@GCC_3.0

000007d8 t ___do_global_ctors_aux

000006f0 t ___do_global_dtors_aux

00004908 d ___dso_handle

00004830 d ___DTOR_END__

0000495c b _dtor_idx.4839

0000482c d ___DTOR_LIST__

00004838 d _DYNAMIC

00004958 A __edata

00000820 r ___EH_FRAME_BEGIN__

00004978 A __end

00000808 T __fini

00000770 t _frame_dummy

00000820 r ___FRAME_END__

00004918 d __GLOBAL_OFFSET_TABLE_

000004e0 T __init

00004834 d ___JCR_END__

00004834 d ___JCR_LIST__

         w __Jv_RegisterClasses

00004960 b _object.4860

         w ___register_frame_info@@GCC_3.0

00000820 R __ROFIXUP_END__

0000081c R __ROFIXUP_LIST__

00000518 T ___self_reloc

00020000 A __stacksize

         U _testcallback

000007b8 T _testfunc

 

dltest.tgz

QuoteReplyEditDelete

 

 

2010-02-05 17:41:16     Re: version-script problem with gcc 4.3.3

Mike Frysinger (UNITED STATES)

Message: 85718   

 

as i said, the symbols shown by `nm` are the ones you have to put into the linker script.  `nm dltestshared.o` does not show "testfunc", it shows "_testfunc".

QuoteReplyEditDelete

 

 

2010-02-05 18:21:12     Re: version-script problem with gcc 4.3.3

Doug Bailey (UNITED STATES)

Message: 85719   

 

I changed the .export files so that their symbols have a leading underscore.  Now when I run it on the blackin, all variants run.  However, now when it runs on the PC, the version-script variants fail.

 

Who is correct?  the linker for the blackfin (V2.17) or the linker for the PC (2.19.1)?

QuoteReplyEditDelete

 

 

2010-02-05 18:52:11     Re: version-script problem with gcc 4.3.3

Mike Frysinger (UNITED STATES)

Message: 85720   

 

they're both correct.  like i said, the linker script needs to contain the exact ELF symbols, not the C-visible ones.  they may be different depending on the target.  no spec requires these to have an exact format.

 

generate the linker script at configure time using the __USER_LABEL_PREFIX__ define from gcc.

QuoteReplyEditDelete

Attachments

    Outcomes