summaryrefslogtreecommitdiffstats
path: root/lld/wasm/Driver.cpp
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2019-02-20 23:19:31 +0000
committerSam Clegg <sbc@chromium.org>2019-02-20 23:19:31 +0000
commit6540e5700297b09269f2d3db61ad6487ee5f9030 (patch)
tree3195ac11eeb9660014056b5f57730b4cdff88850 /lld/wasm/Driver.cpp
parent2d13dcacfb98881348bbe11920145edbb27d8166 (diff)
downloadbcm5719-llvm-6540e5700297b09269f2d3db61ad6487ee5f9030.tar.gz
bcm5719-llvm-6540e5700297b09269f2d3db61ad6487ee5f9030.zip
[WebAssembly] Don't generate invalid modules when function signatures mismatch
Previously we could emit a warning and generate a potentially invalid wasm module (due to call sites and functions having conflicting signatures). Now, rather than create invalid binaries we handle such cases by creating stub functions containing unreachable, effectively turning these into runtime errors rather than validation failures. Differential Revision: https://reviews.llvm.org/D57909 llvm-svn: 354528
Diffstat (limited to 'lld/wasm/Driver.cpp')
-rw-r--r--lld/wasm/Driver.cpp46
1 files changed, 28 insertions, 18 deletions
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 40e88f2ac2a..d3286af258b 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -534,17 +534,6 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
for (auto *Arg : Args.filtered(OPT_undefined))
handleUndefined(Arg->getValue());
- // Handle the `--export <sym>` options
- // This works like --undefined but also exports the symbol if its found
- for (auto *Arg : Args.filtered(OPT_export)) {
- Symbol *Sym = handleUndefined(Arg->getValue());
- if (Sym && Sym->isDefined())
- Sym->ForceExport = true;
- else if (!Config->AllowUndefined)
- error(Twine("symbol exported via --export not found: ") +
- Arg->getValue());
- }
-
Symbol *EntrySym = nullptr;
if (!Config->Relocatable) {
if (!Config->Shared && !Config->Entry.empty()) {
@@ -555,26 +544,47 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
error("entry symbol not defined (pass --no-entry to supress): " +
Config->Entry);
}
-
- // Make sure we have resolved all symbols.
- if (!Config->AllowUndefined)
- Symtab->reportRemainingUndefines();
}
if (errorCount())
return;
+ // Handle the `--export <sym>` options
+ // This works like --undefined but also exports the symbol if its found
+ for (auto *Arg : Args.filtered(OPT_export))
+ handleUndefined(Arg->getValue());
+
// Do link-time optimization if given files are LLVM bitcode files.
// This compiles bitcode files into real object files.
Symtab->addCombinedLTOObject();
if (errorCount())
return;
- // Add synthetic dummies for weak undefined functions. Must happen
- // after LTO otherwise functions may not yet have signatures.
- if (!Config->Relocatable)
+ // Resolve any variant symbols that were created due to signature
+ // mismatchs.
+ Symtab->handleSymbolVariants();
+ if (errorCount())
+ return;
+
+ for (auto *Arg : Args.filtered(OPT_export)) {
+ Symbol *Sym = Symtab->find(Arg->getValue());
+ if (Sym && Sym->isDefined())
+ Sym->ForceExport = true;
+ else if (!Config->AllowUndefined)
+ error(Twine("symbol exported via --export not found: ") +
+ Arg->getValue());
+ }
+
+ if (!Config->Relocatable) {
+ // Add synthetic dummies for weak undefined functions. Must happen
+ // after LTO otherwise functions may not yet have signatures.
Symtab->handleWeakUndefines();
+ // Make sure we have resolved all symbols.
+ if (!Config->AllowUndefined)
+ Symtab->reportRemainingUndefines();
+ }
+
if (EntrySym)
EntrySym->setHidden(false);
OpenPOWER on IntegriCloud