[PATCH] D47396: [LLD] Place .nv_fatbin section at the beginning of the executable.

Artem Belevich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 25 16:49:22 PDT 2018


tra added a comment.

In https://reviews.llvm.org/D47396#1113016, @hfinkel wrote:

> Does this just not work well with other linkers, do other linkers also have special handling, or does it work better elsewhere for some other reason?


With ld.bfd I could use ldscript with "INSERT BEFORE" in it to tell it where to place .nv_fatbin. Alas, we're not using it.
ld.gold does not support INSERT BEFORE at all and currently just silently corrupts the executable when relocs overflow.
ld.lld sort of supports custom lld script with INSERT BEFORE, but the problem is that it only overrides explicitly provided full ldscript and does not work without it.
I've attempted to feed ld.lld linker scripts from ld.bfd, but that didn't get me far I've failed to create a ldscript good enough to produce a working app. Either LLD is not happy about section placement, or the executable does not work (usually failing in dynamic linker or early libc init phases).

So, tweaking LLD is the only practical option I see ATM.

In https://reviews.llvm.org/D47396#1113018, @ruiu wrote:

> Though this should work as a local patch, I think this is too specific to the NVidia-supplied binary blob that gets linked to your program. Is there any way to generalize this or change your binary?


This is not just for nvidia-supplied libs. This is also the section where clang puts generated GPU code as well.
I'm not sure what we can generalize here or how we can change the binary.

In https://reviews.llvm.org/D47396#1113019, @pcc wrote:

> Here's one generalization idea: move `.rodata` to the end of the r/o segment. That should let us drop the special cases for `.dynsym` and `.dynstr` as well.


It only works if there are no other read-only sections that need to be accessed from .text.
For instance various exception handling bits that  may end up being placed before .nv_fatbin, and we'd still get reloc overflows.


https://reviews.llvm.org/D47396





More information about the llvm-commits mailing list