summaryrefslogtreecommitdiffstats
path: root/lld/wasm
diff options
context:
space:
mode:
Diffstat (limited to 'lld/wasm')
-rw-r--r--lld/wasm/InputFiles.cpp10
-rw-r--r--lld/wasm/LTO.cpp3
-rw-r--r--lld/wasm/MarkLive.cpp4
-rw-r--r--lld/wasm/Symbols.cpp10
-rw-r--r--lld/wasm/Symbols.h1
-rw-r--r--lld/wasm/Writer.cpp6
6 files changed, 24 insertions, 10 deletions
diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp
index ee9e99bd775..55392ccd34f 100644
--- a/lld/wasm/InputFiles.cpp
+++ b/lld/wasm/InputFiles.cpp
@@ -360,12 +360,18 @@ void ArchiveFile::addMember(const Archive::Symbol *Sym) {
"could not get the buffer for the member defining symbol " +
Sym->getName());
- if (identify_magic(MB.getBuffer()) != file_magic::wasm_object) {
+ InputFile *Obj;
+
+ file_magic Magic = identify_magic(MB.getBuffer());
+ if (Magic == file_magic::wasm_object) {
+ Obj = make<ObjFile>(MB);
+ } else if (Magic == file_magic::bitcode) {
+ Obj = make<BitcodeFile>(MB);
+ } else {
error("unknown file type: " + MB.getBufferIdentifier());
return;
}
- InputFile *Obj = make<ObjFile>(MB);
Obj->ParentName = ParentName;
Symtab->addFile(Obj);
}
diff --git a/lld/wasm/LTO.cpp b/lld/wasm/LTO.cpp
index 58f32aaf244..dd66c67e39f 100644
--- a/lld/wasm/LTO.cpp
+++ b/lld/wasm/LTO.cpp
@@ -95,7 +95,8 @@ void BitcodeCompiler::add(BitcodeFile &F) {
// Once IRObjectFile is fixed to report only one symbol this hack can
// be removed.
R.Prevailing = !ObjSym.isUndefined() && Sym->getFile() == &F;
- R.VisibleToRegularObj = Config->Relocatable || Sym->IsUsedInRegularObj;
+ R.VisibleToRegularObj = Config->Relocatable || Sym->IsUsedInRegularObj ||
+ (R.Prevailing && Sym->isExported());
if (R.Prevailing)
undefine(Sym);
}
diff --git a/lld/wasm/MarkLive.cpp b/lld/wasm/MarkLive.cpp
index 018b3255b55..dfaa712c329 100644
--- a/lld/wasm/MarkLive.cpp
+++ b/lld/wasm/MarkLive.cpp
@@ -54,9 +54,9 @@ void lld::wasm::markLive() {
Enqueue(Symtab->find(Config->Entry));
Enqueue(WasmSym::CallCtors);
- // We export all defined, non-hidden symbols so they are all gc roots too
+ // We need to preserve any exported symbol
for (Symbol *Sym : Symtab->getSymbols())
- if (Sym->isDefined() && !Sym->isHidden())
+ if (Sym->isExported())
Enqueue(Sym);
// The ctor functions are all used in the synthetic __wasm_call_ctors
diff --git a/lld/wasm/Symbols.cpp b/lld/wasm/Symbols.cpp
index 6b43eb36341..ef135b35b1a 100644
--- a/lld/wasm/Symbols.cpp
+++ b/lld/wasm/Symbols.cpp
@@ -98,6 +98,16 @@ void Symbol::setHidden(bool IsHidden) {
Flags |= WASM_SYMBOL_VISIBILITY_DEFAULT;
}
+bool Symbol::isExported() const {
+ if (!isDefined() || isLocal())
+ return false;
+
+ if (Config->ExportAll)
+ return true;
+
+ return !isHidden();
+}
+
uint32_t FunctionSymbol::getFunctionIndex() const {
if (auto *F = dyn_cast<DefinedFunction>(this))
return F->Function->getFunctionIndex();
diff --git a/lld/wasm/Symbols.h b/lld/wasm/Symbols.h
index a4d6e0bbf0f..794a65df673 100644
--- a/lld/wasm/Symbols.h
+++ b/lld/wasm/Symbols.h
@@ -90,6 +90,7 @@ public:
void setOutputSymbolIndex(uint32_t Index);
WasmSymbolType getWasmType() const;
+ bool isExported() const;
// True if this symbol was referenced by a regular (non-bitcode) object.
unsigned IsUsedInRegularObj : 1;
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index 41562e3c532..37ad32452a9 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -740,11 +740,7 @@ void Writer::calculateExports() {
unsigned FakeGlobalIndex = NumImportedGlobals + InputGlobals.size();
for (Symbol *Sym : Symtab->getSymbols()) {
- if (!Sym->isDefined())
- continue;
- if (Sym->isHidden() && !Config->ExportAll)
- continue;
- if (Sym->isLocal())
+ if (!Sym->isExported())
continue;
if (!Sym->isLive())
continue;
OpenPOWER on IntegriCloud