xref: /llvm-project/lld/test/ELF/why-extract.s (revision 7fd3849b3565a1e22719338c6cebea9bcb023fca)
1# REQUIRES: x86
2
3# RUN: rm -rf %t && split-file %s %t
4# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/main.s -o %t/main.o
5# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a.s -o %t/a.o
6# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/a_b.s -o %t/a_b.o
7# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/b.s -o %t/b.o
8# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/err.s -o %t/err.o
9# RUN: llvm-ar rc %t/a.a %t/a.o
10# RUN: llvm-ar rc %t/a_b.a %t/a_b.o
11# RUN: llvm-ar rc %t/b.a %t/b.o
12# RUN: cd %t
13
14## Nothing is extracted from an archive. The file is created with just a header.
15# RUN: ld.lld main.o a.o b.a -o /dev/null --why-extract=why1.txt
16# RUN: FileCheck %s --input-file=why1.txt --check-prefix=CHECK1 --match-full-lines --strict-whitespace
17
18#      CHECK1:reference	extracted	symbol
19#  CHECK1-NOT:{{.}}
20
21## Some archive members are extracted.
22# RUN: ld.lld main.o a_b.a b.a -o /dev/null --why-extract=why2.txt
23# RUN: FileCheck %s --input-file=why2.txt --check-prefix=CHECK2 --match-full-lines --strict-whitespace
24
25## A relocation error does not suppress the output.
26# RUN: rm -f why2.txt && not ld.lld main.o a_b.a b.a err.o -o /dev/null --why-extract=why2.txt
27# RUN: FileCheck %s --input-file=why2.txt --check-prefix=CHECK2 --match-full-lines --strict-whitespace
28
29#      CHECK2:reference	extracted	symbol
30# CHECK2-NEXT:main.o	a_b.a(a_b.o)	a
31# CHECK2-NEXT:a_b.a(a_b.o)	b.a(b.o)	b()
32
33## An undefined symbol error does not suppress the output.
34# RUN: not ld.lld main.o a_b.a -o /dev/null --why-extract=why3.txt
35# RUN: FileCheck %s --input-file=why3.txt --check-prefix=CHECK3 --match-full-lines --strict-whitespace
36
37## Check that backward references are supported.
38## - means stdout.
39# RUN: ld.lld b.a a_b.a main.o -o /dev/null --why-extract=- | FileCheck %s --check-prefix=CHECK4
40
41#      CHECK3:reference	extracted	symbol
42# CHECK3-NEXT:main.o	a_b.a(a_b.o)	a
43
44#      CHECK4:reference	extracted	symbol
45# CHECK4-NEXT:a_b.a(a_b.o)	b.a(b.o)	b()
46# CHECK4-NEXT:main.o	a_b.a(a_b.o)	a
47
48# RUN: ld.lld main.o a_b.a b.a -o /dev/null --no-demangle --why-extract=- | FileCheck %s --check-prefix=MANGLED
49
50# MANGLED: a_b.a(a_b.o)	b.a(b.o)	_Z1bv
51
52# RUN: ld.lld main.o a.a b.a -o /dev/null -u _Z1bv --why-extract=- | FileCheck %s --check-prefix=UNDEFINED
53
54## We insert -u symbol before processing other files, so its name is <internal>.
55## This is not ideal.
56# UNDEFINED: <internal>	b.a(b.o)	b()
57
58# RUN: ld.lld main.o a.a b.a -o /dev/null --undefined-glob '_Z1b*' --why-extract=- | FileCheck %s --check-prefix=UNDEFINED_GLOB
59
60# UNDEFINED_GLOB: --undefined-glob	b.a(b.o)	b()
61
62# RUN: ld.lld main.o a.a b.a -o /dev/null -e _Z1bv --why-extract=- | FileCheck %s --check-prefix=ENTRY
63
64# ENTRY: --entry	b.a(b.o)	b()
65
66# RUN: ld.lld main.o b.a -o /dev/null -T a.lds --why-extract=- | FileCheck %s --check-prefix=SCRIPT
67
68# SCRIPT: <internal>	b.a(b.o)	b()
69
70# RUN: ld.lld main.o --start-lib a_b.o b.o --end-lib -o /dev/null --why-extract=- | FileCheck %s --check-prefix=LAZY
71
72# LAZY: main.o	a_b.o	a
73# LAZY: a_b.o	b.o	b()
74
75# RUN: not ld.lld -shared main.o -o /dev/null --why-extract=/ 2>&1 | FileCheck %s --check-prefix=ERR
76
77# ERR: error: cannot open --why-extract= file /: {{.*}}
78
79#--- main.s
80.globl _start
81_start:
82  call a
83
84#--- a.s
85.globl a
86a:
87
88#--- a_b.s
89.globl a
90a:
91  call _Z1bv
92
93#--- b.s
94.globl _Z1bv
95_Z1bv:
96
97#--- a.lds
98a = _Z1bv;
99
100#--- err.s
101.reloc ., R_X86_64_RELATIVE, 0
102