[PATCH] D65032: [ELF] Support explicitly overriding relocation model in LTO
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 20 15:00:03 PDT 2019
phosek updated this revision to Diff 210974.
phosek marked an inline comment as done.
Repository:
rLLD LLVM Linker
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D65032/new/
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 -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.210974.patch
Type: text/x-patch
Size: 2143 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190720/4b503723/attachment.bin>
More information about the llvm-commits
mailing list