Help needed - defining the output section order
Nick Clifton
nickc@redhat.com
Mon Aug 22 12:03:00 GMT 2005
Hi Simon,
> Now the big questions is: Is there any way to force ld to put the fpc.resspare
> section after fpc.resdata?
Yes - use the SECTIONS command in the linker script...
> 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".
Ah well, that is because your new linker script is too simple. There is
a section in the linker documentation that talks about this problem:
When producing an ELF output file, if the linker script uses
the SIZEOF_HEADERS builtin function, the linker must compute
the number of program headers before it has determined all
the section addresses and sizes. If the linker later
discovers that it needs additional program headers, it will
report an error "not enough room for program headers". To
avoid this error, you must avoid using the SIZEOF_HEADERS
function, or you must rework your linker script to avoid
forcing the linker to use additional program headers, or
you must define the program headers yourself using the
PHDRS command.
So what you probably need to do is to add a PHDRS command to your linker
script.
Plus what you probably really want to do is to find out the default
script used by the linker (by running ld --verbose) and then take the
SECTIONS command from there and merge in your fpc.* sections. The
SECTIONS command in the default script will probably be a lot more
comprehensive than the one that you are currently using.
Cheers
Nick
More information about the Binutils
mailing list