[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:
Petr Hosek 2019-07-20 21:59:47 +00:00
parent a2dd672c5f
commit ae4c30a4be
4 changed files with 17 additions and 1 deletions

View File

@ -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();
}

View File

@ -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_;

View File

@ -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();

View File

@ -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