[llvm] bc0725a - [Object] Improve ArchiveWriter diagnostics

Yi Kong via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 10 06:08:30 PDT 2022


Author: Yi Kong
Date: 2022-09-10T21:06:52+08:00
New Revision: bc0725a43763ff241f807e1de45d1a548aec89b8

URL: https://github.com/llvm/llvm-project/commit/bc0725a43763ff241f807e1de45d1a548aec89b8
DIFF: https://github.com/llvm/llvm-project/commit/bc0725a43763ff241f807e1de45d1a548aec89b8.diff

LOG: [Object] Improve ArchiveWriter diagnostics

Print out the archive member that failed, to make debugging easier.

Before:
  error: failed to build archive: Not an int attribute (Producer: 'LLVM15.0.1git' Reader: 'LLVM 14.0.5-rust-dev')
After:
  error: failed to build archive: 'fake_bt_keystore.o': Not an int attribute (Producer: 'LLVM15.0.1git' Reader: 'LLVM 14.0.5-rust-dev')

Differential Revision: https://reviews.llvm.org/D133607

Added: 
    

Modified: 
    llvm/lib/Object/ArchiveWriter.cpp
    llvm/test/Object/archive-malformed-object.test

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp
index dbf5052cdac06..0d3aad658fe43 100644
--- a/llvm/lib/Object/ArchiveWriter.cpp
+++ b/llvm/lib/Object/ArchiveWriter.cpp
@@ -598,8 +598,8 @@ computeMemberData(raw_ostream &StringTable, raw_ostream &SymNames,
     if (NeedSymbols) {
       Expected<std::vector<unsigned>> SymbolsOrErr =
           getSymbols(Buf, SymNames, HasObject);
-      if (auto E = SymbolsOrErr.takeError())
-        return std::move(E);
+      if (!SymbolsOrErr)
+        return createFileError(M.MemberName, SymbolsOrErr.takeError());
       Symbols = std::move(*SymbolsOrErr);
     }
 

diff  --git a/llvm/test/Object/archive-malformed-object.test b/llvm/test/Object/archive-malformed-object.test
index 7d502c3f301d6..b254dcbd029e2 100644
--- a/llvm/test/Object/archive-malformed-object.test
+++ b/llvm/test/Object/archive-malformed-object.test
@@ -10,13 +10,13 @@
 # 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
 
-# ERR1: error: bad.a: Invalid bitcode signature
+# ERR1: error: bad.a: 'input.bc': Invalid bitcode signature
 
 ## Non-bitcode malformed file.
 # RUN: yaml2obj input.yaml -o input.o
 # RUN: not llvm-ar rc bad.a input.o 2>&1 | FileCheck %s --check-prefix=ERR2
 
-# ERR2: error: bad.a: section header table goes past the end of the file: e_shoff = 0x9999
+# ERR2: error: bad.a: 'input.o': section header table goes past the end of the file: e_shoff = 0x9999
 
 ## Don't emit an error if the symbol table is not required.
 # RUN: llvm-ar rcS good.a input.o input.bc


        


More information about the llvm-commits mailing list