Skip to content

Commit dad7f79

Browse files
committed
[ARM] Set STT_TLS for a few relocation specifiers
Symbols referenced through TLSLDO and FDPIC TLS-specific specifiers should be set to STT_TLS as well.
1 parent e710797 commit dad7f79

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed

llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
8181
unsigned Kind = Fixup.getTargetKind();
8282
if (Kind >= FirstLiteralRelocationKind)
8383
return Kind - FirstLiteralRelocationKind;
84-
MCSymbolRefExpr::VariantKind Modifier = Target.getAccessVariant();
84+
MCSymbolRefExpr::VariantKind Specifier = Target.getAccessVariant();
8585
auto CheckFDPIC = [&](uint32_t Type) {
8686
if (getOSABI() != ELF::ELFOSABI_ARM_FDPIC)
8787
Ctx.reportError(Fixup.getLoc(),
@@ -91,13 +91,31 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
9191
return Type;
9292
};
9393

94+
switch (Specifier) {
95+
case MCSymbolRefExpr::VK_GOTTPOFF:
96+
case MCSymbolRefExpr::VK_GOTTPOFF_FDPIC:
97+
case MCSymbolRefExpr::VK_TLSCALL:
98+
case MCSymbolRefExpr::VK_TLSDESC:
99+
case MCSymbolRefExpr::VK_TLSGD:
100+
case MCSymbolRefExpr::VK_TLSGD_FDPIC:
101+
case MCSymbolRefExpr::VK_TLSLDM:
102+
case MCSymbolRefExpr::VK_TLSLDM_FDPIC:
103+
case MCSymbolRefExpr::VK_ARM_TLSLDO:
104+
case MCSymbolRefExpr::VK_TPOFF:
105+
if (auto *S = Target.getSymA())
106+
cast<MCSymbolELF>(S->getSymbol()).setType(ELF::STT_TLS);
107+
break;
108+
default:
109+
break;
110+
}
111+
94112
if (IsPCRel) {
95113
switch (Fixup.getTargetKind()) {
96114
default:
97115
Ctx.reportError(Fixup.getLoc(), "unsupported relocation type");
98116
return ELF::R_ARM_NONE;
99117
case FK_Data_4:
100-
switch (Modifier) {
118+
switch (Specifier) {
101119
default:
102120
Ctx.reportError(Fixup.getLoc(),
103121
"invalid fixup for 4-byte pc-relative data relocation");
@@ -120,7 +138,7 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
120138
}
121139
case ARM::fixup_arm_blx:
122140
case ARM::fixup_arm_uncondbl:
123-
switch (Modifier) {
141+
switch (Specifier) {
124142
case MCSymbolRefExpr::VK_PLT:
125143
return ELF::R_ARM_CALL;
126144
case MCSymbolRefExpr::VK_TLSCALL:
@@ -158,7 +176,7 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
158176
return ELF::R_ARM_THM_JUMP8;
159177
case ARM::fixup_arm_thumb_bl:
160178
case ARM::fixup_arm_thumb_blx:
161-
switch (Modifier) {
179+
switch (Specifier) {
162180
case MCSymbolRefExpr::VK_TLSCALL:
163181
return ELF::R_ARM_THM_TLS_CALL;
164182
default:
@@ -189,7 +207,7 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
189207
Ctx.reportError(Fixup.getLoc(), "unsupported relocation type");
190208
return ELF::R_ARM_NONE;
191209
case FK_Data_1:
192-
switch (Modifier) {
210+
switch (Specifier) {
193211
default:
194212
Ctx.reportError(Fixup.getLoc(),
195213
"invalid fixup for 1-byte data relocation");
@@ -198,7 +216,7 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
198216
return ELF::R_ARM_ABS8;
199217
}
200218
case FK_Data_2:
201-
switch (Modifier) {
219+
switch (Specifier) {
202220
default:
203221
Ctx.reportError(Fixup.getLoc(),
204222
"invalid fixup for 2-byte data relocation");
@@ -207,7 +225,7 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
207225
return ELF::R_ARM_ABS16;
208226
}
209227
case FK_Data_4:
210-
switch (Modifier) {
228+
switch (Specifier) {
211229
default:
212230
Ctx.reportError(Fixup.getLoc(),
213231
"invalid fixup for 4-byte data relocation");
@@ -263,7 +281,7 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
263281
case ARM::fixup_arm_uncondbranch:
264282
return ELF::R_ARM_JUMP24;
265283
case ARM::fixup_arm_movt_hi16:
266-
switch (Modifier) {
284+
switch (Specifier) {
267285
default:
268286
Ctx.reportError(Fixup.getLoc(), "invalid fixup for ARM MOVT instruction");
269287
return ELF::R_ARM_NONE;
@@ -273,7 +291,7 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
273291
return ELF::R_ARM_MOVT_BREL;
274292
}
275293
case ARM::fixup_arm_movw_lo16:
276-
switch (Modifier) {
294+
switch (Specifier) {
277295
default:
278296
Ctx.reportError(Fixup.getLoc(), "invalid fixup for ARM MOVW instruction");
279297
return ELF::R_ARM_NONE;
@@ -283,7 +301,7 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
283301
return ELF::R_ARM_MOVW_BREL_NC;
284302
}
285303
case ARM::fixup_t2_movt_hi16:
286-
switch (Modifier) {
304+
switch (Specifier) {
287305
default:
288306
Ctx.reportError(Fixup.getLoc(),
289307
"invalid fixup for Thumb MOVT instruction");
@@ -294,7 +312,7 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
294312
return ELF::R_ARM_THM_MOVT_BREL;
295313
}
296314
case ARM::fixup_t2_movw_lo16:
297-
switch (Modifier) {
315+
switch (Specifier) {
298316
default:
299317
Ctx.reportError(Fixup.getLoc(),
300318
"invalid fixup for Thumb MOVW instruction");

llvm/test/MC/ARM/fdpic.s

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: llvm-mc -triple=armv7-linux-gnueabi %s | FileCheck %s --check-prefix=ASM
2-
# RUN: llvm-mc -filetype=obj -triple=armv7-linux-gnueabi --fdpic %s | llvm-readelf -h -r - | FileCheck %s
2+
# RUN: llvm-mc -filetype=obj -triple=armv7-linux-gnueabi --fdpic %s | llvm-readelf -h -r -s - | FileCheck %s --implicit-check-not=TLS
33

44
# RUN: not llvm-mc -filetype=obj -triple=armv7-linux-gnueabi %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR
55

@@ -14,9 +14,13 @@
1414
# CHECK: R_ARM_FUNCDESC 00000000 f
1515
# CHECK-NEXT: R_ARM_GOTFUNCDESC 00000000 f
1616
# CHECK-NEXT: R_ARM_GOTOFFFUNCDESC 00000000 f
17-
# CHECK-NEXT: R_ARM_TLS_GD32_FDPIC 00000000 tls
18-
# CHECK-NEXT: R_ARM_TLS_LDM32_FDPIC 00000000 tls
19-
# CHECK-NEXT: R_ARM_TLS_IE32_FDPIC 00000000 tls
17+
# CHECK-NEXT: R_ARM_TLS_GD32_FDPIC 00000000 tls0
18+
# CHECK-NEXT: R_ARM_TLS_LDM32_FDPIC 00000000 tls1
19+
# CHECK-NEXT: R_ARM_TLS_IE32_FDPIC 00000000 tls2
20+
21+
# CHECK: TLS GLOBAL DEFAULT UND tls0
22+
# CHECK: TLS GLOBAL DEFAULT UND tls1
23+
# CHECK: TLS GLOBAL DEFAULT UND tls2
2024

2125
.data
2226
# ERR: [[#@LINE+1]]:7: error: relocation R_ARM_FUNCDESC only supported in FDPIC mode
@@ -26,8 +30,8 @@
2630
# ERR: [[#@LINE+1]]:7: error: relocation R_ARM_GOTOFFFUNCDESC only supported in FDPIC mode
2731
.long f(GOTOFFFUNCDESC)
2832
# ERR: [[#@LINE+1]]:7: error: relocation R_ARM_TLS_GD32_FDPIC only supported in FDPIC mode
29-
.long tls(tlsgd_fdpic)
33+
.long tls0(tlsgd_fdpic)
3034
# ERR: [[#@LINE+1]]:7: error: relocation R_ARM_TLS_LDM32_FDPIC only supported in FDPIC mode
31-
.long tls(tlsldm_fdpic)
35+
.long tls1(tlsldm_fdpic)
3236
# ERR: [[#@LINE+1]]:7: error: relocation R_ARM_TLS_IE32_FDPIC only supported in FDPIC mode
33-
.long tls(gottpoff_fdpic)
37+
.long tls2(gottpoff_fdpic)

llvm/test/MC/ARM/symbol-variants.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ bl f05(plt)
7777
.word f21(tlsldo)
7878
@CHECK: 50 R_ARM_TLS_LDO32 f20
7979
@CHECK: 54 R_ARM_TLS_LDO32 f21
80-
@READELF: NOTYPE GLOBAL DEFAULT UND f20
81-
@READELF: NOTYPE GLOBAL DEFAULT UND f21
80+
@READELF: TLS GLOBAL DEFAULT UND f20
81+
@READELF: TLS GLOBAL DEFAULT UND f21
8282

8383
@ tlscall
8484
.word f22(TLSCALL)

0 commit comments

Comments
 (0)