1# REQUIRES: x86
2# RUN: mkdir -p %t
3# RUN: echo ".global _boo; _boo: ret"                           | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/2.o
4# RUN: echo ".global _bar; _bar: ret"                           | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/3.o
5# RUN: echo ".global _undefined; .global _unused; _unused: ret" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/4.o
6# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/main.o
7
8# RUN: rm -f %t/test.a
9# RUN: llvm-ar rcs %t/test.a %t/2.o %t/3.o %t/4.o
10# RUN: %lld %t/main.o %t/test.a -o %t/test.out
11
12## TODO: Run llvm-nm -p to validate symbol order
13# RUN: llvm-nm %t/test.out | FileCheck %s
14# CHECK: T _bar
15# CHECK: T _boo
16# CHECK: T _main
17
18## Linking with the archive first in the command line shouldn't change anything
19# RUN: %lld %t/test.a %t/main.o -o %t/test.out
20# RUN: llvm-nm %t/test.out | FileCheck %s --check-prefix ARCHIVE-FIRST
21# ARCHIVE-FIRST: T _bar
22# ARCHIVE-FIRST: T _boo
23# ARCHIVE-FIRST: T _main
24
25# RUN: llvm-nm %t/test.out | FileCheck %s --check-prefix VISIBLE
26# VISIBLE-NOT: T _undefined
27# VISIBLE-NOT: T _unused
28
29# RUN: %lld %t/test.a %t/main.o -o %t/all-load -all_load
30# RUN: llvm-nm %t/all-load | FileCheck %s --check-prefix ALL-LOAD
31# ALL-LOAD: T _bar
32# ALL-LOAD: T _boo
33# ALL-LOAD: T _main
34# ALL-LOAD: T _unused
35
36.global _main
37_main:
38  callq _boo
39  callq _bar
40  mov $0, %rax
41  ret
42