[lld] 718fd90 - ELF,test: Make tests not rely on PPC64 .TOC.

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 8 10:14:26 PDT 2025


Author: Fangrui Song
Date: 2025-06-08T10:14:21-07:00
New Revision: 718fd90b8a8cee30b6e491d6f78306e88ecaafbf

URL: https://github.com/llvm/llvm-project/commit/718fd90b8a8cee30b6e491d6f78306e88ecaafbf
DIFF: https://github.com/llvm/llvm-project/commit/718fd90b8a8cee30b6e491d6f78306e88ecaafbf.diff

LOG: ELF,test: Make tests not rely on PPC64 .TOC.

`.quad .TOC. at tocbase` leads to a R_PPC64_TOC relocation referencing 0.
GNU Assembler does not define .TOC. . Fix reliance on the .TOC. symbol.

Added: 
    

Modified: 
    lld/test/ELF/ppc64-long-branch-pi.s
    lld/test/ELF/ppc64-relocs.s

Removed: 
    


################################################################################
diff  --git a/lld/test/ELF/ppc64-long-branch-pi.s b/lld/test/ELF/ppc64-long-branch-pi.s
index 4c8c4cebf2742..f97eda9632fc0 100644
--- a/lld/test/ELF/ppc64-long-branch-pi.s
+++ b/lld/test/ELF/ppc64-long-branch-pi.s
@@ -15,19 +15,20 @@
 # RUN: llvm-objdump -d --no-show-raw-insn %t.so | FileCheck %s
 
 # SEC-PIE:    Name       Type     Address          Off     Size   ES Flg Lk Inf Al
-# SEC-PIE:    .got       PROGBITS 0000000002002110 2012110 000008 00  WA  0   0  8
-# SEC-PIE:    .branch_lt NOBITS   0000000002002120 2012120 000020 00  WA  0   0  8
+# SEC-PIE:    .got       PROGBITS 0000000002002120 2012120 000010 00  WA  0   0  8
+# SEC-PIE:    .branch_lt NOBITS   0000000002002138 2012138 000020 00  WA  0   0  8
 
 # SEC-SHARED: Name       Type     Address          Off     Size   ES Flg Lk Inf Al
-# SEC-SHARED: .got       PROGBITS 00000000020020f0 20120f0 000008 00  WA  0   0  8
-# SEC-SHARED: .branch_lt NOBITS   0000000002002100 2012100 000020 00  WA  0   0  8
+# SEC-SHARED: .got       PROGBITS 0000000002002100 2012100 000010 00  WA  0   0  8
+# SEC-SHARED: .branch_lt NOBITS   0000000002002118 2012118 000020 00  WA  0   0  8
 
 # RELOC:      .rela.dyn {
-# RELOC-NEXT:   0x2002118 R_PPC64_RELATIVE - 0x2012110
-# RELOC-NEXT:   0x2002120 R_PPC64_RELATIVE - 0x2002000
-# RELOC-NEXT:   0x2002128 R_PPC64_RELATIVE - 0x2002008
-# RELOC-NEXT:   0x2002130 R_PPC64_RELATIVE - 0x200200C
-# RELOC-NEXT:   0x2002138 R_PPC64_RELATIVE - 0x2000
+# RELOC-NEXT:   0x2002128 R_PPC64_RELATIVE - 0x2002000
+# RELOC-NEXT:   0x2002130 R_PPC64_RELATIVE - 0x2012120
+# RELOC-NEXT:   0x2002138 R_PPC64_RELATIVE - 0x2002000
+# RELOC-NEXT:   0x2002140 R_PPC64_RELATIVE - 0x2002008
+# RELOC-NEXT:   0x2002148 R_PPC64_RELATIVE - 0x200200C
+# RELOC-NEXT:   0x2002150 R_PPC64_RELATIVE - 0x2000
 # RELOC-NEXT: }
 
 # CHECK:      <_start>:
@@ -36,24 +37,24 @@
 # CHECK-NEXT:                 bl 0x2030
 # CHECK-NEXT:                 bl 0x2050
 
