[PATCH] D23352: [ELF] - Linkerscript: implemented simple heuristic for placing orphan sections.

Sean Silva via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 15 21:04:43 PDT 2016


silvas added a subscriber: silvas.
silvas added a comment.

Thanks for working on this George, this is really helpful for building the FreeBSD kernel. One comment inline.

FYI, Michael and I are also debugging why the bootloader doesn't like LLD produced binaries. Besides the issue addressed by this patch, so far we have identified two other issues (there are more, but these are the ones we've identified so far):

- `__start_SECNAME`/`__stop_SECNAME` are not exported in the dynamic symbol table. This is needed for the loader which looks up `__start_set_modmetadata_set`/`__stop_set_modmetadata_set`.

- LLD does not honor MAXPAGESIZE (needs to be 2M for amd64), this causes the kernel load address to get set far too low (at 4K, close to where the loader lives), which clobbers the loader's text / data structures when copying in the kernel :)

Hopefully it saves you some time!


================
Comment at: ELF/LinkerScript.cpp:283
@@ +282,3 @@
+                        [&](OutputSectionBase<ELFT> *S) {
+                          return getPermissions(S) == getPermissions(OutSec);
+                        });
----------------
I think this also needs to check `&& !(S->getType() & SHT_NOBITS)` so that we don't add a PROGBITS section into BSS.

E.g. with this patch applied I get this error during a FreeBSD kernel build:

```
BFD: stc5VrZP: section set_pcpu lma 0xffffffff81529d80 overlaps previous sections
BFD: stc5VrZP: section `set_pcpu' can't be allocated in segment 5
objcopy: stc5VrZP: Bad value
BFD: stc5VrZP: section set_pcpu lma 0xffffffff81529d80 overlaps previous sections
BFD: stc5VrZP: section `set_pcpu' can't be allocated in segment 5
objcopy: stc5VrZP: Bad value
*** Error code 1
```

Relevant section of `readelf --sections` output on the binary produced by this patch:
```
  [33] .data             PROGBITS         ffffffff81401000  01015000
       000000000012823c  0000000000000000  WA       0     0     32
  [34] .bss              NOBITS           ffffffff81529280  0113d23c
       0000000000207ad0  0000000000000000  WA       0     0     128
  [35] set_pcpu          PROGBITS         ffffffff81730d80  0113dd80
       00000000000010b0  0000000000000000  WA       0     0     128
```


https://reviews.llvm.org/D23352





More information about the llvm-commits mailing list