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.

Unused library functions for GCC (4.9.1) in .text segment of binary.

When examining a disassembler file of a binary compiled with the msp430 GCC I can find several functions that are unused, blowing out the size of the .text segment. 

E.g. several different multiply functions like __mulsi2__mulsi2_hw32, ... (maybe without/with or with different hardware support ).

For reducing these multiply functions compiling with -ffunction  and linking with --gc-sections does the job.

However, there are remaining functions that seem to be unreferenced, e.g. from nosyscalls.o: open, close, kill, getpid, ...

I can't understand why these functions are still linked to the binary. Do they have a certain purpose?

  • I have let the MSP430 gcc compiler experts know about your issue.  I'm sure they will want a test case.  Is this organized as a CCS project you could send in?

    Thanks and regards,

    -George

  • There's a list of system calls that make no sense on embedded boards but are needed to "complete" a port, and we list them all in libgloss/msp430/nosyscalls.S. They're done with macros, one per line, so we keep them together, but if you call one you get them all. You're probably calling (indirectly) exit(). You can use ld's linker map to see why a given object is pulled in (-Wl,-Map,foo.map from gcc).
  • What means complete port?

    We investigated the map file. Actually __crt0_call_exit() calls _exit(). _exit() causes nosyscalls.o to be included which further causes lib_a-errno.o and lib_a-impure.o to be included.

    These are quite a lot unused functions bloating the code. How could we finally get rid of unused code?

  • Please try some of the suggestions found in this forum thread.

    Thanks and regards,

    -George

  • Since we build all of newlib, we have to provide a few OS-level functions that newlib might call just to make sure you don't have link errors.  These functions always fail, but at least they exist .


    In your case, if _exit() is being called by crt0, that means gcc thinks your main() function eventually returns.  When main() returns, the standards say to call "exit" but of course an MCU can't "exit" so we provide a dummy exit() call.  If you change your main() so that gcc sees that it doesn't exit (like, by ending with a while(1) loop of some sort), the call to exit (and thus the other functions) should go away.

  • Not ending main() did it!  Thanks for the explanation.