forked from OSchip/llvm-project
[ELF] Support explicitly overriding relocation model in LTO
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. llvm-svn: 366644
This commit is contained in:
parent
a2dd672c5f
commit
ae4c30a4be
|
@ -26,6 +26,10 @@ llvm::TargetOptions lld::initTargetOptionsFromCodeGenFlags() {
|
|||
return ::InitTargetOptionsFromCodeGenFlags();
|
||||
}
|
||||
|
||||
llvm::Optional<llvm::Reloc::Model> lld::getRelocModelFromCMModel() {
|
||||
return getRelocModel();
|
||||
}
|
||||
|
||||
llvm::Optional<llvm::CodeModel::Model> lld::getCodeModelFromCMModel() {
|
||||
return getCodeModel();
|
||||
}
|
||||
|
|
|
@ -76,7 +76,9 @@ static lto::Config createConfig() {
|
|||
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_;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue