1# REQUIRES: x86
2# RUN: rm -rf %t; split-file %s %t
3# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/archive-foo.s -o %t/archive-foo.o
4# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/archive-baz.s -o %t/archive-baz.o
5# RUN: llvm-ar rcs %t/foo.a %t/archive-foo.o
6# RUN: llvm-ar rcs %t/baz.a %t/archive-baz.o
7# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/foo.s -o %t/foo.o
8# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
9
10# RUN: %lld -lSystem -force_load %t/foo.a %t/foo.o %t/test.o -o %t/test-force-load-first
11# FORCE-LOAD-FIRST:  __TEXT,archive _foo
12# RUN: llvm-objdump --syms %t/test-force-load-first | FileCheck %s --check-prefix=FORCE-LOAD-FIRST
13
14# RUN: %lld %t/foo.o -lSystem -force_load %t/foo.a %t/test.o -o %t/test-force-load-second
15# RUN: llvm-objdump --syms %t/test-force-load-second | FileCheck %s --check-prefix=FORCE-LOAD-SECOND
16# FORCE-LOAD-SECOND: __TEXT,obj _foo
17
18## If an archive has already been loaded w/o -force_load earlier in the command
19## line, a later -force_load argument will not have an effect.
20# RUN: %lld -lSystem %t/foo.a -force_load %t/foo.a %t/test.o -o %t/test-regular-then-force
21# RUN: llvm-objdump --syms %t/test-regular-then-force | FileCheck %s --check-prefix=REGULAR-THEN-FORCE
22# REGULAR-THEN-FORCE-NOT: _foo
23## If the -force_load comes first, then the second load will just be a no-op.
24# RUN: %lld -lSystem -force_load %t/foo.a %t/foo.a %t/test.o -o %t/test-force-then-regular
25# RUN: llvm-objdump --syms %t/test-force-then-regular | FileCheck %s --check-prefix=FORCE-THEN-REGULAR
26# FORCE-THEN-REGULAR: _foo
27
28## Force-loading the same path twice is fine
29# RUN: %lld -lSystem %t/foo.o -force_load %t/foo.a -force_load %t/foo.a %t/test.o -o /dev/null
30
31## Note that we do not call realpath() before dedup'ing the force-load
32## arguments, so this is an error.
33# RUN: cd %t; not %lld -lSystem %t/foo.o -force_load %t/foo.a -force_load foo.a \
34# RUN:   %t/test.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=DUP
35
36# DUP: error: duplicate symbol: _bar
37
38## Force-loading two different paths w/o conflicting symbols is fine
39# RUN: %lld -lSystem -force_load %t/foo.a -force_load %t/baz.a %t/test.o -o %t/test-two-force-loads
40# RUN: llvm-objdump --syms %t/test-two-force-loads | FileCheck %s --check-prefix=TWICE
41# TWICE-DAG: __TEXT,archive _foo
42# TWICE-DAG: __TEXT,archive _bar
43# TWICE-DAG: __TEXT,archive _baz
44
45#--- archive-foo.s
46.section __TEXT,archive
47.globl _foo, _bar
48.weak_definition _foo
49_foo:
50_bar:
51
52#--- archive-baz.s
53.section __TEXT,archive
54.globl _baz
55_baz:
56
57#--- foo.s
58.section __TEXT,obj
59.globl _foo
60.weak_definition _foo
61_foo:
62
63#--- test.s
64.globl _main
65_main:
66  ret
67