Skip to content

Commit be646e3

Browse files
Wael Yehiadaltenty
authored andcommitted
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
1 parent 1a80828 commit be646e3

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

llvm/lib/LTO/LTOBackend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ createTargetMachine(const Config &Conf, const Target *TheTarget, Module &M) {
184184
for (const std::string &A : Conf.MAttrs)
185185
Features.AddFeature(A);
186186

187-
Reloc::Model RelocModel;
187+
Optional<Reloc::Model> RelocModel = None;
188188
if (Conf.RelocModel)
189189
RelocModel = *Conf.RelocModel;
190-
else
190+
else if (M.getModuleFlag("PIC Level"))
191191
RelocModel =
192192
M.getPICLevel() == PICLevel::NotPIC ? Reloc::Static : Reloc::PIC_;
193193

test/tools/llvm-lto/aix.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; REQUIRES: powerpc-registered-target
2+
; RUN: llvm-as < %s > %t1
3+
; RUN: llvm-lto %t1 | FileCheck %s
4+
5+
target triple = "powerpc-ibm-aix"
6+
7+
define i32 @main() {
8+
entry:
9+
ret i32 42
10+
}
11+
; CHECK: Wrote native object file
12+

0 commit comments

Comments
 (0)