[lld] aaeba64 - [LLD] [TEST] Add test case for patching an absolute relocation to a weak undef
Ben Dunbobbin via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 11 05:18:56 PDT 2021
Author: Ben Dunbobbin
Date: 2021-10-11T13:14:45+01:00
New Revision: aaeba6483fdafa442b950427bfa3e6443034f78d
URL: https://github.com/llvm/llvm-project/commit/aaeba6483fdafa442b950427bfa3e6443034f78d
DIFF: https://github.com/llvm/llvm-project/commit/aaeba6483fdafa442b950427bfa3e6443034f78d.diff
LOG: [LLD] [TEST] Add test case for patching an absolute relocation to a weak undef
I noticed that we had this case in our internal testsuite but couldn't find it in LLD's tests.
This adds that case.
Differential Revision: https://reviews.llvm.org/D110716
Added:
Modified:
lld/test/ELF/relocation-undefined-weak.s
lld/test/ELF/weak-undef-rw.s
lld/test/ELF/weak-undef.s
Removed:
################################################################################
diff --git a/lld/test/ELF/relocation-undefined-weak.s b/lld/test/ELF/relocation-undefined-weak.s
index 18c1094f74119..209dda7c342bc 100644
--- a/lld/test/ELF/relocation-undefined-weak.s
+++ b/lld/test/ELF/relocation-undefined-weak.s
@@ -2,16 +2,27 @@
## On some targets (e.g. ARM, AArch64, and PPC), PC relative relocations to
## weak undefined symbols resolve to special positions. On many others
-## the target symbols as treated as VA 0.
+## the target symbols as treated as VA 0. Absolute relocations are always
+## resolved as VA 0.
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
# RUN: ld.lld %t.o -o %t
-# RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t | FileCheck %s
+
+# RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t | FileCheck %s --check-prefix=TEXT
+# TEXT: 201158: movl $0x1, -0x201162(%rip)
+
+# RUN: llvm-readelf -r --hex-dump=.data %t | FileCheck %s --check-prefix=DATA
+# DATA: Hex dump of section '.data':
+# DATA-NEXT: {{.*}} 00000000 00000000
+# DATA-EMPTY:
+
+# RUN: llvm-readelf -r %t | FileCheck %s --check-prefix=NORELCS
+# NORELCS: no relocations
.global _start
_start:
movl $1, sym1(%rip)
+.data
.weak sym1
-
-# CHECK: 201120: movl $0x1, -0x20112a(%rip)
+.quad sym1
diff --git a/lld/test/ELF/weak-undef-rw.s b/lld/test/ELF/weak-undef-rw.s
index 26cc74788bc24..ec3e4ce734895 100644
--- a/lld/test/ELF/weak-undef-rw.s
+++ b/lld/test/ELF/weak-undef-rw.s
@@ -1,7 +1,7 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: ld.lld %t.o -o %t --export-dynamic
-# RUN: llvm-readelf -r %t | FileCheck %s --check-prefix=NOPIC
+# RUN: llvm-readelf -r --hex-dump=.data %t | FileCheck %s --check-prefix=NOPIC
# RUN: ld.lld %t.o -o %t.pie -pie
# RUN: llvm-readobj -r %t.pie | FileCheck %s --check-prefix=PIC
# RUN: ld.lld %t.o -o %t.so -shared
@@ -15,6 +15,9 @@
## implement.
# NOPIC: no relocations
+# NOPIC: Hex dump of section '.data':
+# NOPIC-NEXT: {{.*}} 00000000 00000000
+# NOPIC-EMPTY:
# PIC: .rela.dyn {
# PIC-NEXT: R_X86_64_64 foobar 0x0
diff --git a/lld/test/ELF/weak-undef.s b/lld/test/ELF/weak-undef.s
index 9fd538549f25f..3a9d5f462c21b 100644
--- a/lld/test/ELF/weak-undef.s
+++ b/lld/test/ELF/weak-undef.s
@@ -1,33 +1,28 @@
# 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-readobj --dyn-syms %t | FileCheck %s
+# 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-readobj --dyn-syms %t | FileCheck %s
+# 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
-# CHECK: DynamicSymbols [
-# CHECK-NEXT: Symbol {
-# CHECK-NEXT: Name:
-# CHECK-NEXT: Value: 0x0
-# CHECK-NEXT: Size: 0
-# CHECK-NEXT: Binding: Local (0x0)
-# CHECK-NEXT: Type: None (0x0)
-# CHECK-NEXT: Other: 0
-# CHECK-NEXT: Section: Undefined (0x0)
-# CHECK-NEXT: }
-# CHECK-NEXT: Symbol {
-# CHECK-NEXT: Name: foo
-# CHECK-NEXT: Value: 0x0
-# CHECK-NEXT: Size: 0
-# CHECK-NEXT: Binding: Weak
-# CHECK-NEXT: Type: None
-# CHECK-NEXT: Other: 0
-# CHECK-NEXT: Section: Undefined
-# CHECK-NEXT: }
-# CHECK-NEXT: ]
+# COMMON: Symbol table '.dynsym' contains 2 entries:
+# COMMON-NEXT: Num: Value Size Type Bind Vis Ndx Name
+# COMMON-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
+# COMMON-NEXT: 1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND foo
+# COMMON: Hex dump of section '.data':
+# COMMON-NEXT: {{.*}} 00000000 00000000
+# COMMON-EMPTY:
.weak foo
More information about the llvm-commits
mailing list