[PATCH] D92301: [LLD][ELF] - Don't keep empty output sections that are explicitly assigned to segment.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 30 04:11:07 PST 2020


grimar added inline comments.


================
Comment at: lld/test/ELF/linkerscript/implicit-program-header.test:10
 # CHECK:      Segment Sections...
-# CHECK-NEXT:   00     .dynsym .hash .dynstr .bar .foo .text .dynamic
-# CHECK-NEXT:   01     .bar .foo
+# CHECK-NEXT:   00     .dynsym .hash .dynstr .foo .text .dynamic
+# CHECK-NEXT:   01     .foo
----------------
jhenderson wrote:
> Unrelated to this patch, but it looks incorrect that .foo is assigned to this program header? It should be in ph_exec, and only ph_exec, by my understanding.
This happens because `.foo` is placed between `.dynsym` and `.dynamic` which belongs to "W" segment:

```
Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg L
k Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00
0   0  0
  [ 1] .dynsym           DYNSYM          0000000000000000 001000 000018 18   A
3   1  8
  [ 2] .hash             HASH            0000000000000018 001018 000010 04   A
1   0  4
  [ 3] .dynstr           STRTAB          0000000000000028 001028 000001 00   A
0   0  1
  [ 4] .foo              PROGBITS        0000000000000029 001029 000008 00  AX
0   0  1
  [ 5] .text             PROGBITS        0000000000000034 001034 000008 00  AX
0   0  4
  [ 6] .dynamic          DYNAMIC         0000000000000040 001040 000060 10  WA
3   0  8
  [ 7] .comment          PROGBITS        0000000000000000 0010a0 000008 01  MS
0   0  1
  [ 8] .symtab           SYMTAB          0000000000000000 0010a8 000030 18     1
0   2  8
  [ 9] .shstrtab         STRTAB          0000000000000000 0010d8 00004e 00
0   0  1
  [10] .strtab           STRTAB          0000000000000000 001126 00000a 00
0   0  1

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
  Flg Align
  LOAD           0x001000 0x0000000000000000 0x0000000000000000 0x0000a0 0x0000a
0  W  0x1000
  LOAD           0x001029 0x0000000000000029 0x0000000000000029 0x000008 0x00000
8   E 0x1000

 Section to Segment mapping:
  Segment Sections...
   00     .dynsym .hash .dynstr .foo .text .dynamic
   01     .foo
```

The output might looks strange, but I am not sure this is not correct. Sections are sorted by their flags as expected it seems.
I guess the linker script should be more precise about orphpans first of all for having a better and more stable behavior.




================
Comment at: lld/test/ELF/linkerscript/implicit-program-header.test:19
 SECTIONS {
   .bar : { *(.bar) } : ph_exec
   .foo : { *(.foo) }
----------------
jhenderson wrote:
> Is it worth extending this test case to show that ALL program headers are propagated, e.g. if .bar was inside `: ph_exec : ph_other` then .foo is too?
Done.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92301/new/

https://reviews.llvm.org/D92301



More information about the llvm-commits mailing list