Index: wasm/Driver.cpp =================================================================== --- wasm/Driver.cpp +++ wasm/Driver.cpp @@ -184,7 +184,7 @@ // Inject a new wasm global into the output binary with the given value. // Wasm global are used in relocatable object files to model symbol imports -// and exports. In the final exectuable the only use of wasm globals is the +// and exports. In the final executable the only use of wasm globals is // for the exlicit stack pointer (__stack_pointer). static void addSyntheticGlobal(StringRef Name, int32_t Value) { log("injecting global: " + Name); Index: wasm/SymbolTable.cpp =================================================================== --- wasm/SymbolTable.cpp +++ wasm/SymbolTable.cpp @@ -128,14 +128,14 @@ S->update(Kind, F, Sym, Segment); } else if (Sym->isWeak()) { // the new symbol is weak we can ignore it - DEBUG(dbgs() << "existing symbol takes precensence\n"); + DEBUG(dbgs() << "existing symbol takes precedence\n"); } else if (S->isWeak()) { // the new symbol is not weak and the existing symbol is, so we replace // it DEBUG(dbgs() << "replacing existing weak symbol\n"); S->update(Kind, F, Sym, Segment); } else { - // niether symbol is week. They conflict. + // neither symbol is week. They conflict. reportDuplicate(S, F); } return S; Index: wasm/Symbols.h =================================================================== --- wasm/Symbols.h +++ wasm/Symbols.h @@ -57,6 +57,7 @@ bool isGlobal() const { return !isFunction(); } bool isLocal() const { return IsLocal; } bool isWeak() const; + bool isHidden() const; // Returns the symbol name. StringRef getName() const { return Name; } Index: wasm/Symbols.cpp =================================================================== --- wasm/Symbols.cpp +++ wasm/Symbols.cpp @@ -83,6 +83,8 @@ bool Symbol::isWeak() const { return Sym && Sym->isWeak(); } +bool Symbol::isHidden() const { return Sym && Sym->isHidden(); } + std::string lld::toString(wasm::Symbol &Sym) { return wasm::displayName(Sym.getName()); } Index: wasm/Writer.cpp =================================================================== --- wasm/Writer.cpp +++ wasm/Writer.cpp @@ -267,7 +267,8 @@ // Memory is and main function are exported for executables. bool ExportMemory = !Config->Relocatable && !Config->ImportMemory; bool ExportMain = !Config->Relocatable; - bool ExportOther = true; // Config->Relocatable; + bool ExportOther = true; // ??? TODO Config->Relocatable; + bool ExportHidden = Config->Relocatable; uint32_t NumExports = 0; @@ -281,7 +282,7 @@ for (ObjFile *File : Symtab->ObjectFiles) { for (Symbol *Sym : File->getSymbols()) { if (!Sym->isFunction() || Sym->isLocal() || Sym->isUndefined() || - Sym->WrittenToSymtab) + (Sym->isHidden() && !ExportHidden) || Sym->WrittenToSymtab) continue; Sym->WrittenToSymtab = true; ++NumExports; @@ -324,8 +325,8 @@ if (ExportOther) { for (ObjFile *File : Symtab->ObjectFiles) { for (Symbol *Sym : File->getSymbols()) { - if (!Sym->isFunction() || Sym->isLocal() | Sym->isUndefined() || - !Sym->WrittenToSymtab) + if (!Sym->isFunction() || Sym->isLocal() || Sym->isUndefined() || + (Sym->isHidden() && !ExportHidden) || !Sym->WrittenToSymtab) continue; Sym->WrittenToSymtab = false; log("Export: " + Sym->getName()); @@ -339,9 +340,6 @@ writeExport(OS, Export); } } - - // TODO(sbc): Export local symbols too, Even though they are not part - // of the symbol table? } } @@ -416,7 +414,7 @@ } } -// Create the custome "linking" section containing linker metadata. +// Create the custom "linking" section containing linker metadata. // This is only created when relocatable output is requested. void Writer::createLinkingSection() { SyntheticSection *Section = @@ -487,7 +485,7 @@ } // Fix the memory layout of the output binary. This assigns memory offsets -// to each of the intput data sections as well as the explicit stack region. +// to each of the input data sections as well as the explicit stack region. void Writer::layoutMemory() { uint32_t MemoryPtr = 0; if (!Config->Relocatable) {