Skip to content

Commit 215c565

Browse files
committed
[ELF,test] Improve PROVIDE tests
1 parent 41d19fb commit 215c565

File tree

3 files changed

+66
-31
lines changed

3 files changed

+66
-31
lines changed
Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
# REQUIRES: x86
2-
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
3-
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/provide-shared.s -o %t2.o
4-
# RUN: ld.lld %t2.o -o %t2.so -shared
5-
# RUN: echo "SECTIONS { . = . + SIZEOF_HEADERS; PROVIDE(foo = 42);}" > %t.script
6-
# RUN: ld.lld -o %t --script %t.script %t.o %t2.so
7-
# RUN: llvm-readelf -s %t | FileCheck %s
2+
# RUN: rm -rf %t && split-file %s %t && cd %t
3+
# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
4+
# RUN: llvm-mc -filetype=obj -triple=x86_64 b.s -o b.o
5+
# RUN: ld.lld b.o -o b.so -shared -soname=b.so
6+
# RUN: ld.lld -T a.t a.o b.so -o a
7+
# RUN: llvm-readelf -s a | FileCheck %s
88

9-
# CHECK: 000000000000002a 0 NOTYPE GLOBAL DEFAULT ABS foo
9+
# CHECK: 000000000000002a 0 NOTYPE GLOBAL DEFAULT ABS f1
10+
# CHECK: 000000000000002a 0 NOTYPE GLOBAL DEFAULT ABS f2
1011

12+
#--- a.s
1113
.global _start
1214
_start:
13-
.quad foo
15+
.quad f1
16+
17+
#--- b.s
18+
.global f1
19+
.size f1, 8
20+
.type f1, @object
21+
f1:
22+
.quad 42
23+
24+
.global f2
25+
.data
26+
.dc.a f2
27+
28+
#--- a.t
29+
SECTIONS {
30+
. = . + SIZEOF_HEADERS;
31+
PROVIDE(f1 = 42);
32+
PROVIDE(f2 = 42);
33+
}

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

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,54 @@
11
# REQUIRES: x86
2-
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
2+
# RUN: rm -rf %t && split-file %s %t && cd %t
3+
# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
34

45
# Provide new symbol. The value should be 1, like set in PROVIDE()
5-
# RUN: echo "SECTIONS { PROVIDE(newsym = 1);}" > %t.script
6-
# RUN: ld.lld -o %t1 --script %t.script %t
7-
# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=PROVIDE1 %s
6+
# RUN: echo "SECTIONS { PROVIDE(newsym = 1);}" > a1.t
7+
# RUN: ld.lld -o a1 -T a1.t a.o
8+
# RUN: llvm-objdump -t a1 | FileCheck --check-prefix=PROVIDE1 %s
89
# PROVIDE1: 0000000000000001 g *ABS* 0000000000000000 newsym
910

1011
# Provide new symbol (hidden). The value should be 1
11-
# RUN: echo "SECTIONS { PROVIDE_HIDDEN(newsym = 1);}" > %t.script
12-
# RUN: ld.lld -o %t1 --script %t.script %t
13-
# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN1 %s
12+
# RUN: echo "SECTIONS { PROVIDE_HIDDEN(newsym = 1);}" > a2.t
13+
# RUN: ld.lld -o a2 -T a2.t a.o
14+
# RUN: llvm-objdump -t a2 | FileCheck --check-prefix=HIDDEN1 %s
1415
# HIDDEN1: 0000000000000001 l *ABS* 0000000000000000 .hidden newsym
1516

16-
# RUN: echo 'SECTIONS { PROVIDE_HIDDEN("newsym" = 1);}' > %t.script
17-
# RUN: ld.lld -o %t1 --script %t.script %t
18-
# RUN: llvm-objdump -t %t1 | FileCheck --check-prefix=HIDDEN1 %s
17+
# RUN: echo 'SECTIONS { PROVIDE_HIDDEN("newsym" = 1);}' > a2.t
18+
# RUN: ld.lld -o a2 -T a2.t a.o
19+
# RUN: llvm-objdump -t a2 | FileCheck --check-prefix=HIDDEN1 %s
1920

21+
# RUN: ld.lld -o chain -T chain.t a.o
22+
# RUN: llvm-nm chain | FileCheck %s
23+
24+
# CHECK: 0000000000001000 a f1
25+
# CHECK-NEXT: 0000000000001000 A f2
26+
# CHECK-NEXT: 0000000000001000 a g1
27+
# CHECK-NEXT: 0000000000001000 A g2
28+
# CHECK-NEXT: 0000000000001000 A newsym
29+
30+
# RUN: not ld.lld -T chain2.t a.o 2>&1 | FileCheck %s --check-prefix=ERR --implicit-check-not=error:
31+
# ERR-COUNT-3: error: chain2.t:1: symbol not found: undef
32+
33+
#--- a.s
2034
.global _start
2135
_start:
2236
nop
2337

2438
.globl patatino
2539
patatino:
2640
movl newsym, %eax
41+
42+
#--- chain.t
43+
PROVIDE(f2 = 0x1000);
44+
PROVIDE_HIDDEN(f1 = f2);
45+
PROVIDE(newsym = f1);
46+
47+
PROVIDE(g2 = 0x1000);
48+
PROVIDE_HIDDEN(g1 = g2);
49+
PROVIDE(unused = g1);
50+
51+
#--- chain2.t
52+
PROVIDE(f2 = undef);
53+
PROVIDE_HIDDEN(f1 = f2);
54+
PROVIDE(newsym = f1);

0 commit comments

Comments
 (0)