[PATCH] D27516: [ELF] - Place ".text" to be first section if -Ttext is used.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 7 11:09:44 PST 2016


>Oh, is the loader trying to set the address of the section .text or of
>the PT_LOAD? If the section, what exactly is it trying to do?
>
I do not know that =/ Loader I am trying to fix is PR31295. It sets -Ttext=0x0.
I was basing on documentation about -Ttext which says it sets address for .text section.

In that case:
1) gold output is:
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        00000080 000080 00ba74 00  AX  0   0 16
Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000000 0x00000000 0x00000000 0x0f238 0x18628 RWE 0x10
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0

2) bfd is:
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 000080 00ba74 00 WAX  0   0 16
Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000080 0x00000000 0x00000000 0x0f1b0 0x18598 RWE 0x10
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RWE 0x10

So both linkers set PT_LOAD address to 0x0. If I do -Ttext=0x30000 for example,
gold and bfd set .text to 0x30080 and 0x30000, but again both set PT_LOAD address to exactly 0x30000.
May be that is what was really expected then.

>If it has expectations on the section order it seems better to use a
>linker script.
>
Issue here that we have next order:
.rodata
.text
<others>

and starting assigning address from .rodata = ImageBase and then
assign .text to 0x0. After that we continue set addressed to sections starting from that 0x0
and that can lead to overlap.
Both gold/bfd assigns VA to sections starting from .text  and -Ttext value in that case and free from such problem.

>If what it really wants is to set a particular section at a particular
>address, I think we can implement that, but as Rui points out we should
>have a general solution.
>
>One such solution would be to put all section with specified addresses
>before other sections and to order them based of the address value.
>
>I don't think we should try to do something fancier like looking for an
>empty spot when placing each section.


George.


More information about the llvm-commits mailing list