[PATCH] D33372: Infer relocation model from module flags in relocatable LTO link

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 19 18:38:39 PDT 2017


pcc added a comment.

> Non-LTO pipeline allows the user to put PIC code in a non-PIE executable, or non-PIC code in a shared library if they wish so. Maybe we should completely ignore the output type here and strictly go by module flags, to be consistent.

Disabling PIC can sometimes act as an optimization. We may want to replace the reloc model field in `lto::Config` with a boolean that gives the backend permission to generate position-dependent code. Before we do that though, I think we will need to decide what to do about the other reloc models (dynamic-no-pic, rwpi, ropi, ropi-rwpi).



================
Comment at: lib/LTO/LTO.cpp:117
     AddString(A);
-  AddUnsigned(Conf.RelocModel);
+  AddUnsigned(Conf.RelocModel.hasValue() ? *Conf.RelocModel
+                                         : static_cast<unsigned>(-1));
----------------
I'd rewrite this with if/else and drop the `.hasValue()` here.


================
Comment at: lib/LTO/LTOBackend.cpp:132
 
+static Reloc::Model relocModelForModule(Config &C, Module &M) {
+  if (C.RelocModel.hasValue())
----------------
Can you pass the module into `createTargetMachine` and inline this function into it?


================
Comment at: lib/LTO/LTOBackend.cpp:133
+static Reloc::Model relocModelForModule(Config &C, Module &M) {
+  if (C.RelocModel.hasValue())
+    return *C.RelocModel;
----------------
Drop `.hasValue()`.


Repository:
  rL LLVM

https://reviews.llvm.org/D33372





More information about the llvm-commits mailing list