From c3be4524a56ba01bc1f868fc37e329f24ec5041c Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 11 Jun 2025 21:23:06 -0700 Subject: [PATCH] [ELF,test] Improve weak-undef-got-plt.s --- lld/test/ELF/weak-undef-got-pie.s | 22 -------------------- lld/test/ELF/weak-undef-got-plt.s | 34 +++++++++++++++++++++++++++++++ lld/test/ELF/weak-undef.s | 31 ---------------------------- 3 files changed, 34 insertions(+), 53 deletions(-) delete mode 100644 lld/test/ELF/weak-undef-got-pie.s create mode 100644 lld/test/ELF/weak-undef-got-plt.s delete mode 100644 lld/test/ELF/weak-undef.s diff --git a/lld/test/ELF/weak-undef-got-pie.s b/lld/test/ELF/weak-undef-got-pie.s deleted file mode 100644 index 2301400f4e0b..000000000000 --- a/lld/test/ELF/weak-undef-got-pie.s +++ /dev/null @@ -1,22 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64 %p/Inputs/dummy-shared.s -o %t1.o -# RUN: ld.lld %t1.o -shared -o %t1.so -# RUN: llvm-mc -filetype=obj -x86-relax-relocations=false -triple=x86_64 %s -o %t.o - -# RUN: ld.lld -pie %t.o %t1.so -o %t -# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOCS %s -# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck --check-prefix=DISASM %s - -# RELOCS: Relocations [ -# RELOCS-NEXT: Section ({{.*}}) .rela.dyn { -# RELOCS-NEXT: R_X86_64_GLOB_DAT foo 0x0 -# RELOCS-NEXT: } -# RELOCS-NEXT: ] - -.weak foo - -.globl _start -_start: -# DISASM: <_start>: -# DISASM-NEXT: movq {{.*}}(%rip), %rax -mov foo@gotpcrel(%rip), %rax diff --git a/lld/test/ELF/weak-undef-got-plt.s b/lld/test/ELF/weak-undef-got-plt.s new file mode 100644 index 000000000000..0ee3da2cd3b4 --- /dev/null +++ b/lld/test/ELF/weak-undef-got-plt.s @@ -0,0 +1,34 @@ +# REQUIRES: x86 +# RUN: rm -rf %t && split-file %s %t && cd %t +# RUN: llvm-mc -filetype=obj -triple=x86_64 -x86-relax-relocations=false a.s -o a.o +# RUN: llvm-mc -filetype=obj -triple=x86_64 %S/Inputs/shared.s -o s.o +# RUN: ld.lld -shared s.o -o s.so + +# RUN: ld.lld a.o -o a +# RUN: llvm-readelf -r a | FileCheck %s --check-prefix=NORELOC +# RUN: ld.lld a.o s.so -o as +# RUN: llvm-objdump -dR as | FileCheck %s + +# RUN: ld.lld -pie a.o s.so -o as.pie +# RUN: llvm-objdump -dR as.pie | FileCheck %s + +# RUN: ld.lld -shared a.o -o a.so +# RUN: llvm-objdump -dR a.so | FileCheck %s + +# NORELOC: no relocation + +# CHECK: TYPE VALUE +# CHECK-NEXT: R_X86_64_GLOB_DAT foo{{$}} +# CHECK-NEXT: R_X86_64_JUMP_SLOT foo{{$}} +# CHECK-EMPTY: +# CHECK: <_start>: +# CHECK-NEXT: movq {{.*}}(%rip), %rax +# CHECK-NEXT: callq {{.*}} + +#--- a.s +.weak foo + +.globl _start +_start: +mov foo@gotpcrel(%rip), %rax +call foo diff --git a/lld/test/ELF/weak-undef.s b/lld/test/ELF/weak-undef.s deleted file mode 100644 index 21488023a79e..000000000000 --- a/lld/test/ELF/weak-undef.s +++ /dev/null @@ -1,31 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o -# RUN: ld.lld %t.o -o %t --export-dynamic -# RUN: llvm-readelf -r --dyn-syms --hex-dump=.data %t | \ -# RUN: FileCheck %s --check-prefixes=NORELOC,COMMON - -# NORELOC: There are no relocations in this file. - -# RUN: llvm-mc -filetype=obj -triple=x86_64 %p/Inputs/dummy-shared.s -o %t1.o -# RUN: ld.lld %t1.o -shared -o %t1.so -# RUN: ld.lld %t.o -o %t %t1.so -pie -# RUN: llvm-readelf -r --dyn-syms --hex-dump=.data %t | \ -# RUN: FileCheck %s --check-prefixes=RELOC,COMMON - -# RELOC: Relocation section '.rela.dyn' at offset {{.*}} contains 1 entries: -# RELOC-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend -# RELOC-NEXT: {{.*}} 0000000100000001 R_X86_64_64 0000000000000000 foo + 0 - -# NORELOC-NOT: Symbol table '.dynsym' -# RELOC: Symbol table '.dynsym' contains 2 entries: -# RELOC-NEXT: Num: Value Size Type Bind Vis Ndx Name -# RELOC-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND -# RELOC-NEXT: 1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND foo -# COMMON: Hex dump of section '.data': -# COMMON-NEXT: {{.*}} 00000000 00000000 -# COMMON-EMPTY: - -.weak foo - -.data - .dc.a foo