Help needed - defining the output section order

Nick Clifton nickc@redhat.com
Mon Aug 22 14:58:00 GMT 2005


Hi Simon,

> Sadly if I add my
>   fpc.ressym    : { *(fpc.ressym) }
>   fpc.resstr    : { *(fpc.resstr) }
>   fpc.reshash   : { *(fpc.reshash) }
>   fpc.resdata   : { *(fpc.resdata) }
>   fpc.resspare  : { *(fpc.resspare) }
> block to it, I'm back at "Not enough room for program headers
> (allocated 5, need 6)". Darn ;)

Right, but now you have a single script which contains a big SECTIONS 
command which handles everything and to which you can add a PHDR command.

Creating the PHDRS command should not be too bad.  Just take the linked 
  executable with the fpc.* sections in the wrong place and run "readelf 
-l" on it.  This should display the program headers for the executable. 
  Now all you have to do is to translate this information into a PHDRS 
command and add an extra header.

Here's an example from running this command on my local system:

   $ readelf -l `which readelf`
Program Headers:
   Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
   PHDR           0x000034 0x08048034 0x08048034 0x00100 0x00100 R E 0x4
   INTERP         0x000134 0x08048134 0x08048134 0x00013 0x00013 R   0x1
       [Requesting program interpreter: /lib/ld-linux.so.2]
   LOAD           0x000000 0x08048000 0x08048000 0x2fbdc 0x2fbdc R E 0x1000
   LOAD           0x02fbdc 0x08078bdc 0x08078bdc 0x005b8 0x01218 RW  0x1000
   DYNAMIC        0x02fbf0 0x08078bf0 0x08078bf0 0x000c8 0x000c8 RW  0x4
   NOTE           0x000148 0x08048148 0x08048148 0x00020 0x00020 R   0x4
   GNU_EH_FRAME   0x02fb64 0x08077b64 0x08077b64 0x0001c 0x0001c R   0x4
   GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x4

Which turns into:

PHDRS
{
   headers PT_PHDR PHDRS ;
   interp PT_INTERP ;
   text PT_LOAD FILEHDR ;
   data PT_LOAD ;
   dynamic PT_DYNAMIC ;
   note PT_NOTE ;
   gnu_eh_frame  0xa74e550 ;
   gnu_stack 0xa74e551 ;
   extra PT_LOAD ;
}

Note - I had to use numbers for the header types not supported by the 
linker script syntax.  You will probably not need to do this.

You may then find that you need to add ":<phdr-name>" to various parts 
of the SECTIONS command,  especially the fpc.* assignments.  eg:

    fpc.ressym    : { *(fpc.ressym) } :extra
    fpc.resstr    : { *(fpc.resstr) } :extra
    fpc.reshash   : { *(fpc.reshash) } :extra
    fpc.resdata   : { *(fpc.resdata) } :extra
    fpc.resspare  : { *(fpc.resspare) } :extra

Cheers
   Nick



More information about the Binutils mailing list