Tech Support > Computer Hardware > Microprocessors > Linking objects with GNU LD
Linking objects with GNU LD
Posted by Karl-Heinz on February 27th, 2006


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

Posted by Hans Odeberg on February 27th, 2006



Karl-Heinz wrote:

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.


Posted by Karl-Heinz on March 7th, 2006


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?


Posted by Hans-Bernhard Broeker on March 7th, 2006


Karl-Heinz <karl-heinz.rossmann@liebherr.com> wrote:

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.

Posted by David Brown on March 7th, 2006


Karl-Heinz wrote:
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.

Posted by Grant Edwards on March 7th, 2006


On 2006-03-07, Karl-Heinz <karl-heinz.rossmann@liebherr.com> wrote:
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

Posted by Grant Edwards on March 7th, 2006


On 2006-03-07, David Brown <david@westcontrol.removethisbit.com> wrote:

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.!!

Posted by Karl-Heinz on March 8th, 2006


David Brown wrote:
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!



Similar Posts