xref: /llvm-project/llvm/test/tools/llvm-libtool-darwin/create-static-lib.test (revision bd0bddc1ea72183813d49508c8b4e73920869ea5)
1303a7f7aSSameer Arora## This test checks that a correct static library is created.
2303a7f7aSSameer Arora
3303a7f7aSSameer Arora# RUN: yaml2obj %S/Inputs/input1.yaml -o %t-input1.o
4303a7f7aSSameer Arora# RUN: yaml2obj %S/Inputs/input2.yaml -o %t-input2.o
505f7b682SPaul-Antoine Arras# RUN: llvm-as %S/Inputs/x86_64-osx.ll -o %t-x86_64.bc
6303a7f7aSSameer Arora
7*bd0bddc1SFangrui Song# RUN: rm -rf %t.lib %t2.lib
805f7b682SPaul-Antoine Arras# RUN: llvm-libtool-darwin -static -o %t.lib %t-input1.o %t-input2.o %t-x86_64.bc
9*bd0bddc1SFangrui Song# RUN: llvm-libtool-darwin -static -o %t2.lib -o %t.lib %t-input1.o %t-input2.o %t-x86_64.bc
10*bd0bddc1SFangrui Song# RUN: not ls %t2.lib
11303a7f7aSSameer Arora
12303a7f7aSSameer Arora## Check that binaries are present:
13303a7f7aSSameer Arora# RUN: llvm-ar t %t.lib | \
14303a7f7aSSameer Arora# RUN:   FileCheck %s --check-prefix=CHECK-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
15303a7f7aSSameer Arora
16303a7f7aSSameer Arora# CHECK-NAMES:      [[PREFIX]]-input1.o
17303a7f7aSSameer Arora# CHECK-NAMES-NEXT: [[PREFIX]]-input2.o
1805f7b682SPaul-Antoine Arras# CHECK-NAMES-NEXT: [[PREFIX]]-x86_64.bc
19303a7f7aSSameer Arora
20303a7f7aSSameer Arora## Check that symbols are present:
21303a7f7aSSameer Arora# RUN: llvm-nm --print-armap %t.lib | \
22303a7f7aSSameer Arora# RUN:   FileCheck %s --check-prefix=CHECK-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines
23303a7f7aSSameer Arora
24303a7f7aSSameer Arora# CHECK-SYMBOLS:      Archive map
25303a7f7aSSameer Arora# CHECK-SYMBOLS-NEXT: _symbol1 in [[PREFIX]]-input1.o
26303a7f7aSSameer Arora# CHECK-SYMBOLS-NEXT: _symbol2 in [[PREFIX]]-input2.o
2705f7b682SPaul-Antoine Arras# CHECK-SYMBOLS-NEXT: _x86_64 in [[PREFIX]]-x86_64.bc
28303a7f7aSSameer Arora# CHECK-SYMBOLS-EMPTY:
29303a7f7aSSameer Arora
30303a7f7aSSameer Arora## Check that output archive is in Darwin format:
31303a7f7aSSameer Arora# RUN: llvm-objdump --macho --archive-headers %t.lib | \
32303a7f7aSSameer Arora# RUN:   FileCheck %s --check-prefix=FORMAT -DPREFIX=%basename_t.tmp -DARCHIVE=%t
33303a7f7aSSameer Arora
34303a7f7aSSameer Arora# FORMAT:      Archive : [[ARCHIVE]]
35303a7f7aSSameer Arora# FORMAT-NEXT: __.SYMDEF
36303a7f7aSSameer Arora# FORMAT-NEXT: [[PREFIX]]-input1.o
37303a7f7aSSameer Arora# FORMAT-NEXT: [[PREFIX]]-input2.o
3805f7b682SPaul-Antoine Arras# FORMAT-NEXT: [[PREFIX]]-x86_64.bc
39303a7f7aSSameer Arora# FORMAT-NOT:  {{.}}
40303a7f7aSSameer Arora
41303a7f7aSSameer Arora## Check that the output file is overwritten:
42303a7f7aSSameer Arora# RUN: llvm-libtool-darwin -static -o %t.lib %t-input2.o
43303a7f7aSSameer Arora# RUN: llvm-ar t %t.lib | \
44303a7f7aSSameer Arora# RUN:   FileCheck %s --check-prefix=OVERWRITE-NAMES --implicit-check-not={{.}} -DPREFIX=%basename_t.tmp
45303a7f7aSSameer Arora# RUN: llvm-nm --print-armap %t.lib | \
46303a7f7aSSameer Arora# RUN:   FileCheck %s --check-prefix=OVERWRITE-SYMBOLS -DPREFIX=%basename_t.tmp --match-full-lines
47303a7f7aSSameer Arora
48303a7f7aSSameer Arora# OVERWRITE-NAMES: [[PREFIX]]-input2.o
49303a7f7aSSameer Arora
50303a7f7aSSameer Arora# OVERWRITE-SYMBOLS:      Archive map
51303a7f7aSSameer Arora# OVERWRITE-SYMBOLS-NEXT: _symbol2 in [[PREFIX]]-input2.o
52303a7f7aSSameer Arora# OVERWRITE-SYMBOLS-EMPTY:
53303a7f7aSSameer Arora
54303a7f7aSSameer Arora## Duplicate a binary:
55303a7f7aSSameer Arora# RUN: llvm-libtool-darwin -static -o %t.lib %t-input1.o %t-input2.o %t-input1.o 2>&1 | \
56f4744e9aSShoaib Meenai# RUN:   FileCheck %s --check-prefix=DUPLICATE-INPUT -DFILE=%basename_t.tmp-input1.o \
57f4744e9aSShoaib Meenai# RUN:     -DINPUTA=%t-input1.o -DINPUTB=%t-input1.o
58303a7f7aSSameer Arora
59f4744e9aSShoaib Meenai# DUPLICATE-INPUT:     warning: file '[[FILE]]' was specified multiple times.
60f4744e9aSShoaib Meenai# DUPLICATE-INPUT-DAG: [[INPUTA]]
61f4744e9aSShoaib Meenai# DUPLICATE-INPUT-DAG: [[INPUTB]]
62303a7f7aSSameer Arora
634c12a75eSKeith Smiley# RUN: not llvm-libtool-darwin -warnings_as_errors -static -o %t.lib %t-input1.o %t-input2.o %t-input1.o 2>&1 | \
644c12a75eSKeith Smiley# RUN:   FileCheck %s --check-prefix=ERROR-DUPLICATE-INPUT -DFILE=%basename_t.tmp-input1.o \
654c12a75eSKeith Smiley# RUN:     -DINPUTA=%t-input1.o -DINPUTB=%t-input1.o
664c12a75eSKeith Smiley
674c12a75eSKeith Smiley# ERROR-DUPLICATE-INPUT:     error: file '[[FILE]]' was specified multiple times.
684c12a75eSKeith Smiley# ERROR-DUPLICATE-INPUT-DAG: [[INPUTA]]
694c12a75eSKeith Smiley# ERROR-DUPLICATE-INPUT-DAG: [[INPUTB]]
704c12a75eSKeith Smiley
71f4744e9aSShoaib Meenai## Make sure we can combine object files with the same name if
72f4744e9aSShoaib Meenai## they are for different architectures.
73f4744e9aSShoaib Meenai# RUN: mkdir -p %t/arm64 %t/armv7
74f4744e9aSShoaib Meenai# RUN: llvm-as %S/Inputs/arm64-ios.ll -o %t/arm64/out.bc
75f4744e9aSShoaib Meenai# RUN: llvm-as %S/Inputs/armv7-ios.ll -o %t/armv7/out.bc
76f4744e9aSShoaib Meenai## Command output should be empty.
77f4744e9aSShoaib Meenai# RUN: llvm-libtool-darwin -static %t/arm64/out.bc %t/armv7/out.bc -o %t.lib 2>&1 | \
78f4744e9aSShoaib Meenai# RUN:   FileCheck %s --implicit-check-not=warning: --allow-empty
79