[llvm] Object: Don't error out on malformed bitcode files. (PR #96848)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 11 00:56:54 PDT 2024


================
@@ -9,37 +10,65 @@
 # RUN: llvm-as input.ll -o input.bc
 # RUN: cp input.bc good.bc
 # RUN: %python -c "with open('input.bc', 'a') as f: f.truncate(10)"
-# RUN: not llvm-ar rc bad.a input.bc 2>&1 | FileCheck %s --check-prefix=ERR1
+# RUN: llvm-ar rc bad.a input.bc 2>&1 | FileCheck %s --check-prefix=WARN1
+
+## llvm-nm will fail when it tries to read the malformed bitcode file, but
+## it's supposed to print the archive map first, which in this case it
+## won't because there won't be one.
+# RUN: not llvm-nm --print-armap bad.a | count 0
 
 ## Malformed bitcode object is the last file member of archive if the symbol table is required.
 # RUN: rm -rf bad.a
-# RUN: not llvm-ar rc bad.a good.bc input.bc 2>&1 | FileCheck %s --check-prefix=ERR1
+# RUN: llvm-ar rc bad.a good.bc input.bc 2>&1 | FileCheck %s --check-prefix=WARN1
+# RUN: not llvm-nm --print-armap bad.a | FileCheck %s --check-prefix=ARMAP
+
+## Malformed bitcode object either warn or error depending on the archive format
+## (see switch in getSymbolicFile).
+# RUN: rm -rf bad.a
+# RUN: llvm-ar --format=bsd rc bad.a input.bc 2>&1 | FileCheck %s --check-prefix=WARN1
+# RUN: rm -rf bad.a
+# RUN: llvm-ar --format=gnu rc bad.a input.bc 2>&1 | FileCheck %s --check-prefix=WARN1
+# RUN: rm -rf bad.a
+# RUN: not llvm-ar --format=bigarchive rc bad.a input.bc 2>&1 | FileCheck %s --check-prefix=ERR1
+# RUN: rm -rf bad.a
+# RUN: not llvm-ar --format=coff rc bad.a input.bc 2>&1 | FileCheck %s --check-prefix=ERR1
+# RUN: rm -rf bad.a
+# RUN: not llvm-ar --format=darwin rc bad.a input.bc 2>&1 | FileCheck %s --check-prefix=ERR1
 
 ## Malformed bitcode object if the symbol table is not required for big archive.
+## For big archives we print an error instead of a warning because the AIX linker
+## presumably requires the index.
----------------
jh7370 wrote:

@diggerlin, could you confirm that the big archive format does require the archive symbol index, please?

https://github.com/llvm/llvm-project/pull/96848


More information about the llvm-commits mailing list