diff --git a/llvm/test/tools/llvm-ar/bitcode-add.ll b/llvm/test/tools/llvm-ar/bitcode-add.ll new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-ar/bitcode-add.ll @@ -0,0 +1,68 @@ +## Show that when bitcode is added to an archive it is handled correctly. +## The symbol table is as expected and it can be extracted without issue. + +# RUN: rm -rf %t +# RUN: split-file %s %t +# RUN: mkdir -p %t/extracted +# RUN: llvm-as %t/a.ll -o %t/a.bc +# RUN: cd %t + +## Create symtab from bitcode for a new archive. +# RUN: llvm-ar rs new.a a.bc +# RUN: llvm-ar t new.a | FileCheck --check-prefix=FILES %s +# RUN: llvm-nm --print-armap new.a | sort | FileCheck --check-prefix=SYMS %s + +# FILES: a.bc + +# SYMS-NOT: ldata in {{.*}} +# SYMS-NOT: lfunc in {{.*}} +# SYMS: gdata in {{.*}} +# SYMS: gfunc in {{.*}} + +## Create symtab from bitcode for a new thin archive. +# RUN: llvm-ar rs --thin new-thin.a a.bc +# RUN: llvm-ar t new-thin.a | FileCheck --check-prefix=FILES %s +# RUN: llvm-nm --print-armap new-thin.a | sort | FileCheck --check-prefix=SYMS %s + +## Update symtab from bitcode in an existing archive. +# RUN: llvm-ar rS update.a a.bc +# RUN: llvm-ar t update.a | FileCheck --check-prefix=FILES %s +## Check no symbol table is present +# RUN: llvm-nm --print-armap update.a | FileCheck --check-prefix=NOSYMS %s +# RUN: llvm-ar s update.a +# RUN: llvm-ar t update.a | FileCheck --check-prefix=FILES %s +# RUN: llvm-nm --print-armap update.a | sort | FileCheck --check-prefix=SYMS %s + +# NOSYMS-NOT: Archive map + +## Update symtab from bitcode in an existing thin archive. +# RUN: llvm-ar rS --thin update-thin.a a.bc +# RUN: llvm-ar t update-thin.a | FileCheck --check-prefix=FILES %s +## Check no symbol table is present +# RUN: llvm-nm --print-armap update-thin.a | FileCheck --check-prefix=NOSYMS %s +# RUN: llvm-ar s update-thin.a +# RUN: llvm-ar t update-thin.a | FileCheck --check-prefix=FILES %s +# RUN: llvm-nm --print-armap update-thin.a | sort | FileCheck --check-prefix=SYMS %s + +## Create symtab from bitcode from another archive. +# RUN: llvm-ar rS input.a a.bc +# RUN: llvm-ar qsL lib.a input.a +# RUN: llvm-ar t lib.a | FileCheck --check-prefix=FILES %s +# RUN: llvm-nm --print-armap lib.a | sort | FileCheck --check-prefix=SYMS %s + +## Create symtab from bitcode from another thin archive. +# RUN: llvm-ar rS --thin input-thin.a a.bc +# RUN: llvm-ar qsL --thin lib-thin.a input-thin.a +# RUN: llvm-ar t lib-thin.a | FileCheck --check-prefix=FILES %s +# RUN: llvm-nm --print-armap lib-thin.a | sort | FileCheck --check-prefix=SYMS %s + +## Extract bitcode and ensure it has not been changed. +# RUN: cd %t/extracted +# RUN: llvm-ar x %t/new.a a.bc +# RUN: diff a.bc %t/a.bc + +#--- a.ll +@gdata = global i32 0 +@ldata = internal global i32 0 +define void @gfunc() { ret void } +define internal void @lfunc() { ret void } diff --git a/llvm/test/tools/llvm-ar/mri-bitcode.ll b/llvm/test/tools/llvm-ar/mri-bitcode.ll new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-ar/mri-bitcode.ll @@ -0,0 +1,73 @@ +## Show that when bitcode is added to an archive via mri script it is +## handled correctly. The symbol table is as expected and it can be +## extracted without issue. + +# RUN: rm -rf %t +# RUN: split-file %s %t +# RUN: mkdir -p %t/extracted +# RUN: llvm-as %t/a.ll -o %t/a.bc +# RUN: cd %t + +## Create symtab from bitcode for a regular archive. +# RUN: llvm-ar -M < add.mri +# RUN: llvm-ar t archive.a | FileCheck --check-prefix=FILES %s +# RUN: llvm-nm --print-armap archive.a | sort | FileCheck --check-prefix=SYMS %s + +# FILES: a.bc + +# SYMS-NOT: ldata in {{.*}} +# SYMS-NOT: lfunc in {{.*}} +# SYMS: gdata in {{.*}} +# SYMS: gfunc in {{.*}} + +## Create symtab from bitcode for a thin archive. +# RUN: llvm-ar -M < add-thin.mri +# RUN: llvm-ar t thin.a | FileCheck --check-prefix=FILES %s +# RUN: llvm-nm --print-armap thin.a | sort | FileCheck --check-prefix=SYMS %s + +## Create symtab from bitcode from another archive. +# RUN: llvm-ar rS lib.a a.bc +# RUN: llvm-ar -M < addlib.mri +# RUN: llvm-ar t thin.a | FileCheck --check-prefix=FILES %s +# RUN: llvm-nm --print-armap thin.a | sort | FileCheck --check-prefix=SYMS %s + +## Create symtab from bitcode from another thin archive. +# RUN: llvm-ar rS --thin lib-thin.a a.bc +# RUN: llvm-ar -M < addlib-thin.mri +# RUN: llvm-ar t thin.a | FileCheck --check-prefix=FILES %s +# RUN: llvm-nm --print-armap thin.a | sort | FileCheck --check-prefix=SYMS %s + +## Extract bitcode and ensure it has not been changed. +# RUN: cd %t/extracted +# RUN: llvm-ar x %t/archive.a a.bc +# RUN: diff a.bc %t/a.bc + +#--- a.ll +@gdata = global i32 0 +@ldata = internal global i32 0 +define void @gfunc() { ret void } +define internal void @lfunc() { ret void } + +#--- add.mri +CREATE archive.a +ADDMOD a.bc +SAVE +END + +#--- add-thin.mri +CREATETHIN thin.a +ADDMOD a.bc +SAVE +END + +#--- addlib.mri +CREATE addlib.a +ADDLIB lib.a +SAVE +END + +#--- addlib-thin.mri +CREATE addlib-thin.a +ADDLIB lib-thin.a +SAVE +END