[llvm] 417390d - [M68k] Set STT_TLS for TLS relocations
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 22 18:33:47 PDT 2025
Author: Fangrui Song
Date: 2025-03-22T18:33:42-07:00
New Revision: 417390d77d6f828a2f2341e0565784c677ef13ab
URL: https://github.com/llvm/llvm-project/commit/417390d77d6f828a2f2341e0565784c677ef13ab
DIFF: https://github.com/llvm/llvm-project/commit/417390d77d6f828a2f2341e0565784c677ef13ab.diff
LOG: [M68k] Set STT_TLS for TLS relocations
Added:
llvm/test/MC/M68k/Relocations/tls.s
Modified:
llvm/lib/Target/M68k/MCTargetDesc/M68kELFObjectWriter.cpp
llvm/lib/Target/M68k/MCTargetDesc/M68kMCExpr.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/M68k/MCTargetDesc/M68kELFObjectWriter.cpp b/llvm/lib/Target/M68k/MCTargetDesc/M68kELFObjectWriter.cpp
index 950f14d3b910d..4a08591629e35 100644
--- a/llvm/lib/Target/M68k/MCTargetDesc/M68kELFObjectWriter.cpp
+++ b/llvm/lib/Target/M68k/MCTargetDesc/M68kELFObjectWriter.cpp
@@ -68,6 +68,19 @@ unsigned M68kELFObjectWriter::getRelocType(MCContext &Ctx,
auto Specifier = M68kMCExpr::Specifier(Target.getAccessVariant());
unsigned Kind = Fixup.getKind();
M68kRelType Type = getType(Kind, Specifier, IsPCRel);
+ switch (Specifier) {
+ case M68kMCExpr::VK_GOTTPOFF:
+ case M68kMCExpr::VK_TLSGD:
+ case M68kMCExpr::VK_TLSLD:
+ case M68kMCExpr::VK_TLSLDM:
+ case M68kMCExpr::VK_TPOFF:
+ if (auto *S = Target.getSymA())
+ cast<MCSymbolELF>(S->getSymbol()).setType(ELF::STT_TLS);
+ break;
+ default:
+ break;
+ }
+
switch (Specifier) {
default:
llvm_unreachable("Unimplemented");
diff --git a/llvm/lib/Target/M68k/MCTargetDesc/M68kMCExpr.h b/llvm/lib/Target/M68k/MCTargetDesc/M68kMCExpr.h
index a38569e322ae4..d9b72da6318fc 100644
--- a/llvm/lib/Target/M68k/MCTargetDesc/M68kMCExpr.h
+++ b/llvm/lib/Target/M68k/MCTargetDesc/M68kMCExpr.h
@@ -52,7 +52,9 @@ class M68kMCExpr : public MCTargetExpr {
bool evaluateAsRelocatableImpl(MCValue &Res,
const MCAssembler *Asm) const override;
void visitUsedExpr(MCStreamer &Streamer) const override;
- MCFragment *findAssociatedFragment() const override;
+ MCFragment *findAssociatedFragment() const override {
+ return getSubExpr()->findAssociatedFragment();
+ }
};
} // namespace llvm
diff --git a/llvm/test/MC/M68k/Relocations/tls.s b/llvm/test/MC/M68k/Relocations/tls.s
new file mode 100644
index 0000000000000..ec7e11f17fe70
--- /dev/null
+++ b/llvm/test/MC/M68k/Relocations/tls.s
@@ -0,0 +1,31 @@
+; RUN: llvm-mc -triple m68k -show-encoding %s | FileCheck -check-prefix=INSTR %s
+; RUN: llvm-mc -triple m68k --mcpu=M68020 -filetype=obj %s -o %t
+; RUN: llvm-readelf -rs %t | FileCheck --check-prefix=READELF %s --implicit-check-not=TLS
+
+; INSTR: move.l (le at TPOFF,%a0), %d0
+; INSTR-NEXT: fixup A - offset: 2, value: le at TPOFF, kind: FK_Data_2
+; INSTR-NEXT: move.l (ie at GOTTPOFF,%a0), %a2
+; INSTR-NEXT: fixup A - offset: 2, value: ie at GOTTPOFF, kind: FK_Data_2
+; INSTR-NEXT: lea (gd at TLSGD,%a0), %a0
+; INSTR-NEXT: fixup A - offset: 2, value: gd at TLSGD, kind: FK_Data_2
+; INSTR-NEXT: move.l (ld at TLSLD,%a0), %d0
+; INSTR-NEXT: fixup A - offset: 2, value: ld at TLSLD, kind: FK_Data_2
+; INSTR-NEXT: lea (ld at TLSLDM,%a2), %a1
+; INSTR-NEXT: fixup A - offset: 2, value: ld at TLSLDM, kind: FK_Data_2
+
+; READELF: R_68K_TLS_LE16 00000000 le + 0
+; READELF-NEXT: R_68K_TLS_IE16 00000000 ie + 0
+; READELF-NEXT: R_68K_TLS_GD16 00000000 gd + 0
+; READELF-NEXT: R_68K_TLS_LDO16 00000000 ld + 0
+; READELF-NEXT: R_68K_TLS_LDM16 00000000 ld + 0
+
+; READELF: TLS GLOBAL DEFAULT UND le
+; READELF-NEXT: TLS GLOBAL DEFAULT UND ie
+; READELF-NEXT: TLS GLOBAL DEFAULT UND gd
+; READELF-NEXT: TLS GLOBAL DEFAULT UND ld
+
+move.l (le at TPOFF,%a0), %d0
+move.l (ie at GOTTPOFF,%a0), %a2
+lea (gd at TLSGD,%a0), %a0
+move.l (ld at TLSLD,%a0), %d0
+lea (ld at TLSLDM,%a2), %a1
More information about the llvm-commits
mailing list