[llvm] d00f03d - [PPC32] Emit relocation type R_PPC_DTPREL32 for tls variables
Aaron Ballman via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 9 11:29:12 PDT 2023
Author: Varun Erigila
Date: 2023-08-09T14:28:11-04:00
New Revision: d00f03dd6fc744fd10fa1c3363c3b980a11bd51b
URL: https://github.com/llvm/llvm-project/commit/d00f03dd6fc744fd10fa1c3363c3b980a11bd51b
DIFF: https://github.com/llvm/llvm-project/commit/d00f03dd6fc744fd10fa1c3363c3b980a11bd51b.diff
LOG: [PPC32] Emit relocation type R_PPC_DTPREL32 for tls variables
This patch emits the relocation type R_PPC_DTPREL32 for tls variables,
which was previously emitting R_PPC_ADDR32 in power-pc 32bit.
Differential Revision: https://reviews.llvm.org/D156953
Added:
llvm/test/MC/PowerPC/ppc32-R_PPC_DTPREL32-reloc.s
Modified:
llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
index 1e58039582c250..7609ac461ea872 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
@@ -456,7 +456,13 @@ unsigned PPCELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
}
break;
case FK_Data_4:
- Type = ELF::R_PPC_ADDR32;
+ switch (Modifier) {
+ case MCSymbolRefExpr::VK_DTPREL:
+ Type = ELF::R_PPC_DTPREL32;
+ break;
+ default:
+ Type = ELF::R_PPC_ADDR32;
+ }
break;
case FK_Data_2:
Type = ELF::R_PPC_ADDR16;
diff --git a/llvm/test/MC/PowerPC/ppc32-R_PPC_DTPREL32-reloc.s b/llvm/test/MC/PowerPC/ppc32-R_PPC_DTPREL32-reloc.s
new file mode 100644
index 00000000000000..88813b072ccc04
--- /dev/null
+++ b/llvm/test/MC/PowerPC/ppc32-R_PPC_DTPREL32-reloc.s
@@ -0,0 +1,50 @@
+# RUN: llvm-mc -filetype=obj -triple=ppc %s -o %t
+# RUN: llvm-readelf -r %t | FileCheck %s
+
+# CHECK: Relocation section '.rela.debug_info' at offset 0xf8 contains 1 entries:
+# CHECK-NEXT: Offset Info Type Sym. Value Symbol's Name + Addend
+# CHECK-NEXT: 00000000 0000024e R_PPC_DTPREL32 00000000 tls_rtp_var + 8000
+
+ .text
+ .globl foo # -- Begin function foo
+ .p2align 2
+ .type foo, at function
+foo: # @foo
+# %bb.0: # %entry
+ stwu 1, -16(1)
+ stw 31, 12(1)
+ mr 31, 1
+ addis 3, 2, tls_rtp_var at tprel@ha
+ addi 4, 3, tls_rtp_var at tprel@l
+ lwz 3, 0(4)
+ addi 3, 3, 1
+ stw 3, 0(4)
+ lis 4, my_global_var at ha
+ lwz 3, my_global_var at l(4)
+ addi 3, 3, 1
+ stw 3, my_global_var at l(4)
+ lwz 31, 12(1)
+ addi 1, 1, 16
+ blr
+
+ .type tls_rtp_var, at object # @tls_rtp_var
+ .section .tdata,"awT", at progbits
+ .globl tls_rtp_var
+ .p2align 2, 0x0
+tls_rtp_var:
+ .long 5 # 0x5
+ .size tls_rtp_var, 4
+
+ .type my_global_var, at object # @my_global_var
+ .data
+ .globl my_global_var
+ .p2align 2, 0x0
+my_global_var:
+ .long 7 # 0x7
+ .size my_global_var, 4
+
+ .section .debug_info,"", at progbits
+.Lcu_begin0:
+.Ldebug_info_start0:
+ .long tls_rtp_var at DTPREL+32768
+.Ldebug_info_end0:
More information about the llvm-commits
mailing list