From: Ben Dunbobbin Date: Mon, 11 Oct 2021 12:10:52 +0000 (+0100) Subject: [LLD] [TEST] Add test case for patching an absolute relocation to a weak undef X-Git-Tag: upstream/15.0.7~28999 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aaeba6483fdafa442b950427bfa3e6443034f78d;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/lld/test/ELF/relocation-undefined-weak.s b/lld/test/ELF/relocation-undefined-weak.s index 18c1094..209dda7 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 26cc747..ec3e4ce 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 9fd5385..3a9d5f4 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