Skip to content

Commit 459e8e9

Browse files
author
Justin Hibbits
committed
[PowerPC]: Don't allow r0 as a target for LD_GOT_TPREL_L/32
Summary: The linker is free to relax this (relocation R_PPC_GOT_TPREL16) against R_PPC_TLS, if it sees fit (initial exec to local exec). If r0 is used, this can generate execution-invalid code (converts to 'addi %rX, %r0, FOO, which translates in PPC-lingo to li %rX, FOO). Forbid this instead. This fixes static binaries using locales on FreeBSD/powerpc (tested on FreeBSD/powerpcspe). Reviewed By: nemanjai Differential Revision: https://reviews.llvm.org/D76662
1 parent a92673f commit 459e8e9

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

llvm/lib/Target/PowerPC/PPCInstr64Bit.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ def ADDISgotTprelHA: PPCEmitTimePseudo<(outs g8rc:$rD), (ins g8rc_nox0:$reg, s16
11271127
(PPCaddisGotTprelHA i64:$reg,
11281128
tglobaltlsaddr:$disp))]>,
11291129
isPPC64;
1130-
def LDgotTprelL: PPCEmitTimePseudo<(outs g8rc:$rD), (ins s16imm64:$disp, g8rc_nox0:$reg),
1130+
def LDgotTprelL: PPCEmitTimePseudo<(outs g8rc_nox0:$rD), (ins s16imm64:$disp, g8rc_nox0:$reg),
11311131
"#LDgotTprelL",
11321132
[(set i64:$rD,
11331133
(PPCldGotTprelL tglobaltlsaddr:$disp, i64:$reg))]>,

llvm/lib/Target/PowerPC/PPCInstrInfo.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3213,7 +3213,7 @@ def PPC32GOT: PPCEmitTimePseudo<(outs gprc:$rD), (ins), "#PPC32GOT",
32133213
def PPC32PICGOT: PPCEmitTimePseudo<(outs gprc:$rD, gprc:$rT), (ins), "#PPC32PICGOT",
32143214
[]>, NoEncode<"$rT">;
32153215

3216-
def LDgotTprelL32: PPCEmitTimePseudo<(outs gprc:$rD), (ins s16imm:$disp, gprc_nor0:$reg),
3216+
def LDgotTprelL32: PPCEmitTimePseudo<(outs gprc_nor0:$rD), (ins s16imm:$disp, gprc_nor0:$reg),
32173217
"#LDgotTprelL32",
32183218
[(set i32:$rD,
32193219
(PPCldGotTprelL tglobaltlsaddr:$disp, i32:$reg))]>;

llvm/test/CodeGen/PowerPC/tls.ll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
;OPT1-LABEL: localexec:
1212
define i32 @localexec() nounwind {
1313
entry:
14-
;OPT0: addis [[REG1:[0-9]+]], 13, a@tprel@ha
15-
;OPT0-NEXT: addi [[REG2:[0-9]+]], [[REG1]], a@tprel@l
14+
;OPT0: addis [[REG1:[1-9][0-9]*]], 13, a@tprel@ha
15+
;OPT0-NEXT: addi [[REG2:[1-9][0-9]*]], [[REG1]], a@tprel@l
1616
;OPT0-NEXT: li [[REG3:[0-9]+]], 42
1717
;OPT0: stw [[REG3]], 0([[REG2]])
18-
;OPT1: addis [[REG1:[0-9]+]], 13, a@tprel@ha
18+
;OPT1: addis [[REG1:[1-9][0-9]*]], 13, a@tprel@ha
1919
;OPT1-NEXT: li [[REG3:[0-9]+]], 42
2020
;OPT1: stw [[REG3]], a@tprel@l([[REG1]])
2121
store i32 42, i32* @a, align 4
@@ -36,19 +36,19 @@ entry:
3636
}
3737

3838
; OPT1-LABEL: main2:
39-
; OPT1: addis [[REG1:[0-9]+]], 2, a2@got@tprel@ha
39+
; OPT1: addis [[REG1:[1-9][0-9]*]], 2, a2@got@tprel@ha
4040
; OPT1: ld [[REG2:[0-9]+]], a2@got@tprel@l([[REG1]])
4141
; OPT1: add {{[0-9]+}}, [[REG2]], a2@tls
4242

4343
;OPT0-PPC32-LABEL: main2:
44-
;OPT0-PPC32: li [[REG1:[0-9]+]], _GLOBAL_OFFSET_TABLE_@l
44+
;OPT0-PPC32: li [[REG1:[1-9][0-9]*]], _GLOBAL_OFFSET_TABLE_@l
4545
;OPT0-PPC32: addis [[REG1]], [[REG1]], _GLOBAL_OFFSET_TABLE_@ha
46-
;OPT0-PPC32: lwz [[REG2:[0-9]+]], a2@got@tprel([[REG1]])
46+
;OPT0-PPC32: lwz [[REG2:[1-9][0-9]*]], a2@got@tprel([[REG1]])
4747
;OPT0-PPC32: add 3, [[REG2]], a2@tls
4848

4949
;OPT0-PPC32-PIC-LABEL: main2:
5050
;OPT0-PPC32-PIC: .long _GLOBAL_OFFSET_TABLE_-{{.*}}
5151
;OPT0-PPC32-PIC-NOT: li {{[0-9]+}}, _GLOBAL_OFFSET_TABLE_@l
52-
;OPT0-PPC32-PIC-NOT: addis {{[0-9]+}}, {{[0-9+]}}, _GLOBAL_OFFSET_TABLE_@ha
52+
;OPT0-PPC32-PIC-NOT: addis {{[0-9]+}}, {{[1-9][0-9*]}}, _GLOBAL_OFFSET_TABLE_@ha
5353
;OPT0-PPC32-PIC-NOT: bl __tls_get_addr(a2@tlsgd)@PLT
54-
;OPT0-PPC32-PIC: lwz {{[0-9]+}}, a2@got@tprel({{[0-9]+}})
54+
;OPT0-PPC32-PIC: lwz {{[0-9]+}}, a2@got@tprel({{[1-9][0-9]*}})

0 commit comments

Comments
 (0)