Skip to content

[lld][WebAssembly] Fix use of undefined funcs under --warn-unresolved-symbols #78643

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
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions lld/test/wasm/unresolved-symbols.s
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
# RUN: FileCheck -check-prefix=ERR1 %s

## Ignore all should not produce error and should not produce
# any imports. It should create a stub function in the place of the missing
# function symbol.
## any imports. It should create a stub function in the place of the missing
## function symbol.
# RUN: wasm-ld %t1.o -o %t2.wasm --unresolved-symbols=ignore-all
# RUN: obj2yaml %t2.wasm | FileCheck -check-prefix=IGNORE %s

## --warn-unresolved-symbols should behave the same
# RUN: wasm-ld %t1.o -o %t2.wasm --warn-unresolved-symbols
# RUN: obj2yaml %t2.wasm | FileCheck -check-prefix=IGNORE %s

# IGNORE-NOT: - Type: IMPORT
# IGNORE-NOT: - Type: ELEM
#
Expand Down Expand Up @@ -52,10 +57,10 @@
# IGNORE-NEXT: - Index: 3
# IGNORE-NEXT: Name: get_func_addr

## --import-undefined should handle unresolved funtions symbols
# by importing them but still report errors/warning for missing data symbols.
# `--allow-undefined` should behave like `--import-undefined` +
# `--unresolve-symbols=ignore`
## --import-undefined should handle unresolved functions symbols
## by importing them but still report errors/warning for missing data symbols.
## `--allow-undefined` should behave like `--import-undefined` +
## `--unresolve-symbols=ignore`
# RUN: wasm-ld %t1.o -o %t3.wasm --import-undefined --unresolved-symbols=ignore-all
# RUN: obj2yaml %t3.wasm | FileCheck -check-prefix=IMPORT %s
# IMPORT: - Type: IMPORT
Expand Down
23 changes: 12 additions & 11 deletions lld/wasm/Relocations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,22 @@ static void reportUndefined(Symbol *sym) {
case UnresolvedPolicy::Ignore:
LLVM_DEBUG(dbgs() << "ignoring undefined symbol: " + toString(*sym) +
"\n");
if (!config->importUndefined) {
if (auto *f = dyn_cast<UndefinedFunction>(sym)) {
if (!f->stubFunction) {
f->stubFunction = symtab->createUndefinedStub(*f->getSignature());
f->stubFunction->markLive();
// Mark the function itself as a stub which prevents it from being
// assigned a table entry.
f->isStub = true;
}
}
}
break;
case UnresolvedPolicy::ImportDynamic:
break;
}

if (auto *f = dyn_cast<UndefinedFunction>(sym)) {
if (!f->stubFunction &&
config->unresolvedSymbols != UnresolvedPolicy::ImportDynamic &&
!config->importUndefined) {
f->stubFunction = symtab->createUndefinedStub(*f->getSignature());
f->stubFunction->markLive();
// Mark the function itself as a stub which prevents it from being
// assigned a table entry.
f->isStub = true;
}
}
}
}

Expand Down