[lld] 215c565 - [ELF,test] Improve PROVIDE tests

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 12 22:29:41 PST 2023


Author: Fangrui Song
Date: 2023-12-12T22:29:36-08:00
New Revision: 215c5656449c8e817a3759d989f27ba39d711cbd

URL: https://github.com/llvm/llvm-project/commit/215c5656449c8e817a3759d989f27ba39d711cbd
DIFF: https://github.com/llvm/llvm-project/commit/215c5656449c8e817a3759d989f27ba39d711cbd.diff

LOG: [ELF,test] Improve PROVIDE tests

Added: 
    

Modified: 
    lld/test/ELF/linkerscript/provide-shared.s
    lld/test/ELF/linkerscript/symbolreferenced.s

Removed: 
    lld/test/ELF/linkerscript/provide-shared2.s


################################################################################
diff  --git a/lld/test/ELF/linkerscript/provide-shared.s b/lld/test/ELF/linkerscript/provide-shared.s
index 31a297f0991bda..96ad703d7a3694 100644
--- a/lld/test/ELF/linkerscript/provide-shared.s
+++ b/lld/test/ELF/linkerscript/provide-shared.s
@@ -1,13 +1,33 @@
 # REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/provide-shared.s -o %t2.o
-# RUN: ld.lld %t2.o -o %t2.so -shared
-# RUN: echo "SECTIONS { . = . + SIZEOF_HEADERS; PROVIDE(foo = 42);}" > %t.script
-# RUN: ld.lld -o %t --script %t.script %t.o %t2.so
-# RUN: llvm-readelf -s %t | FileCheck  %s
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# 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: ld.lld b.o -o b.so -shared -soname=b.so
+# RUN: ld.lld -T a.t a.o b.so -o a
+# RUN: llvm-readelf -s a | FileCheck  %s
 
-# CHECK: 000000000000002a 0 NOTYPE GLOBAL DEFAULT ABS foo
+# CHECK: 000000000000002a 0 NOTYPE GLOBAL DEFAULT ABS f1
+# CHECK: 000000000000002a 0 NOTYPE GLOBAL DEFAULT ABS f2
 
+#--- a.s
 .global _start
 _start:
-.quad foo
+.quad f1
+
+#--- b.s
+.global f1
+.size f1, 8
+.type f1, @object
+f1:
+.quad 42
+
+.global f2
+.data
+.dc.a f2
+
+#--- a.t
+SECTIONS {
+  . = . + SIZEOF_HEADERS;
+  PROVIDE(f1 = 42);
+  PROVIDE(f2 = 42);
+}

diff  --git a/lld/test/ELF/linkerscript/provide-shared2.s b/lld/test/ELF/linkerscript/provide-shared2.s
deleted file mode 100644
index 3c55d2fa6318c3..00000000000000
--- a/lld/test/ELF/linkerscript/provide-shared2.s
+++ /dev/null
@@ -1,13 +0,0 @@
-# REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/provide-shared2.s -o %t2.o
-# RUN: ld.lld %t2.o -o %t2.so -shared
-# RUN: echo "SECTIONS { . = . + SIZEOF_HEADERS; PROVIDE(foo = 42); }" > %t.script
-# RUN: ld.lld -o %t --script %t.script %t.o %t2.so
-# RUN: llvm-readelf --dyn-symbols %t | FileCheck  %s
-
-# CHECK: 1: 000000000000002a 0 NOTYPE GLOBAL DEFAULT ABS foo
-
-.global _start
-_start:
-        nop

diff  --git a/lld/test/ELF/linkerscript/symbolreferenced.s b/lld/test/ELF/linkerscript/symbolreferenced.s
index f6d9a1214fdd9d..ba7a7721ea9697 100644
--- a/lld/test/ELF/linkerscript/symbolreferenced.s
+++ b/lld/test/ELF/linkerscript/symbolreferenced.s
@@ -1,22 +1,36 @@
 # REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
 
 # Provide new symbol. The value should be 1, like set in PROVIDE()
-# RUN: echo "SECTIONS { PROVIDE(newsym = 1);}" > %t.script
-# RUN: ld.lld -o %t1 --script %t.script %t
-# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=PROVIDE1 %s
+# RUN: echo "SECTIONS { PROVIDE(newsym = 1);}" > a1.t
+# RUN: ld.lld -o a1 -T a1.t a.o
+# RUN: llvm-objdump -t a1 | FileCheck --check-prefix=PROVIDE1 %s
 # PROVIDE1: 0000000000000001 g       *ABS*  0000000000000000 newsym
 
 # Provide new symbol (hidden). The value should be 1
-# RUN: echo "SECTIONS { PROVIDE_HIDDEN(newsym = 1);}" > %t.script
-# RUN: ld.lld -o %t1 --script %t.script %t
-# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN1 %s
+# RUN: echo "SECTIONS { PROVIDE_HIDDEN(newsym = 1);}" > a2.t
+# RUN: ld.lld -o a2 -T a2.t a.o
+# RUN: llvm-objdump -t a2 | FileCheck --check-prefix=HIDDEN1 %s
 # HIDDEN1: 0000000000000001 l       *ABS*  0000000000000000 .hidden newsym
 
-# RUN: echo 'SECTIONS { PROVIDE_HIDDEN("newsym" = 1);}' > %t.script
-# RUN: ld.lld -o %t1 --script %t.script %t
-# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN1 %s
+# RUN: echo 'SECTIONS { PROVIDE_HIDDEN("newsym" = 1);}' > a2.t
+# RUN: ld.lld -o a2 -T a2.t a.o
+# RUN: llvm-objdump -t a2 | FileCheck --check-prefix=HIDDEN1 %s
 
+# RUN: ld.lld -o chain -T chain.t a.o
+# RUN: llvm-nm chain | FileCheck %s
+
+# CHECK:      0000000000001000 a f1
+# CHECK-NEXT: 0000000000001000 A f2
+# CHECK-NEXT: 0000000000001000 a g1
+# CHECK-NEXT: 0000000000001000 A g2
+# CHECK-NEXT: 0000000000001000 A newsym
+
+# RUN: not ld.lld -T chain2.t a.o 2>&1 | FileCheck %s --check-prefix=ERR --implicit-check-not=error:
+# ERR-COUNT-3: error: chain2.t:1: symbol not found: undef
+
+#--- a.s
 .global _start
 _start:
  nop
@@ -24,3 +38,17 @@ _start:
 .globl patatino
 patatino:
   movl newsym, %eax
+
+#--- chain.t
+PROVIDE(f2 = 0x1000);
+PROVIDE_HIDDEN(f1 = f2);
+PROVIDE(newsym = f1);
+
+PROVIDE(g2 = 0x1000);
+PROVIDE_HIDDEN(g1 = g2);
+PROVIDE(unused = g1);
+
+#--- chain2.t
+PROVIDE(f2 = undef);
+PROVIDE_HIDDEN(f1 = f2);
+PROVIDE(newsym = f1);


        


More information about the llvm-commits mailing list