This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to retain all symbols from a linked library?

Hello,

I need to retain all symbols from a linked library (because they might be used by other dynamic libraries).

I tried to do it like below, but no success so far. What is the correct way to do this? 

--retain='mylibrary.lib<*>(*)'

thanks,

vesa

  • You mean to entirely circumvent the very purpose of a library.  A library is a collection of object modules.  Just like a normal library of books, the linker "checks out" only the ones you need to read.  All the other books are left alone.  After all that occurs, the linker goes on to remove parts of object modules (think of them as chapters in the books) that are not needed.  You use --retain to disable the removal of specified chapters.

    This means there is no straightforward way to do this.

    One method is to turn the library into normal object files and link all of them in.  If you are using the ARM compiler, that would look like ...

    % armar -x name_of_library.lib
    

    That command extracts all the members of the library into the current directory.

    Another method is to apply the linker option --undef_sym to every global symbol in the library.  You can get a list of these global symbols with the command ...

    % armnm -g name_of_library.lib
    

    With a bit of scripting, you can capture those symbol names in a text file with --undef_sym prepended to each one.  Then supply that file as an input to the linker.  The linker will process it like any other linker command file.

    Thanks and regards,

    -George

  • Thanks George,

    I'm building for DSP using cl6x compiler/linker.

    We are building a DSP "base image" which has to have functionality available for dynamically loaded code. Hence, we don't know at the linking time what functions will be used from this library. We still want to use "--unused_section_elimination" for other libraries linked into the base image. 

    This seems to do the job, I don't know if by mistake or is it the correct way to do it with cl6x:

    --retain='mylib.lib*(*)' 

    ************************************

    I've related question related linking against RTS library.

    When I make the base image, RTS lib is included there. What is the proper way to link dynamic libraries with cl6x, so that they can use symbols from the RTS library? 

    I anticipate few issues here:

    1. when linking dynamically "-z--dynamic=lib   -l"rts6600_elf_eh.lib" , is the library included in the output? We don't want to have it many times (once in the baseimage and once per a dynamic library)

    2. If I'm using symbols from RTS that baseimage is not using, they are eliminated.

    3. do I need to export all (used) symbols from RTS when building the base image? 

    thanks,

    vesa

  • Vesa Peltonen said:

    This seems to do the job, I don't know if by mistake or is it the correct way to do it with cl6x:

    --retain='mylib.lib*(*)' 

    When I try that, it does not cause any additional members of the library to be included in the link.

    When I try --retain='mylib.lib<*>(*)' I do see more parts of the library in the link, but far from everything in the library.  I haven't analyzed this in full detail, because it doesn't really solve the problem.  I'm pretty sure this prevents the removal of any section from a normally included library member.  That, in turn, can cause yet other members of the library to be referenced and brought in.  But it does not chain out to all members of the library.

    I'll have to get help on your other questions.

    Thanks and regards,

    -George

  • Hi George, others,

    You are correct, it didn't work as you said. However, actually found out that I don't need to use the "--retain" option at all, because we have to --export the symbols anyway, so they will be visible for the dynamic libraries. Exporting a symbols retains it even it is not used in the current code.

    I still need some suggestion how to expose properly the RTS functionality from a DSP baseimage to dynamic libraries.

    cheers,

    vesa