Skip to content

[lld][WebAssembly] Improve error message on adding LTO object post-LTO. NFC #66688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2023

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Sep 18, 2023

We have been getting errors from emscripten users where including the name of the symbol that triggered the inclusion would be useful in the diagnosis. e.g:
emscripten-core/emscripten#20275

…O. NFC

We have been getting errors from emscripten users where including
the name of the symbol that triggered the inclusion would be useful
in the diagnosis. e.g:
emscripten-core/emscripten#20275
@llvmbot
Copy link
Member

llvmbot commented Sep 18, 2023

@llvm/pr-subscribers-lld

@llvm/pr-subscribers-lld-wasm

Changes

We have been getting errors from emscripten users where including the name of the symbol that triggered the inclusion would be useful in the diagnosis. e.g:
emscripten-core/emscripten#20275


Full diff: https://github.com/llvm/llvm-project/pull/66688.diff

5 Files Affected:

  • (modified) lld/test/wasm/lto/libcall-truncsfhf2.ll (+1-1)
  • (modified) lld/wasm/InputFiles.cpp (+3-3)
  • (modified) lld/wasm/InputFiles.h (+1-1)
  • (modified) lld/wasm/SymbolTable.cpp (+2-2)
  • (modified) lld/wasm/SymbolTable.h (+1-1)
diff --git a/lld/test/wasm/lto/libcall-truncsfhf2.ll b/lld/test/wasm/lto/libcall-truncsfhf2.ll
index 1eea2b28b6db1d8..08b334ace9ba30c 100644
--- a/lld/test/wasm/lto/libcall-truncsfhf2.ll
+++ b/lld/test/wasm/lto/libcall-truncsfhf2.ll
@@ -17,4 +17,4 @@ define void @_start() {
   ret void
 }
 
-; CHECK: wasm-ld: error: {{.*}}truncsfhf2.o): attempt to add bitcode file after LTO.
+; CHECK: wasm-ld: error: {{.*}}truncsfhf2.o): attempt to add bitcode file after LTO (__truncsfhf2)
diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp
index fa20a35ded9d9e6..96ac1e1610dd3b0 100644
--- a/lld/wasm/InputFiles.cpp
+++ b/lld/wasm/InputFiles.cpp
@@ -760,7 +760,7 @@ void ArchiveFile::addMember(const Archive::Symbol *sym) {
                 sym->getName());
 
   InputFile *obj = createObjectFile(mb, getName(), c.getChildOffset());
-  symtab->addFile(obj);
+  symtab->addFile(obj, sym->getName());
 }
 
 static uint8_t mapVisibility(GlobalValue::VisibilityTypes gvVisibility) {
@@ -826,9 +826,9 @@ BitcodeFile::BitcodeFile(MemoryBufferRef m, StringRef archiveName,
 
 bool BitcodeFile::doneLTO = false;
 
-void BitcodeFile::parse() {
+void BitcodeFile::parse(StringRef symName) {
   if (doneLTO) {
-    error(toString(this) + ": attempt to add bitcode file after LTO.");
+    error(toString(this) + ": attempt to add bitcode file after LTO (" + symName + ")");
     return;
   }
 
diff --git a/lld/wasm/InputFiles.h b/lld/wasm/InputFiles.h
index 327813484eafd3a..d9a8b5306603249 100644
--- a/lld/wasm/InputFiles.h
+++ b/lld/wasm/InputFiles.h
@@ -176,7 +176,7 @@ class BitcodeFile : public InputFile {
               uint64_t offsetInArchive);
   static bool classof(const InputFile *f) { return f->kind() == BitcodeKind; }
 
-  void parse();
+  void parse(StringRef symName);
   std::unique_ptr<llvm::lto::InputFile> obj;
 
   // Set to true once LTO is complete in order prevent further bitcode objects
diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp
index d33176a0fa54ad6..9a381e95f3d9fa5 100644
--- a/lld/wasm/SymbolTable.cpp
+++ b/lld/wasm/SymbolTable.cpp
@@ -23,7 +23,7 @@ using namespace llvm::object;
 namespace lld::wasm {
 SymbolTable *symtab;
 
-void SymbolTable::addFile(InputFile *file) {
+void SymbolTable::addFile(InputFile *file, StringRef symName) {
   log("Processing: " + toString(file));
 
   // .a file
@@ -50,7 +50,7 @@ void SymbolTable::addFile(InputFile *file) {
 
   // LLVM bitcode file
   if (auto *f = dyn_cast<BitcodeFile>(file)) {
-    f->parse();
+    f->parse(symName);
     bitcodeFiles.push_back(f);
     return;
   }
diff --git a/lld/wasm/SymbolTable.h b/lld/wasm/SymbolTable.h
index ef2a023b68c44d8..59eda1c0b6740c2 100644
--- a/lld/wasm/SymbolTable.h
+++ b/lld/wasm/SymbolTable.h
@@ -40,7 +40,7 @@ class SymbolTable {
 
   void wrap(Symbol *sym, Symbol *real, Symbol *wrap);
 
-  void addFile(InputFile *file);
+  void addFile(InputFile *file, StringRef symName = {});
 
   void compileBitcodeFiles();
 

@sbc100 sbc100 merged commit 7bac0bc into llvm:main Sep 18, 2023
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
…O. NFC (llvm#66688)

We have been getting errors from emscripten users where including the
name of the symbol that triggered the inclusion would be useful in the
diagnosis. e.g:
emscripten-core/emscripten#20275
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants