xref: /llvm-project/llvm/test/tools/llvm-ar/bitcode.ll (revision e97a6f6104ccc978fbff94adaf5abd40976976e1)
1*e97a6f61Sgbreynoo## Show that when bitcode is added to an archive it is handled correctly.
2*e97a6f61Sgbreynoo## The symbol table is as expected and it can be extracted without issue.
3*e97a6f61Sgbreynoo
4*e97a6f61Sgbreynoo# RUN: rm -rf %t
5*e97a6f61Sgbreynoo# RUN: split-file %s %t && mkdir -p %t/extracted
6*e97a6f61Sgbreynoo# RUN: cd %t
7*e97a6f61Sgbreynoo# RUN: llvm-as a.ll -o a.bc
8*e97a6f61Sgbreynoo
9*e97a6f61Sgbreynoo## Create symtab from bitcode for a new archive.
10*e97a6f61Sgbreynoo# RUN: llvm-ar rcs new.a a.bc
11*e97a6f61Sgbreynoo# RUN: llvm-ar t new.a | FileCheck --check-prefix=FILES %s --implicit-check-not={{.}}
12*e97a6f61Sgbreynoo# RUN: llvm-nm --print-armap new.a | FileCheck --check-prefix=SYMS %s --implicit-check-not={{.}}
13*e97a6f61Sgbreynoo
14*e97a6f61Sgbreynoo# FILES: a.bc
15*e97a6f61Sgbreynoo
16*e97a6f61Sgbreynoo# SYMS:      Archive map
17*e97a6f61Sgbreynoo# SYMS-NEXT: gfunc in a.bc
18*e97a6f61Sgbreynoo# SYMS-NEXT: gdata in a.bc
19*e97a6f61Sgbreynoo
20*e97a6f61Sgbreynoo# SYMS:      a.bc:
21*e97a6f61Sgbreynoo# SYMS-NEXT: -------- D gdata
22*e97a6f61Sgbreynoo# SYMS-NEXT: -------- T gfunc
23*e97a6f61Sgbreynoo# SYMS-NEXT: -------- d ldata
24*e97a6f61Sgbreynoo# SYMS-NEXT: -------- t lfunc
25*e97a6f61Sgbreynoo
26*e97a6f61Sgbreynoo## Update symtab from bitcode in an existing archive.
27*e97a6f61Sgbreynoo# RUN: llvm-ar rcS update.a a.bc
28*e97a6f61Sgbreynoo# RUN: llvm-ar t update.a | FileCheck --check-prefix=FILES %s --implicit-check-not={{.}}
29*e97a6f61Sgbreynoo## Check no symbol table is present.
30*e97a6f61Sgbreynoo# RUN: llvm-nm --print-armap update.a | FileCheck --check-prefix=NOSYMS %s --implicit-check-not={{.}}
31*e97a6f61Sgbreynoo# RUN: llvm-ar s update.a
32*e97a6f61Sgbreynoo# RUN: llvm-ar t update.a | FileCheck --check-prefix=FILES %s --implicit-check-not={{.}}
33*e97a6f61Sgbreynoo# RUN: llvm-nm --print-armap update.a | FileCheck --check-prefix=SYMS %s --implicit-check-not={{.}}
34*e97a6f61Sgbreynoo
35*e97a6f61Sgbreynoo# NOSYMS: a.bc:
36*e97a6f61Sgbreynoo# NOSYMS-NEXT: -------- D gdata
37*e97a6f61Sgbreynoo# NOSYMS-NEXT: -------- T gfunc
38*e97a6f61Sgbreynoo# NOSYMS-NEXT: -------- d ldata
39*e97a6f61Sgbreynoo# NOSYMS-NEXT: -------- t lfunc
40*e97a6f61Sgbreynoo
41*e97a6f61Sgbreynoo## Create symtab from bitcode for a regular archive via MRI script.
42*e97a6f61Sgbreynoo# RUN: llvm-ar -M < add.mri
43*e97a6f61Sgbreynoo# RUN: llvm-ar t mri.a | FileCheck --check-prefix=FILES %s --implicit-check-not={{.}}
44*e97a6f61Sgbreynoo# RUN: llvm-nm --print-armap mri.a | FileCheck --check-prefix=SYMS %s --implicit-check-not={{.}}
45*e97a6f61Sgbreynoo
46*e97a6f61Sgbreynoo## Create symtab from bitcode for a new thin archive.
47*e97a6f61Sgbreynoo# RUN: llvm-ar rcs --thin new-thin.a a.bc
48*e97a6f61Sgbreynoo# RUN: llvm-ar t new-thin.a | FileCheck --check-prefix=FILES %s --implicit-check-not={{.}}
49*e97a6f61Sgbreynoo# RUN: llvm-nm --print-armap new-thin.a | FileCheck --check-prefix=SYMS %s --implicit-check-not={{.}}
50*e97a6f61Sgbreynoo
51*e97a6f61Sgbreynoo## Update symtab from bitcode in an existing thin archive.
52*e97a6f61Sgbreynoo# RUN: llvm-ar rcS --thin update-thin.a a.bc
53*e97a6f61Sgbreynoo# RUN: llvm-ar t update-thin.a | FileCheck --check-prefix=FILES %s --implicit-check-not={{.}}
54*e97a6f61Sgbreynoo## Check no symbol table is present.
55*e97a6f61Sgbreynoo# RUN: llvm-nm --print-armap update-thin.a | FileCheck --check-prefix=NOSYMS %s --implicit-check-not={{.}}
56*e97a6f61Sgbreynoo# RUN: llvm-ar s update-thin.a
57*e97a6f61Sgbreynoo# RUN: llvm-ar t update-thin.a | FileCheck --check-prefix=FILES %s --implicit-check-not={{.}}
58*e97a6f61Sgbreynoo# RUN: llvm-nm --print-armap update-thin.a | FileCheck --check-prefix=SYMS %s --implicit-check-not={{.}}
59*e97a6f61Sgbreynoo
60*e97a6f61Sgbreynoo## Create symtab from bitcode for a thin archive via MRI script.
61*e97a6f61Sgbreynoo# RUN: llvm-ar -M < add-thin.mri
62*e97a6f61Sgbreynoo# RUN: llvm-ar t mri-thin.a | FileCheck --check-prefix=FILES %s --implicit-check-not={{.}}
63*e97a6f61Sgbreynoo# RUN: llvm-nm --print-armap mri-thin.a | FileCheck --check-prefix=SYMS %s --implicit-check-not={{.}}
64*e97a6f61Sgbreynoo
65*e97a6f61Sgbreynoo## Create symtab from bitcode from another archive.
66*e97a6f61Sgbreynoo# RUN: llvm-ar rcs input.a a.bc
67*e97a6f61Sgbreynoo# RUN: llvm-ar cqsL lib.a input.a
68*e97a6f61Sgbreynoo# RUN: llvm-ar t lib.a | FileCheck --check-prefix=FILES %s --implicit-check-not={{.}}
69*e97a6f61Sgbreynoo# RUN: llvm-nm --print-armap lib.a | FileCheck --check-prefix=SYMS %s --implicit-check-not={{.}}
70*e97a6f61Sgbreynoo
71*e97a6f61Sgbreynoo## Create symtab from bitcode from another archive via MRI script.
72*e97a6f61Sgbreynoo# RUN: llvm-ar -M < addlib.mri
73*e97a6f61Sgbreynoo# RUN: llvm-ar t mri-addlib.a | FileCheck --check-prefix=FILES %s --implicit-check-not={{.}}
74*e97a6f61Sgbreynoo# RUN: llvm-nm --print-armap mri-addlib.a | FileCheck --check-prefix=SYMS %s --implicit-check-not={{.}}
75*e97a6f61Sgbreynoo
76*e97a6f61Sgbreynoo## Create symtab from bitcode from another thin archive.
77*e97a6f61Sgbreynoo# RUN: llvm-ar rcs --thin input-thin.a a.bc
78*e97a6f61Sgbreynoo# RUN: llvm-ar cqsL --thin lib-thin.a input-thin.a
79*e97a6f61Sgbreynoo# RUN: llvm-ar t lib-thin.a | FileCheck --check-prefix=FILES %s --implicit-check-not={{.}}
80*e97a6f61Sgbreynoo# RUN: llvm-nm --print-armap lib-thin.a | FileCheck --check-prefix=SYMS %s --implicit-check-not={{.}}
81*e97a6f61Sgbreynoo
82*e97a6f61Sgbreynoo## Create symtab from bitcode from another thin archive via MRI script.
83*e97a6f61Sgbreynoo# RUN: llvm-ar -M < addlib-thin.mri
84*e97a6f61Sgbreynoo# RUN: llvm-ar t mri-addlib-thin.a | FileCheck --check-prefix=FILES %s --implicit-check-not={{.}}
85*e97a6f61Sgbreynoo# RUN: llvm-nm --print-armap mri-addlib-thin.a | FileCheck --check-prefix=SYMS %s --implicit-check-not={{.}}
86*e97a6f61Sgbreynoo
87*e97a6f61Sgbreynoo## Extract bitcode and ensure it has not been changed.
88*e97a6f61Sgbreynoo# RUN: cd extracted
89*e97a6f61Sgbreynoo# RUN: llvm-ar x ../new.a a.bc
90*e97a6f61Sgbreynoo# RUN: cmp a.bc a.bc
91*e97a6f61Sgbreynoo
92*e97a6f61Sgbreynoo#--- a.ll
93*e97a6f61Sgbreynoo@gdata = global i32 0
94*e97a6f61Sgbreynoo@ldata = internal global i32 0
95*e97a6f61Sgbreynoodefine void @gfunc() { ret void }
96*e97a6f61Sgbreynoodefine internal void @lfunc() { ret void }
97*e97a6f61Sgbreynoo
98*e97a6f61Sgbreynoo#--- add.mri
99*e97a6f61SgbreynooCREATE mri.a
100*e97a6f61SgbreynooADDMOD a.bc
101*e97a6f61SgbreynooSAVE
102*e97a6f61SgbreynooEND
103*e97a6f61Sgbreynoo
104*e97a6f61Sgbreynoo#--- add-thin.mri
105*e97a6f61SgbreynooCREATETHIN mri-thin.a
106*e97a6f61SgbreynooADDMOD a.bc
107*e97a6f61SgbreynooSAVE
108*e97a6f61SgbreynooEND
109*e97a6f61Sgbreynoo
110*e97a6f61Sgbreynoo#--- addlib.mri
111*e97a6f61SgbreynooCREATE mri-addlib.a
112*e97a6f61SgbreynooADDLIB input.a
113*e97a6f61SgbreynooSAVE
114*e97a6f61SgbreynooEND
115*e97a6f61Sgbreynoo
116*e97a6f61Sgbreynoo#--- addlib-thin.mri
117*e97a6f61SgbreynooCREATE mri-addlib-thin.a
118*e97a6f61SgbreynooADDLIB input-thin.a
119*e97a6f61SgbreynooSAVE
120*e97a6f61SgbreynooEND
121