Linking objects with GNU LD

Feb 27, 2006 7 Replies

Hi everybody,



I am using the GNU GCC toolchain configured for m68k (cross compiler). I want to link several objects into an executable file. Unfortunately there are several c-functions compiled into one object but I don't want to use all functions in my executable. Looking into the map file I can see the unused functions in my executable. Is there a way to avoid this functions being in the executable (apart from splitting the functions in the c file)?



Thanks in advance



The gcc options -ffunction-sections and -fdata-sections will generate separate sections for the functions and data items in a file. (Assuming the output format can support this.)

The ld option --gc-sections will remove unreferenced sections.

Hans Odeberg schrieb:

If I try to do as described, I get .text and .data sections with different extensions, e.g. ".text.foo". If I link without the ld option --gc-sections the executable seems to be fine. Unfortunately the ld option --gc-sections leads to an executable which has empty .text and .data sections. What's wrong?

For all anybody out here can guess: your build of binutils, your linker script, or both.

Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain.

It sounds like ld has concluded that none of the sections are used, and they can thus all be eliminated. Perhaps you need to explicitly reference your Start symbol (the name can vary), so that it's section is not removed, nor any section referred to by that section, and so on.

Yup. That's how it works.

Your linker script.

Look at the input section specifiers below:

.text : { *(.text.*) etext = .; } > rom

.data : AT (__data_init_start) { __data_start = .; *(.data.*) __data_end = .; } > ram .bss : { __bss_start = . ; *(.bss.*) *(COMMON) __bss_end = . ; } > ram

Grant Edwards grante Yow! I was making donuts at and now I'm on a bus! visi.com

Ah. Good point.

He may have to do a KEEP() on a few key functions in order to prime the pump.

Grant Edwards grante Yow! Hey, LOOK!! A pair of at SIZE 9 CAPRI PANTS!! They visi.com probably belong to SAMMY DAVIS, JR.!!

That's it! I forgot to add "ENTRY(start)" into my linker script and there was no symbol "start" in my crt0. Thanks to all for your help!

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required