[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
Sun Jul 14 17:44:09 PDT 2019


phosek created this revision.
phosek added reviewers: ruiu, tejohnson.
Herald added subscribers: llvm-commits, dang, dexonsmith, steven_wu, MaskRay, arichardson, inglorion, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Currently, lld LTO configuration explicitly sets relocation model
based on the linker flags, effectively overriding whatever model is
stored inside the module. This behavior differs from the behavior
one would get during regular linking or even ThinLTO with explicit
codegen where the linker flags such as -r, -pie or -shared don't
affect codegen. This breaks the case where user wants to deliberately
select different relocation model for codegen and for linking, which
is can be the case in special environments like kernels.

Concretely, we stumbled upon this issue while trying to build Zircon
kernel with ThinLTO but the resulting kernel wouldn't boot. Upon
investigation, we've noticed that the kernel code is non-relocatable
despite it being compiled with -fpie. The problem was that our build
passes --no-pie to the linker. This is on purpose, while we want pie
codegen, we want to link the final binary to be linked as static one
(because there's no dynamic linker in our environment).

This change alters the behavior to use the relocation model stored
in the module which is the default behavior of the LTO backend, and
allows overriding the model via -mllvm flag. This matches the behavior
already used for code model. With this change, our kernel builds and
boots even when built with (Thin)LTO.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D64711

Files:
  lld/Common/TargetOptionsCommandFlags.cpp
  lld/ELF/LTO.cpp
  lld/include/lld/Common/TargetOptionsCommandFlags.h
  lld/test/ELF/lto/discard-value-names.ll
  lld/test/ELF/lto/relax-relocs.ll
  lld/test/ELF/lto/relocation-model.ll
  lld/test/ELF/lto/section-name.ll
  lld/test/ELF/lto/unnamed-addr.ll
  llvm/include/llvm/LTO/Config.h
  llvm/test/LTO/Resolution/X86/not-prevailing-alias.ll
  llvm/test/LTO/X86/codemodel-1.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64711.209751.patch
Type: text/x-patch
Size: 6537 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190715/8bdb240f/attachment.bin>


More information about the llvm-commits mailing list