llvm-lto: default Relocation Model should be selected by the TargetMachine.

Right now, the createTargetMachine function in LTOBackend.cpp (used by llvm-lto, and other components) selects the default Relocation Model when none is specified in the module.
Other components (such as opt and llc) that construct a TargetMachine delegate the decision on the default value to the polymorphic TargetMachine's constructor.

This commit aligns llvm-lto with other components.

Reviewed By: daltenty, fhahn

Differential Revision: https://reviews.llvm.org/D97507
This commit is contained in:
Wael Yehia 2021-03-10 17:20:09 -05:00 committed by David Tenty
parent 1a808286ef
commit be646e3148
2 changed files with 14 additions and 2 deletions

View File

@ -184,10 +184,10 @@ createTargetMachine(const Config &Conf, const Target *TheTarget, Module &M) {
for (const std::string &A : Conf.MAttrs) for (const std::string &A : Conf.MAttrs)
Features.AddFeature(A); Features.AddFeature(A);
Reloc::Model RelocModel; Optional<Reloc::Model> RelocModel = None;
if (Conf.RelocModel) if (Conf.RelocModel)
RelocModel = *Conf.RelocModel; RelocModel = *Conf.RelocModel;
else else if (M.getModuleFlag("PIC Level"))
RelocModel = RelocModel =
M.getPICLevel() == PICLevel::NotPIC ? Reloc::Static : Reloc::PIC_; M.getPICLevel() == PICLevel::NotPIC ? Reloc::Static : Reloc::PIC_;

View File

@ -0,0 +1,12 @@
; REQUIRES: powerpc-registered-target
; RUN: llvm-as < %s > %t1
; RUN: llvm-lto %t1 | FileCheck %s
target triple = "powerpc-ibm-aix"
define i32 @main() {
entry:
ret i32 42
}
; CHECK: Wrote native object file