[lld] 9662a60 - [ELF,test] Make loongarch-reloc-leb128.s similar to riscv-reloc-leb128.s

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat May 24 17:36:11 PDT 2025


Author: Fangrui Song
Date: 2025-05-24T17:36:06-07:00
New Revision: 9662a6039c0320eb4473d87b47f0ed891a0f111c

URL: https://github.com/llvm/llvm-project/commit/9662a6039c0320eb4473d87b47f0ed891a0f111c
DIFF: https://github.com/llvm/llvm-project/commit/9662a6039c0320eb4473d87b47f0ed891a0f111c.diff

LOG: [ELF,test] Make loongarch-reloc-leb128.s similar to riscv-reloc-leb128.s

For the label difference A-B where A and B are in the same section,
if the section contains no linker-relaxable instruction, we can disable
the framnent walk code path. However, the test from #81133 relies on the
redundant relocations. Make it similar to riscv-reloc-leb128.s.
For now, lose the 32-bit coverage as call36 is 64-bit only.

Added: 
    

Modified: 
    lld/test/ELF/loongarch-reloc-leb128.s

Removed: 
    


################################################################################
diff  --git a/lld/test/ELF/loongarch-reloc-leb128.s b/lld/test/ELF/loongarch-reloc-leb128.s
index 2dd327d1564eb..78b580e9e4274 100644
--- a/lld/test/ELF/loongarch-reloc-leb128.s
+++ b/lld/test/ELF/loongarch-reloc-leb128.s
@@ -6,14 +6,7 @@
 # RUN: ld.lld -shared --gc-sections a.o -o a.so
 # RUN: llvm-readelf -x .gcc_except_table -x .debug_rnglists -x .debug_loclists a.so | FileCheck %s
 
-# RUN: llvm-mc --filetype=obj --triple=loongarch32 --mattr=+relax a.s -o a32.o
-# RUN: llvm-readobj -r -x .gcc_except_table -x .debug_rnglists -x .debug_loclists a32.o | FileCheck %s --check-prefix=REL
-# RUN: ld.lld -shared --gc-sections a32.o -o a32.so
-# RUN: llvm-readelf -x .gcc_except_table -x .debug_rnglists -x .debug_loclists a32.so | FileCheck %s
-
-# RUN: llvm-mc --filetype=obj --triple=loongarch32 --mattr=+relax extraspace.s -o extraspace32.o
 # RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=+relax extraspace.s -o extraspace64.o
-# RUN: not ld.lld -shared extraspace32.o 2>&1 | FileCheck %s --check-prefix=ERROR
 # RUN: not ld.lld -shared extraspace64.o 2>&1 | FileCheck %s --check-prefix=ERROR
 # ERROR: error: extraspace{{.*}}.o:(.rodata+0x0): extra space for uleb128
 
@@ -22,72 +15,67 @@
 .cfi_lsda 0x1b,.LLSDA0
 .cfi_endproc
 
+.globl _start
+_start:
+foo:
+  nop
+
 .section .text.w,"axR"
-break 0; break 0; break 0; w1:
-  .p2align 4    # 4 bytes after relaxation
-w2: break 0
+w1:
+  call36 foo    # 4 bytes after relaxation
+w2:
 
 .section .text.x,"ax"
-break 0; break 0; break 0; x1:
-  .p2align 4    # 4 bytes after relaxation
-x2: break 0
+x1:
+  call36 foo    # 4 bytes after relaxation
+x2:
 
 .section .gcc_except_table,"a"
 .LLSDA0:
-.uleb128 w2-w1+116                   # initial value: 0x0080
-.uleb128 w1-w2+141                   # initial value: 0x0080
-.uleb128 w2-w1+16372                 # initial value: 0x008080
-.uleb128 w1-w2+16397                 # initial value: 0x008080
-.uleb128 w2-w1+2097140               # initial value: 0x00808080
-.uleb128 w1-w2+2097165               # initial value: 0x00808080
+.reloc ., R_LARCH_ADD_ULEB128, w1+130
+.reloc ., R_LARCH_SUB_ULEB128, w2-1  # non-zero addend for SUB
+.byte 0x7b
+.uleb128 w2-w1+120
+.uleb128 w1-w2+137
+.uleb128 w2-w1+16376
+.uleb128 w1-w2+16393
+.uleb128 w2-w1+2097144
+.uleb128 w1-w2+2097161
 
 .section .debug_rnglists
