1# REQUIRES: x86
2
3# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
4# RUN: echo ".global foo; foo:" | \
5# RUN:   llvm-mc -filetype=obj -triple=x86_64 - -o %tfoo.o
6# RUN: rm -rf %t.dir %t.cwd
7# RUN: mkdir -p %t.dir
8
9## Error if dependent libraries cannot be found.
10# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s -DOBJ=%t.o --check-prefix MISSING
11# MISSING:      error: [[OBJ]]: unable to find library from dependent library specifier: foo.a
12# MISSING-NEXT: error: [[OBJ]]: unable to find library from dependent library specifier: bar
13
14## Can ignore dependent libraries.
15# RUN: not ld.lld %t.o -o /dev/null --no-dependent-libraries 2>&1 | FileCheck %s --check-prefix IGNORE
16# IGNORE: error: undefined symbol: foo
17
18## -r links preserve dependent libraries.
19# RUN: ld.lld %t.o %t.o -r -o %t-r.o
20# RUN: not ld.lld %t-r.o -o /dev/null 2>&1 | sort | FileCheck %s -DOBJ=%t-r.o --check-prefixes MINUSR
21# MINUSR:      error: [[OBJ]]: unable to find library from dependent library specifier: bar
22# MINUSR-NEXT: error: [[OBJ]]: unable to find library from dependent library specifier: foo.a
23# MINUSR-NOT:  unable to find library from dependent library specifier
24
25## Dependent libraries searched for symbols after libraries on the command line.
26# RUN: mkdir -p %t.cwd
27# RUN: cd %t.cwd
28# RUN: llvm-ar rc %t.dir/foo.a %tfoo.o
29# RUN: touch %t.dir/libbar.so
30# RUN: cp %t.dir/foo.a %t.cwd/libcmdline.a
31# RUN: ld.lld %t.o libcmdline.a -o /dev/null -L %t.dir --trace 2>&1 | \
32# RUN:   FileCheck %s -DOBJ=%t.o -DSO=%t.dir --check-prefix CMDLINE \
33# RUN:                --implicit-check-not=foo.a --implicit-check-not=libbar.so
34# CMDLINE:      [[OBJ]]
35# CMDLINE-NEXT: {{^libcmdline\.a}}
36
37## LLD tries to resolve dependent library specifiers in the following order:
38##   1) The literal name in the current working directory.
39##   2) The literal name in a library search path.
40##   3) The name, prefixed with "lib" and suffixed with ".so" or ".a" in a
41##      library search path. This means that a directive of "foo.a" could lead
42##      to a library named "libfoo.a.a" being linked in.
43## When using library search paths for dependent libraries, LLD follows the same
44## rules as for libraries specified on the command line.
45# RUN: cp %t.dir/foo.a %t.cwd/foo.a
46# RUN: cp %t.dir/foo.a %t.dir/libfoo.a.a
47# RUN: ld.lld %t.o -o /dev/null -L %t.dir --trace 2>&1 | \
48# RUN:   FileCheck %s -DOBJ=%t.o -DDIR=%t.dir --check-prefix=CWD \
49# RUN:                --implicit-check-not=foo.a --implicit-check-not=libbar.so
50
51# CWD:      [[OBJ]]
52# CWD-NEXT: {{^foo\.a}}
53
54# RUN: rm %t.cwd/foo.a
55# RUN: ld.lld %t.o -o /dev/null -L %t.dir --trace 2>&1 | \
56# RUN:   FileCheck %s -DOBJ=%t.o -DDIR=%t.dir --check-prefix=PLAIN-DIR \
57# RUN:                --implicit-check-not=foo.a --implicit-check-not=libbar.so
58
59# PLAIN-DIR:      [[OBJ]]
60# PLAIN-DIR-NEXT: [[DIR]]{{[\\/]}}foo.a
61
62# RUN: rm %t.dir/foo.a
63# RUN: ld.lld %t.o -o /dev/null -L %t.dir --trace 2>&1 | \
64# RUN:   FileCheck %s -DOBJ=%t.o -DDIR=%t.dir --check-prefix=LIBA-DIR \
65# RUN:                --implicit-check-not=foo.a --implicit-check-not=libbar.so
66
67# LIBA-DIR:      [[OBJ]]
68# LIBA-DIR-NEXT: [[DIR]]{{[\\/]}}libfoo.a.a
69
70    call foo
71.section ".deplibs","MS",@llvm_dependent_libraries,1
72    .asciz "foo.a"
73    ## Show that an unneeded archive must be present but may not be linked in.
74    .asciz "bar"
75