[PATCH] D64711: [LTO] Don't override relocation model stored in the module

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 15 18:06:56 PDT 2019


phosek added a comment.

In D64711#1586738 <https://reviews.llvm.org/D64711#1586738>, @pcc wrote:

> In D64711#1586696 <https://reviews.llvm.org/D64711#1586696>, @phosek wrote:
>
> > In D64711#1584916 <https://reviews.llvm.org/D64711#1584916>, @pcc wrote:
> >
> > > I'd like to understand the motivation behind this change a little better because the relaxation of the code model from PIC to static is technically an "optimization" that the linker should have license to perform and in fact is already performing in some ways (e.g. emitting addresses into the binary instead of RELATIVE/RELR relocations for statically known addresses).
> >
> >
> > In the case of our kernel, we need the generated code to be position independent for our KASLR scheme, but we're not doing traditional PIE link. When compiling individual translation units, we use `-fpie`, but when linking we use `--no-pie`. Changing the code model from PIC to static in this case results in an invalid kernel image because the generated code is not relocatable. I think it's a matter of principle that it shouldn't be the linker's responsibility to decide how to combine our code-generation choices with our linking choices. I'm open to suggestions for other ways to solve this issue though as we'd really like to be able to use ThinLTO for our kernel.
>
>
> Have you considered linking the kernel as a PIE image when KASLR is enabled? This will fix not only this problem but also others (e.g. initializers containing global pointers, which might not just be explicit in the source code but could also be implicitly generated by the compiler, are broken with this scheme).
>
> This is what the Linux kernel does (it uses `-shared -Bsymbolic` instead of `-pie` in KASLR mode, but they are almost equivalent):
>  https://github.com/torvalds/linux/blob/fec88ab0af9706b2201e5daf377c5031c62d11f7/arch/arm64/Makefile#L21
>
> It uses assembly to self relocate to avoid depending on relative relocations during early startup:
>  https://github.com/torvalds/linux/blob/fec88ab0af9706b2201e5daf377c5031c62d11f7/arch/arm64/kernel/head.S#L822


We're considering it but it requires some non-trivial changes and so won't be ready anytime soon.


Repository:
  rLLD LLVM Linker

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

https://reviews.llvm.org/D64711





More information about the llvm-commits mailing list