Skip to content

Commit 7bac0bc

Browse files
authored
[lld][WebAssembly] Improve error message on adding LTO object post-LTO. NFC (#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
1 parent e2a9d3f commit 7bac0bc

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

lld/test/wasm/lto/libcall-truncsfhf2.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ define void @_start() {
1717
ret void
1818
}
1919

20-
; CHECK: wasm-ld: error: {{.*}}truncsfhf2.o): attempt to add bitcode file after LTO.
20+
; CHECK: wasm-ld: error: {{.*}}truncsfhf2.o): attempt to add bitcode file after LTO (__truncsfhf2)

lld/wasm/InputFiles.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ void ArchiveFile::addMember(const Archive::Symbol *sym) {
760760
sym->getName());
761761

762762
InputFile *obj = createObjectFile(mb, getName(), c.getChildOffset());
763-
symtab->addFile(obj);
763+
symtab->addFile(obj, sym->getName());
764764
}
765765

766766
static uint8_t mapVisibility(GlobalValue::VisibilityTypes gvVisibility) {
@@ -826,9 +826,9 @@ BitcodeFile::BitcodeFile(MemoryBufferRef m, StringRef archiveName,
826826

827827
bool BitcodeFile::doneLTO = false;
828828

829-
void BitcodeFile::parse() {
829+
void BitcodeFile::parse(StringRef symName) {
830830
if (doneLTO) {
831-
error(toString(this) + ": attempt to add bitcode file after LTO.");
831+
error(toString(this) + ": attempt to add bitcode file after LTO (" + symName + ")");
832832
return;
833833
}
834834

lld/wasm/InputFiles.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class BitcodeFile : public InputFile {
176176
uint64_t offsetInArchive);
177177
static bool classof(const InputFile *f) { return f->kind() == BitcodeKind; }
178178

179-
void parse();
179+
void parse(StringRef symName);
180180
std::unique_ptr<llvm::lto::InputFile> obj;
181181

182182
// Set to true once LTO is complete in order prevent further bitcode objects

lld/wasm/SymbolTable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using namespace llvm::object;
2323
namespace lld::wasm {
2424
SymbolTable *symtab;
2525

26-
void SymbolTable::addFile(InputFile *file) {
26+
void SymbolTable::addFile(InputFile *file, StringRef symName) {
2727
log("Processing: " + toString(file));
2828

2929
// .a file
@@ -50,7 +50,7 @@ void SymbolTable::addFile(InputFile *file) {
5050

5151
// LLVM bitcode file
5252
if (auto *f = dyn_cast<BitcodeFile>(file)) {
53-
f->parse();
53+
f->parse(symName);
5454
bitcodeFiles.push_back(f);
5555
return;
5656
}

lld/wasm/SymbolTable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SymbolTable {
4040

4141
void wrap(Symbol *sym, Symbol *real, Symbol *wrap);
4242

43-
void addFile(InputFile *file);
43+
void addFile(InputFile *file, StringRef symName = {});
4444

4545
void compileBitcodeFiles();
4646

0 commit comments

Comments
 (0)