How to stop --gc-sections nukeing all sections?
Ian Lance Taylor
ian@zembu.com
Wed Apr 5 10:52:00 GMT 2000
Date: Wed, 5 Apr 2000 13:47:19 +1000 (EST)
From: greyham@research.canon.com.au (Graham Stoney)
I'm currently using --gc-sections to eliminate dead code from the Linux kernel
for use on embedded systems. I think I just resolved my last problem, which
was that the linker wasn't outputing _any_ data in the output sections,
presumably because there are no external references to any section. Hence, it
garbage collected _everything_, leaving no output section data, and no kernel
:-(.
My hack workaround is to add "-u _start" to LINKFLAGS, which is enough to
stop ld from discarding everything. However, I'm wondering what the approved
method is to prevent --gc-sections from simply discarding everything?
Is there something I can add to the linker command file to achieve this?
It would be nice to be able to turn --gc-sections on and off without having
to add other stuff to LINKFLAGS. I notice the binutils ldscripts don't suffer
from this problem, but I can't see the magic that makes it work.
The binutils ldscripts typically have an implicit -u option from the
ENTRY command.
They also the KEEP command to retain special sections, such as those
holding initialization code for global constructors.
Ian
More information about the Binutils
mailing list