-## &.branch_lt[0] - .TOC. = .branch_lt - (.got+0x8000) = -32752
+## &.branch_lt[0] - .TOC. = .branch_lt - (.got+0x8000) = -32744
 # CHECK:      <__long_branch_>:
 # CHECK-NEXT:     2010:       addis 12, 2, 0
-# CHECK-NEXT:                 ld 12, -32752(12)
+# CHECK-NEXT:                 ld 12, -32744(12)
 # CHECK-NEXT:                 mtctr 12
 # CHECK-NEXT:                 bctr
 
-## &.branch_lt[1] - .TOC. = .branch_lt - (.got+0x8000) = -32744
+## &.branch_lt[1] - .TOC. = .branch_lt - (.got+0x8000) = -32736
 # CHECK:      <__long_branch_>:
 # CHECK-NEXT:     2030:       addis 12, 2, 0
-# CHECK-NEXT:                 ld 12, -32744(12)
+# CHECK-NEXT:                 ld 12, -32736(12)
 # CHECK-NEXT:                 mtctr 12
 # CHECK-NEXT:                 bctr
 
-## &.branch_lt[2] - .TOC. = .branch_lt - (.got+0x8000) = -32736
+## &.branch_lt[2] - .TOC. = .branch_lt - (.got+0x8000) = -32728
 # CHECK:      <__long_branch_>:
 # CHECK-NEXT:     2050:       addis 12, 2, 0
-# CHECK-NEXT:                 ld 12, -32736(12)
+# CHECK-NEXT:                 ld 12, -32728(12)
 # CHECK-NEXT:                 mtctr 12
 # CHECK-NEXT:                 bctr
 
@@ -68,12 +69,12 @@ bl .text_high+0xc # Need a thunk
 # CHECK:      <high_target>:
 # CHECK-NEXT:  2002000:   bl 0x2004
 # CHECK-NEXT:             bl 0x2004
-# CHECK-NEXT:             bl 0x2002010
+# CHECK-NEXT:             bl 0x2002020
 
-## &.branch_lt[3] - .TOC. = .branch_lt - (.got+0x8000) = -32728
+## &.branch_lt[3] - .TOC. = .branch_lt - (.got+0x8000) = -32720
 # CHECK:      <__long_branch_>:
-# CHECK-NEXT:  2002010:       addis 12, 2, 0
-# CHECK-NEXT:                 ld 12, -32728(12)
+# CHECK-NEXT:  2002020:       addis 12, 2, 0
+# CHECK-NEXT:                 ld 12, -32720(12)
 # CHECK-NEXT:                 mtctr 12
 # CHECK-NEXT:                 bctr
 
@@ -85,6 +86,8 @@ bl .text_low      # Need a thunk
 blr
 
 ## Force creation of .got
+addis 3, 2, .text_high at got@ha
+
 ## The R_PPC64_RELATIVE makes sure .rela.dyn survives removeUnusedSyntheticSections.
 .section .data
 .quad .TOC. at tocbase

diff  --git a/lld/test/ELF/ppc64-relocs.s b/lld/test/ELF/ppc64-relocs.s
index 0b0be487521e4..97018ddd25d45 100644
--- a/lld/test/ELF/ppc64-relocs.s
+++ b/lld/test/ELF/ppc64-relocs.s
@@ -2,12 +2,12 @@
 
 # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
 # RUN: ld.lld --no-toc-optimize %t.o -o %t
-# RUN: llvm-readelf -x .rodata -x .R_PPC64_TOC -x .eh_frame %t | FileCheck %s --check-prefix=DATALE
+# RUN: llvm-readelf -x .rodata -x .R_PPC64_TOC %t | FileCheck %s --check-prefix=DATALE
 # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
 
 # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
 # RUN: ld.lld --no-toc-optimize %t.o -o %t
-# RUN: llvm-readelf -x .rodata -x .R_PPC64_TOC -x .eh_frame %t | FileCheck %s --check-prefix=DATABE
+# RUN: llvm-readelf -x .rodata -x .R_PPC64_TOC %t | FileCheck %s --check-prefix=DATABE
 # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
 
 .text


        


More information about the llvm-commits mailing list