Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

split object files

2 views
Skip to first unread message

Konrad Eisele

unread,
Aug 25, 2005, 4:56:16 AM8/25/05
to
I'm searching for a switch that will mark the functions in a object file
so that the linker can select only those functions needed and not the
whole object file when referenced by one symbol.

Paul Pluzhnikov

unread,
Aug 25, 2005, 11:15:55 AM8/25/05
to
Konrad Eisele <kon...@gaisler.com> writes:

From "info gcc":

`-ffunction-sections'
`-fdata-sections'
Place each function or data item into its own section in the output
file if the target supports arbitrary sections. The name of the
function or the name of the data item determines the section's name
in the output file.

Use these options on systems where the linker can perform
optimizations to improve locality of reference in the instruction
space. Most systems using the ELF object format and SPARC
processors running Solaris 2 have linkers with such optimizations.
AIX may have these optimizations in the future.

Only use these options when there are significant benefits from
doing so. When you specify these options, the assembler and
linker will create larger object and executable files and will
also be slower. You will not be able to use `gprof' on all
systems if you specify this option and you may have problems with
debugging if you specify both this option and `-g'.

Note that in order to induce linker to do the optimization on
Linux, you need to pass it some flag(s). I've tried -O and
--gc-sections, but neither did the job. If someone knows what the
correct incantation is, please enlighten me.

Here is the test I tried:

$ cat main.c
int main() { return foo0(); }

$ cat foo.c
int foo0() { return 42; }
int foo1() { return 42; }

$ gcc -c -ffunction-sections foo.c
$ gcc main.c -Wl,-O,--gc-sections foo.o

$ nm a.out | grep foo1
0804835e T foo1 # I would have expected this to be discarded,
# why isn't it?

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.

Konrad Eisele

unread,
Aug 25, 2005, 12:54:53 PM8/25/05
to
Thanks, it worked with my sparc-elf-gcc crosscompiler that way.
Using -ffunction-sections with .o creation
and -Wl,--gc-sections whith exe creation.
-- Konrad
0 new messages