[lld] 539c1c0 - [ELF] Improve symbol resolution tests related to both DSO and archive

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 10 22:41:02 PST 2023


Author: Fangrui Song
Date: 2023-11-10T22:40:57-08:00
New Revision: 539c1c02288d8f5f65cded2e3a535e2e37ab516b

URL: https://github.com/llvm/llvm-project/commit/539c1c02288d8f5f65cded2e3a535e2e37ab516b
DIFF: https://github.com/llvm/llvm-project/commit/539c1c02288d8f5f65cded2e3a535e2e37ab516b.diff

LOG: [ELF] Improve symbol resolution tests related to both DSO and archive

Added: 
    

Modified: 
    lld/test/ELF/shared-lazy.s

Removed: 
    lld/test/ELF/Inputs/as-needed-lazy.s
    lld/test/ELF/as-needed-lazy.s


################################################################################
diff  --git a/lld/test/ELF/Inputs/as-needed-lazy.s b/lld/test/ELF/Inputs/as-needed-lazy.s
deleted file mode 100644
index 7f9c360dda2085e..000000000000000
--- a/lld/test/ELF/Inputs/as-needed-lazy.s
+++ /dev/null
@@ -1,3 +0,0 @@
-.global foo
-foo:
-  nop

diff  --git a/lld/test/ELF/as-needed-lazy.s b/lld/test/ELF/as-needed-lazy.s
deleted file mode 100644
index e892b9980aade9d..000000000000000
--- a/lld/test/ELF/as-needed-lazy.s
+++ /dev/null
@@ -1,14 +0,0 @@
-# REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o
-# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/as-needed-lazy.s -o %t2.o
-# RUN: ld.lld %t2.o -o %t2.so -shared
-# RUN: rm -f %t2.a
-# RUN: llvm-ar rc %t2.a %t2.o
-# RUN: ld.lld %t1.o %t2.a --as-needed %t2.so -o %t
-# RUN: llvm-readobj -d %t | FileCheck %s
-
-# CHECK-NOT: NEEDED
-
-.global _start
-_start:
-  nop

diff  --git a/lld/test/ELF/shared-lazy.s b/lld/test/ELF/shared-lazy.s
index 36b8f16e1794d66..b0009563413b149 100644
--- a/lld/test/ELF/shared-lazy.s
+++ b/lld/test/ELF/shared-lazy.s
@@ -1,17 +1,53 @@
-// REQUIRES: x86
-// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o
-// RUN: rm -f %t1.a
-// RUN: llvm-ar rc %t1.a %t1.o
-// RUN: ld.lld %t1.o -o %t1.so -shared
-// RUN: echo ".global foo" > %t2.s
-// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %t2.s -o %t2.o
-// RUN: ld.lld %t1.a %t1.so %t2.o -o %t.so -shared
-// RUN: llvm-readelf --dyn-symbols %t.so | FileCheck %s
-
-// Test that 'foo' from %t1.so is used and we don't fetch a member
-// from the archive.
-
-// CHECK: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT UND foo
-
-.global foo
-foo:
+# REQUIRES: x86
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o && ld.lld a.o -shared -o a.so
+# RUN: llvm-mc -filetype=obj -triple=x86_64 b.s -o b.o && ld.lld b.o -shared -o b.so
+# RUN: llvm-ar rc a.a a.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux ref.s -o ref.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux ref2.s -o ref2.o
+# RUN: ld.lld a.a b.so ref.o -shared -o 1.so
+# RUN: llvm-readelf --dyn-syms 1.so | FileCheck %s
+# RUN: ld.lld a.so a.a ref.o -shared -o 1.so
+# RUN: llvm-readelf --dyn-syms 1.so | FileCheck %s
+
+## The definitions from a.so are used and we don't extract a member from the
+## archive.
+
+# CHECK:      0000000000000000     0 NOTYPE  GLOBAL DEFAULT UND x1
+# CHECK-NEXT: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT UND x2
+
+## The extracted x1 is defined as STB_GLOBAL.
+# RUN: ld.lld ref.o a.a b.so -o 2.so -shared
+# RUN: llvm-readelf --dyn-symbols 2.so | FileCheck %s --check-prefix=CHECK2
+# RUN: ld.lld a.a ref.o b.so -o 2.so -shared
+# RUN: llvm-readelf --dyn-symbols 2.so | FileCheck %s --check-prefix=CHECK2
+
+# CHECK2:      {{.*}}               0 NOTYPE  GLOBAL DEFAULT [[#]] x1
+# CHECK2-NEXT: {{.*}}               0 NOTYPE  WEAK   DEFAULT [[#]] x2
+
+## The extracted x2 is defined as STB_WEAK. x1 is not referenced by any relocatable object file. Undef x1 is unneeded.
+# RUN: ld.lld a.a ref2.o b.so -o 3.so -shared
+# RUN: llvm-readelf --dyn-symbols 3.so | FileCheck %s --check-prefix=CHECK2
+
+# RUN: ld.lld a.a --as-needed a.so -o 4.so -shared
+# RUN: llvm-readelf -d 4.so | FileCheck %s --check-prefix=NONEEDED
+
+# NONEEDED-NOT: NEEDED
+
+#--- a.s
+.global x1
+x1:
+.weak x2
+x2:
+#--- b.s
+.globl x1, x2
+x1:
+x2:
+  .byte 0
+.size x1, .-x1
+.size x2, .-x2
+#--- ref.s
+.globl x1
+.globl x2
+#--- ref2.s
+.globl x2


        


More information about the llvm-commits mailing list