Linking objects with GNU LD

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

Reply to
Karl-Heinz
Loading thread data ...

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.

Reply to
Hans Odeberg

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?

Reply to
Karl-Heinz

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.
Reply to
Hans-Bernhard Broeker

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.

Reply to
David Brown

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!
 Click to see the full signature
Reply to
Grant Edwards

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
 Click to see the full signature
Reply to
Grant Edwards

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!

Reply to
Karl-Heinz

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.