This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Help needed - defining the output section order
- From: Simon Kissel <scamp at untergrund dot net>
- To: binutils at sources dot redhat dot com
- Date: Mon, 22 Aug 2005 13:03:16 +0200
- Subject: Help needed - defining the output section order
- Reply-to: Simon Kissel <scamp at untergrund dot net>
Hi List,
I'm working on a replaceable resource compiler for the FreePascal
(www.freepascal.org) team. I'm mentioning this to clarify that any
"upgrade your gcc", "pascal sucks anyway, use c" kind of answers
won't really help me ;)
After fiddling with this for a few nights, I really need some help
from you binutils gurus out there.
The situation is the following:
I need to link an object file into an ELF executable. This is how the
object file looks like:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .text PROGBITS 00000000 000034 000000 00 AX 0 0 4
[ 2] .data PROGBITS 00000000 000034 000000 00 WA 0 0 4
[ 3] .bss NOBITS 00000000 000034 000000 00 WA 0 0 4
[ 4] fpc.ressym PROGBITS 00000000 000034 00000f 00 A 0 0 4
[ 5] fpc.resstr PROGBITS 00000000 000044 000000 00 A 0 0 4
[ 6] fpc.reshash PROGBITS 00000000 000044 000040 00 A 0 0 4
[ 7] fpc.resdata PROGBITS 00000000 000084 0005b8 00 A 0 0 4
[ 8] fpc.resspare NOBITS 00000000 00063c 0005b8 00 A 0 0 4
[ 9] .shstrtab STRTAB 00000000 00063c 000067 00 0 0 1
[10] .symtab SYMTAB 00000000 000884 000090 10 11 9 4
[11] .strtab STRTAB 00000000 000914 000001 00 0 0 1
What I need is to have the fpc.* sections in exactly the same order
(or at least have fpc.resspare directly after fpc.resdata) in the
output. Instead I get this:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 080480d4 0000d4 000013 00 A 0 0 1
[ 2] .hash HASH 080480e8 0000e8 000038 04 A 3 0 4
[ 3] .dynsym DYNSYM 08048120 000120 000090 10 A 4 1 4
[ 4] .dynstr STRTAB 080481b0 0001b0 00007f 00 A 0 0 1
[ 5] .gnu.version VERSYM 08048230 000230 000012 02 A 3 0 2
[ 6] .gnu.version_r VERNEED 08048244 000244 000020 00 A 4 1 4
[ 7] .rel.dyn REL 08048264 000264 000008 08 A 3 0 4
[ 8] .rel.plt REL 0804826c 00026c 000040 08 A 3 a 4
[ 9] .init PROGBITS 080482ac 0002ac 000034 00 AX 0 0 4
[10] .plt PROGBITS 080482e0 0002e0 000090 04 AX 0 0 4
[11] .text PROGBITS 08048370 000370 028ec4 00 AX 0 0 4
[12] .fini PROGBITS 08071234 029234 00001f 00 AX 0 0 4
[13] fpc.ressym PROGBITS 08071254 029254 00000f 00 A 0 0 4
[14] fpc.resstr PROGBITS 08071264 029264 000000 00 A 0 0 4
[15] fpc.reshash PROGBITS 08071264 029264 000040 00 A 0 0 4
[16] fpc.resdata PROGBITS 080712a4 0292a4 0005b8 00 A 0 0 4
[17] .eh_frame PROGBITS 08072000 02a000 000004 00 WA 0 0 4
[18] .ctors PROGBITS 08072004 02a004 000008 00 WA 0 0 4
[19] .dtors PROGBITS 0807200c 02a00c 000008 00 WA 0 0 4
[20] .dynamic DYNAMIC 08072014 02a014 0000c8 08 WA 4 0 4
[21] .got PROGBITS 080720dc 02a0dc 000004 04 WA 0 0 4
[22] .got.plt PROGBITS 080720e0 02a0e0 00002c 04 WA 0 0 4
[23] .data PROGBITS 0807210c 02a10c 00b450 00 WA 0 0 4
[24] .bss NOBITS 0807d560 03555c 001dd8 00 WA 0 0 16
[25] fpc.resspare NOBITS 0807f338 03555c 0005b8 00 A 0 0 4
[26] .comment PROGBITS 00000000 03555c 000098 00 0 0 1
[27] .note NOTE 00000000 0355f4 000050 00 0 0 1
[28] .shstrtab STRTAB 00000000 035644 0000ed 00 0 0 1
As you can see, fpc.resspare got moved away, probably because it's of
NOBITS type.
Now the big questions is: Is there any way to force ld to put the fpc.resspare
section after fpc.resdata?
From reading the docs it appeared to me that possibly using a SECTIONS
command in the linker script might do the trick - so added the
following to the end of the linker script:
SECTIONS{
fpc.ressym : { *(fpc.ressym) }
fpc.resstr : { *(fpc.resstr) }
fpc.reshash : { *(fpc.reshash) }
fpc.resdata : { *(fpc.resdata) }
fpc.resspare : { *(fpc.resspare) }
}
Sadly this only results in
"Not enough room for program headers (allocated 5, need 6)" and "final
link failed: Bad value".
Here's the really simple linker script. I know it's ugly, that's
because it's auto-generated by the compiler. Don't be shocked of the
c:\crossfpc\... stuff, this is GNU ld version 2.15.94 20050118 used
for cross-compiling/linking ELF under Windows) ;)
SEARCH_DIR(C:\crossfpc\lib\)
SEARCH_DIR(.\)
SEARCH_DIR(C:\crossfpc\fpcunits\i386-linux\rtl\)
SEARCH_DIR(C:\crossfpc\kylixcompat\)
INPUT(
C:\crossfpc\fpcunits\i386-linux\rtl\cprt21.o
C:\crossfpc\lib\crtbegin.o
C:\crossfpc\lib\crti.o
res.o
C:\crossfpc\fpcunits\i386-linux\rtl\system.o
C:\crossfpc\fpcunits\i386-linux\rtl\objpas.o
C:\crossfpc\fpcunits\i386-linux\rtl\cmem.o
C:\crossfpc\fpcunits\i386-linux\rtl\sysutils.o
C:\crossfpc\fpcunits\i386-linux\rtl\unix.o
C:\crossfpc\fpcunits\i386-linux\rtl\errors.o
C:\crossfpc\fpcunits\i386-linux\rtl\sysconst.o
C:\crossfpc\fpcunits\i386-linux\rtl\unixtype.o
C:\crossfpc\fpcunits\i386-linux\rtl\baseunix.o
C:\crossfpc\fpcunits\i386-linux\rtl\strings.o
C:\crossfpc\fpcunits\i386-linux\rtl\syscall.o
)
GROUP(
C:\crossfpc\examples\resources\libptestres.a
)
INPUT(
-lc
)
INPUT(
C:\crossfpc\lib\crtend.o
C:\crossfpc\lib\crtn.o
)
Using this script works, but will change the section order of res.o as
explained above. Adding the SECTIONS stuff listed above to the end of
the script gives the error message above.
Any pointers on how to achieve my goal would be very welcome. If you
instead wish me to explain "the bigger picture" (WHY I need this),
I'll be happy to do that, too.
Thank you,
Simon