This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

linker bug 10515


I've been looking at linker bug 10515 (http://sourceware.org/bugzilla/show_bug.cgi?id=10515) [the cvs-commit attached to it is a red-herring caused by a typoed bug number].

I attach a simpler testcase. the bad.ld script is ordering elf segments such that the second segment should contain the file header and program headers. As the file headers must be at offset zero, this forces the second segment to have a file offset of zero. however, we process segment mappings in the order of the PHDRs list, so by the time we get to place the second segment, we've placed the first segment at file offset 0x10000. This means we have to place the .text section at 0x20000, and hence the second elf segment spans over the first segment. The end result of this is that the second segment has a rather odd vma and lma because it needs to begin 0x20000 bytes before the .text section.

We could improve this by processing the PHDRS list such that a segment that must include the file headers is processed before the other segment placements. But as the PHDRs statement is there for exactly when the linker's automatic segment placement algorithm is insufficient, it seems rude for the linker to go altering the placement specified in the PHDRS list.

I see two better solutions:

1) fix it in the documentation. Add words to the 'PHDRS Command' section of the manual saying strange, but entirely logical, things happen if you attempt to add FILEHDRS and PHDRS to not-the-first segment.

2) make it an error to have FILEHDRS and/or PHDRS in not-the-first segment of the PHDRS statement.

thoughts?

nathan

--
Nathan Sidwell    ::   http://www.codesourcery.com   ::         CodeSourcery

	.globl _start
	.text
_start:	.4byte 0x12345678
	.data
	.4byte 0x9abcdef0
ENTRY(_start)
MEMORY
{
   mem_one : org = 1M, len = 1M
   mem_two : org = 2M, len = 1M
}

PHDRS
{
   phdr_one  PT_LOAD FLAGS ((4<<20) | 6);
   phdr_two  PT_LOAD FILEHDR PHDRS FLAGS (5);
}

SECTIONS
{
   . = 192M + 64K;
   .text . : AT (1M + 64K)
   {  *(.text)
   } :phdr_two

   . = 2M;
   .data . :
   {
     *(.data)
   } AT>mem_two :phdr_one
}
ENTRY(_start)
MEMORY
{
   mem_one : org = 1M, len = 1M
   mem_two : org = 2M, len = 1M
}

PHDRS
{
   phdr_one  PT_LOAD FILEHDR PHDRS FLAGS (5);
   phdr_two  PT_LOAD FLAGS ((4<<20) | 6);
}

SECTIONS
{
   . = 192M + 64K;
   .text . : AT (1M + 64K)
   {  *(.text)
   } :phdr_one

   . = 2M;
   .data . :
   {
     *(.data)
   } AT>mem_two :phdr_two
}

Attachment: bad
Description: Binary data

Attachment: good
Description: Binary data

There are 6 section headers, starting at offset 0x2002c:

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        0c010000 020000 000004 00  AX  0   0  1
  [ 2] .data             PROGBITS        00200000 010000 000004 00  WA  0   0  1
  [ 3] .shstrtab         STRTAB          00000000 020004 000027 00      0   0  1
  [ 4] .symtab           SYMTAB          00000000 02011c 000040 10      5   3  4
  [ 5] .strtab           STRTAB          00000000 02015c 000008 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

Elf file type is EXEC (Executable file)
Entry point 0xc010000
There are 2 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x010000 0x00200000 0x00200000 0x00004 0x00004 RW  0x10000
  LOAD           0x000000 0x0bff0000 0x000f0000 0x20004 0x20004 R E 0x10000

 Section to Segment mapping:
  Segment Sections...
   00     .data 
   01     .text 
There are 6 section headers, starting at offset 0x2002c:

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        0c010000 010000 000004 00  AX  0   0  1
  [ 2] .data             PROGBITS        00200000 020000 000004 00  WA  0   0  1
  [ 3] .shstrtab         STRTAB          00000000 020004 000027 00      0   0  1
  [ 4] .symtab           SYMTAB          00000000 02011c 000040 10      5   3  4
  [ 5] .strtab           STRTAB          00000000 02015c 000008 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

Elf file type is EXEC (Executable file)
Entry point 0xc010000
There are 2 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000000 0x0c000000 0x00100000 0x10004 0x10004 R E 0x10000
  LOAD           0x020000 0x00200000 0x00200000 0x00004 0x00004 RW  0x10000

 Section to Segment mapping:
  Segment Sections...
   00     .text 
   01     .data 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]