[ELF,test] Improve weak-undef-got-plt.s

This commit is contained in:
Fangrui Song
2025-06-11 21:23:06 -07:00
parent 282e471018
commit c3be4524a5
3 changed files with 34 additions and 53 deletions

View File

@@ -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

View File

@@ -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 {{.*}} <foo@plt>
#--- a.s
.weak foo
.globl _start
_start:
mov foo@gotpcrel(%rip), %rax
call foo

View File

@@ -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