xref: /llvm-project/llvm/test/tools/llvm-libtool-darwin/create-static-lib.test (revision bd0bddc1ea72183813d49508c8b4e73920869ea5)
1## This test checks that a correct static library is created.
2
3# RUN: yaml2obj %S/Inputs/input1.yaml -o %t-input1.o
4# RUN: yaml2obj %S/Inputs/input2.yaml -o %t-input2.o
5# RUN: llvm-as %S/Inputs/x86_64-osx.ll -o %t-x86_64.bc
6
7# RUN: rm -rf %t.lib %t2.lib
8# RUN: llvm-libtool-darwin -static -o %t.lib %t-input1.o %t-input2.o %t-x86_64.bc
9# RUN: llvm-libtool-darwin -static -o %t2.lib -o %t.lib %t-input1.o %t-input2.o %t-x86_64.bc
10# RUN: not ls %t2.lib
11
12## Check that binaries are present:
13# RUN: llvm-ar t %t.lib | \
14# RUN:   FileCheck %s --check-prefix=CHECK-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
15
16# CHECK-NAMES:      [[PREFIX]]-input1.o
17# CHECK-NAMES-NEXT: [[PREFIX]]-input2.o
18# CHECK-NAMES-NEXT: [[PREFIX]]-x86_64.bc
19
20## Check that symbols are present:
21# RUN: llvm-nm --print-armap %t.lib | \
22# RUN:   FileCheck %s --check-prefix=CHECK-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines
23
24# CHECK-SYMBOLS:      Archive map
25# CHECK-SYMBOLS-NEXT: _symbol1 in [[PREFIX]]-input1.o
26# CHECK-SYMBOLS-NEXT: _symbol2 in [[PREFIX]]-input2.o
27# CHECK-SYMBOLS-NEXT: _x86_64 in [[PREFIX]]-x86_64.bc
28# CHECK-SYMBOLS-EMPTY:
29
30## Check that output archive is in Darwin format:
31# RUN: llvm-objdump --macho --archive-headers %t.lib | \
32# RUN:   FileCheck %s --check-prefix=FORMAT -DPREFIX=%basename_t.tmp -DARCHIVE=%t
33
34# FORMAT:      Archive : [[ARCHIVE]]
35# FORMAT-NEXT: __.SYMDEF
36# FORMAT-NEXT: [[PREFIX]]-input1.o
37# FORMAT-NEXT: [[PREFIX]]-input2.o
38# FORMAT-NEXT: [[PREFIX]]-x86_64.bc
39# FORMAT-NOT:  {{.}}
40
41## Check that the output file is overwritten:
42# RUN: llvm-libtool-darwin -static -o %t.lib %t-input2.o
43# RUN: llvm-ar t %t.lib | \
44# RUN:   FileCheck %s --check-prefix=OVERWRITE-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
45# RUN: llvm-nm --print-armap %t.lib | \
46# RUN:   FileCheck %s --check-prefix=OVERWRITE-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines
47
48# OVERWRITE-NAMES: [[PREFIX]]-input2.o
49
50# OVERWRITE-SYMBOLS:      Archive map
51# OVERWRITE-SYMBOLS-NEXT: _symbol2 in [[PREFIX]]-input2.o
52# OVERWRITE-SYMBOLS-EMPTY:
53
54## Duplicate a binary:
55# RUN: llvm-libtool-darwin -static -o %t.lib %t-input1.o %t-input2.o %t-input1.o 2>&1 | \
56# RUN:   FileCheck %s --check-prefix=DUPLICATE-INPUT -DFILE=%basename_t.tmp-input1.o \
57# RUN:     -DINPUTA=%t-input1.o -DINPUTB=%t-input1.o
58
59# DUPLICATE-INPUT:     warning: file '[[FILE]]' was specified multiple times.
60# DUPLICATE-INPUT-DAG: [[INPUTA]]
61# DUPLICATE-INPUT-DAG: [[INPUTB]]
62
63# RUN: not llvm-libtool-darwin -warnings_as_errors -static -o %t.lib %t-input1.o %t-input2.o %t-input1.o 2>&1 | \
64# RUN:   FileCheck %s --check-prefix=ERROR-DUPLICATE-INPUT -DFILE=%basename_t.tmp-input1.o \
65# RUN:     -DINPUTA=%t-input1.o -DINPUTB=%t-input1.o
66
67# ERROR-DUPLICATE-INPUT:     error: file '[[FILE]]' was specified multiple times.
68# ERROR-DUPLICATE-INPUT-DAG: [[INPUTA]]
69# ERROR-DUPLICATE-INPUT-DAG: [[INPUTB]]
70
71## Make sure we can combine object files with the same name if
72## they are for different architectures.
73# RUN: mkdir -p %t/arm64 %t/armv7
74# RUN: llvm-as %S/Inputs/arm64-ios.ll -o %t/arm64/out.bc
75# RUN: llvm-as %S/Inputs/armv7-ios.ll -o %t/armv7/out.bc
76## Command output should be empty.
77# RUN: llvm-libtool-darwin -static %t/arm64/out.bc %t/armv7/out.bc -o %t.lib 2>&1 | \
78# RUN:   FileCheck %s --implicit-check-not=warning: --allow-empty
79