llvm.org GIT mirror llvm / 253933e
Teach LLVM about a PIE option which, when enabled on top of PIC, makes optimizations which are valid for position independent code being linked into a single executable, but not for such code being linked into a shared library. I discussed the design of this with Eric Christopher, and the decision was to support an optional bit rather than a completely separate relocation model. Fundamentally, this is still PIC relocation, its just that certain optimizations are only valid under a PIC relocation model when the resulting code won't be in a shared library. The simplest path to here is to expose a single bit option in the TargetOptions. If folks have different/better designs, I'm all ears. =] I've included the first optimization based upon this: changing TLS models to the *Exec models when PIE is enabled. This is the LLVM component of PR12380 and is all of the hard work. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154294 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 8 years ago
4 changed file(s) with 80 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
4141 GuaranteedTailCallOpt(false), DisableTailCalls(false),
4242 StackAlignmentOverride(0), RealignStack(true),
4343 DisableJumpTables(false), EnableFastISel(false),
44 EnableSegmentedStacks(false), TrapFuncName(""),
45 FloatABIType(FloatABI::Default)
44 PositionIndependentExecutable(false), EnableSegmentedStacks(false),
45 TrapFuncName(""), FloatABIType(FloatABI::Default)
4646 {}
4747
4848 /// PrintMachineCode - This flag is enabled when the -print-machineinstrs
163163 /// compile time.
164164 unsigned EnableFastISel : 1;
165165
166 /// PositionIndependentExecutable - This flag indicates whether the code
167 /// will eventually be linked into a single executable, despite the PIC
168 /// relocation model being in use. It's value is undefined (and irrelevant)
169 /// if the relocation model is anything other than PIC.
170 unsigned PositionIndependentExecutable : 1;
171
166172 unsigned EnableSegmentedStacks : 1;
167173
168174 /// getTrapFunctionName - If this returns a non-empty string, this means
8181 // For variables, is internal different from hidden?
8282 bool isHidden = GV->hasHiddenVisibility();
8383
84 if (getRelocationModel() == Reloc::PIC_) {
84 if (getRelocationModel() == Reloc::PIC_ &&
85 !Options.PositionIndependentExecutable) {
8586 if (isLocal || isHidden)
8687 return TLSModel::LocalDynamic;
8788 else
0 ; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu -relocation-model=pic -enable-pie \
1 ; RUN: | FileCheck -check-prefix=X32 %s
2 ; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu -relocation-model=pic -enable-pie \
3 ; RUN: | FileCheck -check-prefix=X64 %s
4
5 @i = thread_local global i32 15
6 @i2 = external thread_local global i32
7
8 define i32 @f1() {
9 ; X32: f1:
10 ; X32: movl %gs:i@NTPOFF, %eax
11 ; X32-NEXT: ret
12 ; X64: f1:
13 ; X64: movabsq $i@TPOFF, %rax
14 ; X64-NEXT: movl %fs:(%rax), %eax
15 ; X64-NEXT: ret
16
17 entry:
18 %tmp1 = load i32* @i
19 ret i32 %tmp1
20 }
21
22 define i32* @f2() {
23 ; X32: f2:
24 ; X32: movl %gs:0, %eax
25 ; X32-NEXT: leal i@NTPOFF(%eax), %eax
26 ; X32-NEXT: ret
27 ; X64: f2:
28 ; X64: movq %fs:0, %rax
29 ; X64-NEXT: addq $i@TPOFF, %rax
30 ; X64-NEXT: ret
31
32 entry:
33 ret i32* @i
34 }
35
36 define i32 @f3() {
37 ; X32: f3:
38 ; X32: movl i2@INDNTPOFF, %eax
39 ; X32-NEXT: movl %gs:(%eax), %eax
40 ; X32-NEXT: ret
41 ; X64: f3:
42 ; X64: movq i2@GOTTPOFF(%rip), %rax
43 ; X64-NEXT: movl %fs:(%rax), %eax
44 ; X64-NEXT: ret
45
46 entry:
47 %tmp1 = load i32* @i2
48 ret i32 %tmp1
49 }
50
51 define i32* @f4() {
52 ; X32: f4:
53 ; X32: movl %gs:0, %eax
54 ; X32-NEXT: addl i2@INDNTPOFF, %eax
55 ; X32-NEXT: ret
56 ; X64: f4:
57 ; X64: movq %fs:0, %rax
58 ; X64-NEXT: addq i2@GOTTPOFF(%rip), %rax
59 ; X64-NEXT: ret
60
61 entry:
62 ret i32* @i2
63 }
262262 cl::init(""));
263263
264264 static cl::opt
265 EnablePIE("enable-pie",
266 cl::desc("Assume the creation of a position independent executable."),
267 cl::init(false));
268
269 static cl::opt
265270 SegmentedStacks("segmented-stacks",
266271 cl::desc("Use segmented stacks if possible."),
267272 cl::init(false));
466471 Options.RealignStack = EnableRealignStack;
467472 Options.DisableJumpTables = DisableSwitchTables;
468473 Options.TrapFuncName = TrapFuncName;
474 Options.PositionIndependentExecutable = EnablePIE;
469475 Options.EnableSegmentedStacks = SegmentedStacks;
470476
471477 std::auto_ptr