Hello everybody!
I am developing elf linker for the PicoBlaze CPU target using elfutils-0.152 (see work-in-progress patches in [1]). PicoBlaze is a primitive 8-bit RISC core for Xilinx FPGA. It has quite a small program memory - only 1024 instructions. Hence code size is of primary concern here. I've discovered that the option --gc-sections does not work as intended (see test examples in [2] using i386 target instead). I put each function in its own section (-ffunction-sections), but when a single function (section .text.foo) from the object file is included in the output, all the other sections (.text.bar) are included too. I also tried linking against an archive: in this case the situation improves as untouched object files in the archive are not linked in, but once a function is linked-in, all the other from the same object file are linked-in too. In [2] I tried it also with GNU binutils and it works fine.
Some commands from [2] - maybe I am missing an option switch somewhere? gcc -Wall -O3 -ffunction-sections -m32 -c -o main.o ../src/main.c elfutils-ld -c elf32-i386.script --gc-sections -L. main.o -lmy -o fin-lib-gc.elf
I very much need the feature to omit unused functions to minimize code size. Could someone help please?
Bye, Jara
[1] http://dl.dropbox.com/u/3124266/elfutils-0.152-pblaze-20120112.patch [2] http://dl.dropbox.com/u/3124266/elfutils-test.tar.gz
2012/1/13 Ulrich Drepper drepper@gmail.com:
The linker is not complete. Problems are expected.
ok, I think I fixed it for my simple use case. See the attached patch. It skips the sections in archives that define only new symbols (ie. do not satisfy any old unresolved symbols). Still, for stand-alone objects files it links-in all their sections. I think this will have to do for now...
Take it or leave it. Problems are expected ;)
Jara
elfutils-devel@lists.fedorahosted.org