-.uleb128 w2-w1+116                   # initial value: 0x0080
-.uleb128 w1-w2+141                   # initial value: 0x0080
-.uleb128 w2-w1+16372                 # initial value: 0x008080
-.uleb128 w1-w2+16397                 # initial value: 0x008080
-.uleb128 w2-w1+2097140               # initial value: 0x00808080
-.uleb128 w1-w2+2097165               # initial value: 0x00808080
+.reloc ., R_LARCH_ADD_ULEB128, w1+130
+.reloc ., R_LARCH_SUB_ULEB128, w2-1  # non-zero addend for SUB
+.byte 0x7b
+.uleb128 w2-w1+120
+.uleb128 w1-w2+137
+.uleb128 w2-w1+16376
+.uleb128 w1-w2+16393
+.uleb128 w2-w1+2097144
+.uleb128 w1-w2+2097161
 
 .section .debug_loclists
+.reloc ., R_LARCH_ADD_ULEB128, w2+3
+.reloc ., R_LARCH_SUB_ULEB128, w1+4  # SUB with a non-zero addend
+.byte 0
 .uleb128 x2-x1                       # references discarded symbols
 
-# REL:      Section ({{.*}}) .rela.debug_rnglists {
-# REL-NEXT:   0x0 R_LARCH_ADD_ULEB128 w2 0x74
-# REL-NEXT:   0x0 R_LARCH_SUB_ULEB128 w1 0x0
-# REL-NEXT:   0x2 R_LARCH_ADD_ULEB128 w1 0x8D
-# REL-NEXT:   0x2 R_LARCH_SUB_ULEB128 w2 0x0
-# REL-NEXT:   0x4 R_LARCH_ADD_ULEB128 w2 0x3FF4
-# REL-NEXT:   0x4 R_LARCH_SUB_ULEB128 w1 0x0
-# REL-NEXT:   0x7 R_LARCH_ADD_ULEB128 w1 0x400D
-# REL-NEXT:   0x7 R_LARCH_SUB_ULEB128 w2 0x0
-# REL-NEXT:   0xA R_LARCH_ADD_ULEB128 w2 0x1FFFF4
-# REL-NEXT:   0xA R_LARCH_SUB_ULEB128 w1 0x0
-# REL-NEXT:   0xE R_LARCH_ADD_ULEB128 w1 0x20000D
-# REL-NEXT:   0xE R_LARCH_SUB_ULEB128 w2 0x0
-# REL-NEXT: }
-# REL:      Section ({{.*}}) .rela.debug_loclists {
-# REL-NEXT:   0x0 R_LARCH_ADD_ULEB128 x2 0x0
-# REL-NEXT:   0x0 R_LARCH_SUB_ULEB128 x1 0x0
-# REL-NEXT: }
-
-# REL:      Hex dump of section '.gcc_except_table':
-# REL-NEXT: 0x00000000 80008000 80800080 80008080 80008080 .
-# REL-NEXT: 0x00000010 8000                                .
-# REL:      Hex dump of section '.debug_rnglists':
-# REL-NEXT: 0x00000000 80008000 80800080 80008080 80008080 .
-# REL-NEXT: 0x00000010 8000                                .
-# REL:      Hex dump of section '.debug_loclists':
-# REL-NEXT: 0x00000000 00                                  .
+# REL:        Hex dump of section '.gcc_except_table':
+# REL-NEXT:   0x00000000 7b800080 00808000 80800080 80800080 {
+# REL-NEXT:   0x00000010 808000                              .
+# REL:        Hex dump of section '.debug_rnglists':
+# REL-NEXT:   0x00000000 7b800080 00808000 80800080 80800080 {
+# REL-NEXT:   0x00000010 808000                              .
+# REL:        Hex dump of section '.debug_loclists':
+# REL-NEXT:   0x00000000 0000                                  .
 
 # CHECK:      Hex dump of section '.gcc_except_table':
-# CHECK-NEXT: 0x[[#%x,]] f8008901 f8ff0089 8001f8ff ff008980 .
-# CHECK-NEXT: 0x[[#%x,]] 8001                                .
+# CHECK-NEXT: 0x00000238 7afc0085 01fcff00 858001fc ffff0085 z
+# CHECK-NEXT: 0x00000248 808001                              .
 # CHECK:      Hex dump of section '.debug_rnglists':
-# CHECK-NEXT: 0x00000000 f8008901 f8ff0089 8001f8ff ff008980 .
-# CHECK-NEXT: 0x00000010 8001                                .
+# CHECK-NEXT: 0x00000000 7afc0085 01fcff00 858001fc ffff0085 z
+# CHECK-NEXT: 0x00000010 808001                              .
 # CHECK:      Hex dump of section '.debug_loclists':
-# CHECK-NEXT: 0x00000000 00                                  .
+# CHECK-NEXT: 0x00000000 0300                                .
 
 #--- extraspace.s
 .text


        


More information about the llvm-commits mailing list