[lld] a317afa - [ELF][test] Improve -r tests for local symbols
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 19 23:45:00 PDT 2023
Author: Fangrui Song
Date: 2023-09-19T23:44:55-07:00
New Revision: a317afaf00b0b898538855c36c203bb9117d6b86
URL: https://github.com/llvm/llvm-project/commit/a317afaf00b0b898538855c36c203bb9117d6b86
DIFF: https://github.com/llvm/llvm-project/commit/a317afaf00b0b898538855c36c203bb9117d6b86.diff
LOG: [ELF][test] Improve -r tests for local symbols
Added:
Modified:
lld/test/ELF/relocatable-discard-locals.s
lld/test/ELF/relocatable-local-sym.s
Removed:
################################################################################
diff --git a/lld/test/ELF/relocatable-discard-locals.s b/lld/test/ELF/relocatable-discard-locals.s
index 7f9640ceca19f3f..8941e8de7abc897 100644
--- a/lld/test/ELF/relocatable-discard-locals.s
+++ b/lld/test/ELF/relocatable-discard-locals.s
@@ -16,26 +16,31 @@
# DISCARD-LOCALS: 0: {{0+}} 0 NOTYPE LOCAL DEFAULT UND
# DISCARD-LOCALS-NEXT: NOTYPE LOCAL DEFAULT {{.*}} .Lused
# DISCARD-LOCALS-NEXT: NOTYPE LOCAL DEFAULT {{.*}} used
+# DISCARD-LOCALS-NEXT: NOTYPE LOCAL DEFAULT {{.*}} .L.str
# DISCARD-LOCALS-NEXT: NOTYPE LOCAL DEFAULT {{.*}} unused
# DISCARD-LOCALS-NEXT: NOTYPE LOCAL DEFAULT {{.*}} unused_gc
# DISCARD-LOCALS-NEXT: SECTION LOCAL DEFAULT {{.*}} .text
# DISCARD-LOCALS-NEXT: SECTION LOCAL DEFAULT {{.*}} text
# DISCARD-LOCALS-NEXT: SECTION LOCAL DEFAULT {{.*}} gc
+# DISCARD-LOCALS-NEXT: SECTION LOCAL DEFAULT {{.*}} .rodata.str1.1
# DISCARD-LOCALS-NEXT: NOTYPE GLOBAL DEFAULT {{.*}} _start
## --discard-all removes all unused regular local symbols.
# DISCARD-ALL: 0: {{0+}} 0 NOTYPE LOCAL DEFAULT UND
# DISCARD-ALL-NEXT: NOTYPE LOCAL DEFAULT {{.*}} .Lused
# DISCARD-ALL-NEXT: NOTYPE LOCAL DEFAULT {{.*}} used
+# DISCARD-ALL-NEXT: NOTYPE LOCAL DEFAULT {{.*}} .L.str
# DISCARD-ALL-NEXT: SECTION LOCAL DEFAULT {{.*}} .text
# DISCARD-ALL-NEXT: SECTION LOCAL DEFAULT {{.*}} text
# DISCARD-ALL-NEXT: SECTION LOCAL DEFAULT {{.*}} gc
+# DISCARD-ALL-NEXT: SECTION LOCAL DEFAULT {{.*}} .rodata.str1.1
# DISCARD-ALL-NEXT: NOTYPE GLOBAL DEFAULT {{.*}} _start
# REL: .rela.text {
# REL-NEXT: R_X86_64_PLT32 text 0xFFFFFFFFFFFFFFFC
# REL-NEXT: R_X86_64_PLT32 .Lused 0xFFFFFFFFFFFFFFFC
# REL-NEXT: R_X86_64_PLT32 used 0xFFFFFFFFFFFFFFFC
+# REL-NEXT: R_X86_64_PC32 .L.str 0xFFFFFFFFFFFFFFFC
# REL-NEXT: }
.globl _start
@@ -43,6 +48,7 @@ _start:
call text at plt
jmp .Lused at plt
call used at plt
+ leaq .L.str(%rip), %rdi
.section text,"ax"
.Lunused:
@@ -54,3 +60,6 @@ used:
.Lunused_gc:
unused_gc:
ret
+
+.section .rodata.str1.1,"aMS", at progbits,1
+.L.str: .asciz "a"
diff --git a/lld/test/ELF/relocatable-local-sym.s b/lld/test/ELF/relocatable-local-sym.s
index b894d6b9900c1aa..b925ff5bdb402a6 100644
--- a/lld/test/ELF/relocatable-local-sym.s
+++ b/lld/test/ELF/relocatable-local-sym.s
@@ -1,16 +1,42 @@
# REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o
-# RUN: ld.lld -r %t1.o -o %t2.o
-# RUN: llvm-readobj -r %t2.o | FileCheck %s
+## Test relocations referencing non-STT_SECTION local symbols in SHF_ALLOC and non-SHF_ALLOC sections for -r.
-# CHECK: Relocations [
-# CHECK-NEXT: Section ({{.*}}) .rela.text {
-# CHECK-NEXT: 0x3 R_X86_64_PC32 .Lstr 0xFFFFFFFFFFFFFFFC
-# CHECK-NEXT: }
-# CHECK-NEXT: ]
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
+# RUN: ld.lld -r -o %t %t.o %t.o
+# RUN: llvm-readelf -r -x .nonalloc %t | FileCheck --check-prefix=RELA %s
- leaq .Lstr(%rip), %rdi
+# RUN: llvm-mc -filetype=obj -triple=i686 --defsym X86_32=1 %s -o %t1.o
+# RUN: ld.lld -r -o %t1 %t1.o %t1.o
+# RUN: llvm-readelf -r -x .nonalloc %t1 | FileCheck --check-prefix=REL %s
- .section .rodata.str1.1,"aMS", at progbits,1
- .Lstr:
- .asciz "abc\n"
+# RELA: Relocation section '.rela.data' at offset {{.*}} contains 2 entries:
+# RELA: Offset Info Type Symbol's Value Symbol's Name + Addend
+# RELA-NEXT: 0000000000000000 {{.*}} R_X86_64_32 0000000000000000 ifunc + 9
+# RELA-NEXT: 0000000000000004 {{.*}} R_X86_64_32 0000000000000004 ifunc + 9
+# RELA: Relocation section '.rela.nonalloc' at offset {{.*}} contains 2 entries:
+# RELA: Offset Info Type Symbol's Value Symbol's Name + Addend
+# RELA-NEXT: 0000000000000000 {{.*}} R_X86_64_32 0000000000000000 ifunc + 9
+# RELA-NEXT: 0000000000000004 {{.*}} R_X86_64_32 0000000000000004 ifunc + 9
+# RELA: Hex dump of section '.nonalloc':
+# RELA-NEXT: 0x00000000 00000000 00000000 ........
+
+# REL: Offset Info Type Sym. Value Symbol's Name
+# REL-NEXT: 00000000 {{.*}} R_386_32 00000000 ifunc
+# REL-NEXT: 00000004 {{.*}} R_386_32 00000004 ifunc
+# REL-EMPTY:
+# REL: Offset Info Type Sym. Value Symbol's Name
+# REL-NEXT: 00000000 {{.*}} R_386_32 00000000 ifunc
+# REL-NEXT: 00000004 {{.*}} R_386_32 00000004 ifunc
+# REL: Hex dump of section '.nonalloc':
+# REL-NEXT: 0x00000000 09000000 09000000 ........
+
+resolver: ret
+.type ifunc, @gnu_indirect_function
+.set ifunc, resolver
+
+.data
+.long ifunc+9
+
+.section .nonalloc
+## The relocation references ifunc instead of the STT_SECTION symbol.
+.long ifunc+9
More information about the llvm-commits
mailing list