[llvm-branch-commits] [lld] 8031785 - [ELF][test] Improve --wrap tests

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 19 21:28:02 PST 2021


Author: Fangrui Song
Date: 2021-01-19T21:21:19-08:00
New Revision: 8031785f4a7ebd027edb34c91cbcf48db53ef444

URL: https://github.com/llvm/llvm-project/commit/8031785f4a7ebd027edb34c91cbcf48db53ef444
DIFF: https://github.com/llvm/llvm-project/commit/8031785f4a7ebd027edb34c91cbcf48db53ef444.diff

LOG: [ELF][test] Improve --wrap tests

Added: 
    

Modified: 
    lld/test/ELF/wrap-shlib-undefined.s

Removed: 
    


################################################################################
diff  --git a/lld/test/ELF/wrap-shlib-undefined.s b/lld/test/ELF/wrap-shlib-undefined.s
index eca21b91d866..acc9fd8b943e 100644
--- a/lld/test/ELF/wrap-shlib-undefined.s
+++ b/lld/test/ELF/wrap-shlib-undefined.s
@@ -1,28 +1,54 @@
 # REQUIRES: x86
 
-# RUN: split-file %s %t.dir
-# RUN: llvm-mc -filetype=obj -triple=x86_64 %t.dir/main.s -o %t.o
-# RUN: echo '.globl bar; bar: call __real_foo' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
-# RUN: ld.lld -shared -soname=t.so %t1.o -o %t.so
+# RUN: rm -rf %t && split-file %s %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/main.s -o %t/main.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/call-foo.s -o %t/call-foo.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/bar.s -o %t/bar.o
+# RUN: ld.lld -shared -soname=t.so %t/bar.o -o %t/bar.so
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/wrap.s -o %t/wrap.o
+# RUN: ld.lld -shared --soname=fixed %t/wrap.o -o %t/wrap.so
+
+# RUN: ld.lld -shared %t/main.o %t/call-foo.o --wrap foo -o %t1.so
+# RUN: llvm-readelf -r %t1.so | FileCheck %s --check-prefix=CHECK1
+
+# CHECK1:      R_X86_64_JUMP_SLOT 0000000000000000 bar + 0
+# CHECK1-NEXT: R_X86_64_JUMP_SLOT                  0{{$}}
 
 ## --no-allow-shlib-undefined errors because __real_foo is not defined.
-# RUN: not ld.lld %t.o %t.so -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s
+# RUN: not ld.lld %t/main.o %t/bar.so -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s
 # ERR: {{.*}}.so: undefined reference to __real_foo [--no-allow-shlib-undefined]
 
 ## --wrap=foo defines __real_foo.
-# RUN: ld.lld %t.o %t.so --wrap=foo -o %t
-# RUN: llvm-readelf --dyn-syms %t | FileCheck %s
+# RUN: ld.lld %t/main.o %t/bar.so --wrap=foo -o %t2
+# RUN: llvm-readelf --dyn-syms %t2 | FileCheck %s --check-prefix=CHECK2
 
-## The reference __real_foo from %t.so causes foo to be exported.
+## The reference __real_foo from %t/bar.so causes foo to be exported.
 ## __wrap_foo is not used, thus not exported.
-# CHECK:      Symbol table '.dynsym' contains 3 entries:
-# CHECK:      NOTYPE  LOCAL  DEFAULT  UND
-# CHECK-NEXT: NOTYPE  GLOBAL DEFAULT  UND bar
-# CHECK-NEXT: NOTYPE  GLOBAL DEFAULT    6 foo
-
-# RUN: llvm-mc -filetype=obj -triple=x86_64 %t.dir/wrap.s -o %twrap.o
-# RUN: ld.lld -shared --soname=fixed %twrap.o -o %twrap.so
-# RUN: ld.lld %t.o %twrap.so --wrap bar -o %t1
+# CHECK2:      Symbol table '.dynsym' contains 3 entries:
+# CHECK2:      NOTYPE  LOCAL  DEFAULT  UND
+# CHECK2-NEXT: NOTYPE  GLOBAL DEFAULT  UND bar
+# CHECK2-NEXT: NOTYPE  GLOBAL DEFAULT    6 foo
+
+## __wrap_bar is undefined.
+# RUN: ld.lld -shared %t.o --wrap=bar -o %t3.so
+# RUN: llvm-readelf -r --dyn-syms %t3.so | FileCheck %s --check-prefix=CHECK3
+# CHECK3:      R_X86_64_JUMP_SLOT 0{{$}}
+# CHECK3:      Symbol table '.dynsym' contains 3 entries:
+# CHECK3:      NOTYPE  LOCAL  DEFAULT  UND
+# CHECK3-NEXT: NOTYPE  GLOBAL DEFAULT    6 _start
+# CHECK3-NEXT: NOTYPE  GLOBAL DEFAULT    6 foo
+
+## __wrap_bar is defined in %t/wrap.so.
+# RUN: ld.lld -shared %t.o %t/wrap.so --wrap=bar -o %t4.so
+# RUN: llvm-readelf -r --dyn-syms %t4.so | FileCheck %s --check-prefix=CHECK4
+# CHECK4:      R_X86_64_JUMP_SLOT {{.*}} __wrap_bar + 0
+# CHECK4:      Symbol table '.dynsym' contains 4 entries:
+# CHECK4:      NOTYPE  LOCAL  DEFAULT  UND
+# CHECK4-NEXT: NOTYPE  GLOBAL DEFAULT  UND __wrap_bar
+# CHECK4-NEXT: NOTYPE  GLOBAL DEFAULT    6 _start
+# CHECK4-NEXT: NOTYPE  GLOBAL DEFAULT    6 foo
+
+# RUN: ld.lld %t.o %t/wrap.so --wrap bar -o %t1
 # RUN: llvm-readelf --dyn-syms %t1 | FileCheck %s --check-prefix=DYNSYM
 # RUN: llvm-objdump -d %t1 | FileCheck %s --check-prefix=ASM
 
@@ -39,6 +65,14 @@ _start:
   call bar
 foo:
 
+#--- call-foo.s
+  call foo
+
+#--- bar.s
+.globl bar
+bar:
+  call __real_foo
+
 #--- wrap.s
 .globl __wrap_bar
 __wrap_bar:


        


More information about the llvm-branch-commits mailing list