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.

Compiler/RM48L950: ARMCL - How to statically link library into executable, without code referencing it?

Part Number: RM48L950

Tool/software: TI C/C++ Compiler

We are using armcl version 16.9.0.lts.
www.ti.com/.../spnu151q.pdf

We have a static library with dynamic code analysis functionality (CTC++) which we want to include into our compiled executable
The code of the executable isn't supposed or needed to reference it.
We use gdb as a debugger to run the executable and start its main loop and after tasks have been performed, we use gdb to access the CTC functions in the library to give us an overview of what functions were executed.

For an x86 version of the code we use the gcc compiler and these specific linker options to tell gcc to keep the library included:
LIBRARY = -L$(CTC_LIB_PATH) -Wl,--whole-archive -lctc_hota -Wl,--no-whole-archive

Question:
How can we achieve the same effect with the armcl compiler?
Sofar the compiler is probably excluding the library for optimization reasons.
We are using these flags in this order:
-O0ff
-z
---search_path=/dir --library=filename.a

The compiler output doesn't explicitly mention that it has found the library but chooses to ignore it. Can such choices be enabled to show?

Kind regards

  • On page 76 of the manual this text is written:
    "When you specify a library as linker input, the linker includes and links only those library members that resolve undefined references."

    For our specific situation, that is not what we want.
  • We decided to add an empty function to the library and call that one from the code to force the linker to load in the rest of the library.
    Resolved, by having to change the executable code: not what we wanted.

    While doing this, we noticed that unfortunately the optimization step of -Ooff does not work as advertised.
    Using a function call like this, causes linking to happen:
    ctc_linking_armcl();

    Using nm to list symbols from the object file shows all the ctc library functions available.

    Using a function call like this, causes no linking to happen:
    if(false){ctc_linking_armcl();}

    Using nm to list symbols from the object file shows no ctc library functions available.

    From the documentation on page:
    --opt_level=off or -Ooff:
    Performs no optimization
    --opt_level=0 or -O0:
    Eliminates unused code


    We expect when using -Ooff that situations as code below a while(1) or within an if(false) are not optimized away.
  • The above is even the case when using the miscellaneous option:
    --unused_section_elimination=off
  • Unfortunately, there is no option which brings in every file from a library.  Use the linker option --undef_sym=name_of_symbol .  Please read more about it in the ARM assembly tools manual.  In your case, you need an --undef_sym for every symbol in the library.  I realize this is inconvenient.  But it is the only solution.  I suggest you put all the --undef_sym options together in a linker command file (which is an ordinary text file) called something like force_library_functions.cmd.  Then supply that file to the linker just like any other file.

    Thanks and regards,

    -George

  • Hi George,

    We will definitely look into this. Thanks for the answer!

    Kind regards