[ELF,test] Improve weak-undef-rw.s

This commit is contained in:
Fangrui Song
2025-06-11 20:00:45 -07:00
parent faa49d6662
commit d8118ed6db

View File

@@ -3,12 +3,17 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o # RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
# RUN: llvm-mc -filetype=obj -triple=x86_64 b.s -o b.o # RUN: llvm-mc -filetype=obj -triple=x86_64 b.s -o b.o
# RUN: llvm-mc -filetype=obj -triple=x86_64 c.s -o c.o # RUN: llvm-mc -filetype=obj -triple=x86_64 c.s -o c.o
# RUN: ld.lld a.o -o nopie --export-dynamic # RUN: llvm-mc -filetype=obj -triple=x86_64 %S/Inputs/shared.s -o s.o
# RUN: llvm-readelf -r --hex-dump=.data nopie | FileCheck %s --check-prefix=STATIC # RUN: ld.lld -shared s.o -o s.so
# RUN: ld.lld a.o -o out.pie -pie
# RUN: llvm-readelf -r --hex-dump=.data out.pie | FileCheck %s --check-prefix=STATIC # RUN: ld.lld a.o -o a --export-dynamic
# RUN: ld.lld a.o -o out.so -shared # RUN: llvm-readelf -r --hex-dump=.data a | FileCheck %s --check-prefix=STATIC
# RUN: llvm-readobj -r out.so | FileCheck %s --check-prefix=PIC # RUN: ld.lld a.o s.so -o as
# RUN: llvm-readelf -r --hex-dump=.data as | FileCheck %s --check-prefix=STATIC
# RUN: ld.lld a.o -o a.pie -pie
# RUN: llvm-readelf -r --hex-dump=.data a.pie | FileCheck %s --check-prefix=STATIC
# RUN: ld.lld a.o -o a.so -shared
# RUN: llvm-readelf -r a.so | FileCheck %s --check-prefix=DYN
## gABI leaves the behavior of weak undefined references implementation defined. ## gABI leaves the behavior of weak undefined references implementation defined.
## We choose to resolve them statically for static linking and produce dynamic relocations ## We choose to resolve them statically for static linking and produce dynamic relocations
@@ -19,35 +24,44 @@
# STATIC: no relocations # STATIC: no relocations
# STATIC: Hex dump of section '.data': # STATIC: Hex dump of section '.data':
# STATIC-NEXT: {{.*}} 00000000 00000000 . # STATIC-NEXT: {{.*}} 00000000 00000000 03000000 00000000 .
# STATIC-EMPTY: # STATIC-EMPTY:
# PIC: .rela.dyn { # DYN: Relocation section '.rela.dyn' {{.*}} contains 2
# PIC-NEXT: R_X86_64_64 foobar 0x0 # DYN: R_X86_64_64 0000000000000000 foobar + 0{{$}}
# PIC-NEXT: }
# RUN: ld.lld a.o b.o -o out1 -z undefs # RUN: ld.lld a.o b.o -o ab -z undefs
# RUN: llvm-readelf -r -x .data out1 | FileCheck %s --check-prefix=STATIC1 # RUN: llvm-readelf -r -x .data ab | FileCheck %s --check-prefix=STATIC1
# RUN: ld.lld a.o b.o -o out1.pie -pie -z undefs # RUN: ld.lld a.o b.o s.so -o abs -z undefs
# RUN: llvm-readelf -r -x .data out1.pie | FileCheck %s --check-prefix=STATIC1 # RUN: llvm-readelf -r -x .data abs | FileCheck %s --check-prefix=DYN1
# RUN: ld.lld a.o b.o -o abs.pie -pie -z undefs
# RUN: llvm-readelf -r -x .data abs.pie | FileCheck %s --check-prefix=STATIC1
# STATIC1: no relocations # STATIC1: no relocations
# STATIC1: Hex dump of section '.data': # STATIC1: Hex dump of section '.data':
# STATIC1-NEXT: {{.*}} 00000000 00000000 00000000 00000000 . # STATIC1-NEXT: {{.*}} 00000000 00000000 03000000 00000000 .
# STATIC1-NEXT: {{.*}} 05000000 00000000 .
# STATIC1-EMPTY: # STATIC1-EMPTY:
# DYN1: Relocation section '.rela.dyn' {{.*}} contains 1
# DYN1: Hex dump of section '.data':
# DYN1-NEXT: {{.*}} 00000000 00000000 03000000 00000000 .
# DYN1-NEXT: {{.*}} 00000000 00000000 .
# DYN1-EMPTY:
# RUN: ld.lld a.o b.o c.o -pie -z undefs 2>&1 | count 0 # RUN: ld.lld a.o b.o c.o -pie -z undefs 2>&1 | count 0
#--- a.s #--- a.s
.global _start .global _start
_start: _start:
.data .data
.weak foobar .weak foobar
.quad foobar .quad foobar
.quad foobar+3
#--- b.s #--- b.s
.data .data
.quad undef .quad undef+5
#--- c.s #--- c.s
call undef call undef