[PATCH] D65032: [ELF] Support explicitly overriding relocation model in LTO
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 19 17:49:55 PDT 2019
phosek created this revision.
phosek added a reviewer: pcc.
Herald added subscribers: llvm-commits, dexonsmith, steven_wu, MaskRay, arichardson, inglorion, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
lld currently selects the relocation model automatically depending on
the link flags specified, but in some cases it'd be useful to allow
explicitly overriding the relocation model using a flag.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D65032
Files:
lld/Common/TargetOptionsCommandFlags.cpp
lld/ELF/LTO.cpp
lld/include/lld/Common/TargetOptionsCommandFlags.h
lld/test/ELF/lto/relocation-model.ll
Index: lld/test/ELF/lto/relocation-model.ll
===================================================================
--- lld/test/ELF/lto/relocation-model.ll
+++ lld/test/ELF/lto/relocation-model.ll
@@ -33,6 +33,15 @@
; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=PIC
+;; Explicit flag.
+
+; RUN: ld.lld %t.o -o %t-out -save-temps -r -mllvm -relocation-model=pic
+; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=PIC
+
+; RUN: ld.lld %t.o -o %t-out -save-temps -r --export-dynamic --noinhibit-exec -mllvm -relocation-model=static
+; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=STATIC
+
+
; PIC: R_X86_64_REX_GOTPCRELX foo
; STATIC: R_X86_64_PC32 foo
Index: lld/include/lld/Common/TargetOptionsCommandFlags.h
===================================================================
--- lld/include/lld/Common/TargetOptionsCommandFlags.h
+++ lld/include/lld/Common/TargetOptionsCommandFlags.h
@@ -16,6 +16,7 @@
namespace lld {
llvm::TargetOptions initTargetOptionsFromCodeGenFlags();
+llvm::Optional<llvm::Reloc::Model> getRelocModelFromCMModel();
llvm::Optional<llvm::CodeModel::Model> getCodeModelFromCMModel();
std::string getCPUStr();
std::vector<std::string> getMAttrs();
Index: lld/ELF/LTO.cpp
===================================================================
--- lld/ELF/LTO.cpp
+++ lld/ELF/LTO.cpp
@@ -76,7 +76,9 @@
c.Options.FunctionSections = true;
c.Options.DataSections = true;
- if (config->relocatable)
+ if (auto relocModel = getRelocModelFromCMModel())
+ c.RelocModel = *relocModel;
+ else if (config->relocatable)
c.RelocModel = None;
else if (config->isPic)
c.RelocModel = Reloc::PIC_;
Index: lld/Common/TargetOptionsCommandFlags.cpp
===================================================================
--- lld/Common/TargetOptionsCommandFlags.cpp
+++ lld/Common/TargetOptionsCommandFlags.cpp
@@ -26,6 +26,10 @@
return ::InitTargetOptionsFromCodeGenFlags();
}
+llvm::Optional<llvm::Reloc::Model> lld::getRelocModelFromCMModel() {
+ return getRelocModel();
+}
+
llvm::Optional<llvm::CodeModel::Model> lld::getCodeModelFromCMModel() {
return getCodeModel();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65032.210941.patch
Type: text/x-patch
Size: 2177 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190720/a1988ecd/attachment.bin>
More information about the llvm-commits
mailing list