Index: lld/trunk/test/wasm/symbol-type-mismatch.ll =================================================================== --- lld/trunk/test/wasm/symbol-type-mismatch.ll +++ lld/trunk/test/wasm/symbol-type-mismatch.ll @@ -7,5 +7,5 @@ @ret32 = extern_weak global i32, align 4 ; CHECK: error: symbol type mismatch: ret32 -; CHECK: >>> defined as Global in {{.*}}symbol-type-mismatch.ll.tmp.o +; CHECK: >>> defined as Data in {{.*}}symbol-type-mismatch.ll.tmp.o ; CHECK: >>> defined as Function in {{.*}}.ret32.o Index: lld/trunk/wasm/Driver.cpp =================================================================== --- lld/trunk/wasm/Driver.cpp +++ lld/trunk/wasm/Driver.cpp @@ -301,10 +301,10 @@ // Add synthetic symbols before any others WasmSym::CallCtors = Symtab->addSyntheticFunction( "__wasm_call_ctors", &NullSignature, WASM_SYMBOL_VISIBILITY_HIDDEN); - WasmSym::StackPointer = Symtab->addSyntheticGlobal("__stack_pointer"); - WasmSym::HeapBase = Symtab->addSyntheticGlobal("__heap_base"); - WasmSym::DsoHandle = Symtab->addSyntheticGlobal("__dso_handle"); - WasmSym::DataEnd = Symtab->addSyntheticGlobal("__data_end"); + WasmSym::StackPointer = Symtab->addSyntheticDataSymbol("__stack_pointer"); + WasmSym::HeapBase = Symtab->addSyntheticDataSymbol("__heap_base"); + WasmSym::DsoHandle = Symtab->addSyntheticDataSymbol("__dso_handle"); + WasmSym::DataEnd = Symtab->addSyntheticDataSymbol("__data_end"); if (!Config->Entry.empty()) EntrySym = addUndefinedFunction(Config->Entry, &NullSignature); Index: lld/trunk/wasm/InputFiles.h =================================================================== --- lld/trunk/wasm/InputFiles.h +++ lld/trunk/wasm/InputFiles.h @@ -108,8 +108,8 @@ return cast(FunctionSymbols[Index]); } - GlobalSymbol *getGlobalSymbol(uint32_t Index) const { - return cast(GlobalSymbols[Index]); + DataSymbol *getDataSymbol(uint32_t Index) const { + return cast(DataSymbols[Index]); } private: @@ -118,8 +118,8 @@ uint32_t relocateGlobalIndex(uint32_t Original) const; uint32_t relocateTableIndex(uint32_t Original) const; - Symbol *createDefinedGlobal(const WasmSymbol &Sym, InputSegment *Segment, - uint32_t Address); + Symbol *createDefinedData(const WasmSymbol &Sym, InputSegment *Segment, + uint32_t Address); Symbol *createDefinedFunction(const WasmSymbol &Sym, InputFunction *Function); Symbol *createUndefined(const WasmSymbol &Sym, Symbol::Kind Kind, const WasmSignature *Signature = nullptr); @@ -137,7 +137,7 @@ std::vector FunctionSymbols; // List of all global symbols indexed by the global index space - std::vector GlobalSymbols; + std::vector DataSymbols; uint32_t NumGlobalImports = 0; uint32_t NumFunctionImports = 0; Index: lld/trunk/wasm/InputFiles.cpp =================================================================== --- lld/trunk/wasm/InputFiles.cpp +++ lld/trunk/wasm/InputFiles.cpp @@ -44,13 +44,13 @@ void ObjFile::dumpInfo() const { log("info for: " + getName() + "\n" + " Total Functions : " + Twine(FunctionSymbols.size()) + "\n" + - " Total Globals : " + Twine(GlobalSymbols.size()) + "\n" + + " Total Data Symbols : " + Twine(DataSymbols.size()) + "\n" + " Function Imports : " + Twine(NumFunctionImports) + "\n" + " Global Imports : " + Twine(NumGlobalImports) + "\n"); } uint32_t ObjFile::relocateVirtualAddress(uint32_t GlobalIndex) const { - if (auto *DG = dyn_cast(getGlobalSymbol(GlobalIndex))) + if (auto *DG = dyn_cast(getDataSymbol(GlobalIndex))) return DG->getVirtualAddress(); else return 0; @@ -78,7 +78,7 @@ } uint32_t ObjFile::relocateGlobalIndex(uint32_t Original) const { - const Symbol *Sym = getGlobalSymbol(Original); + const Symbol *Sym = getDataSymbol(Original); uint32_t Index = Sym->getOutputIndex(); DEBUG(dbgs() << "relocateGlobalIndex: " << toString(*Sym) << ": " << Original << " -> " << Index << "\n"); @@ -215,7 +215,7 @@ } FunctionSymbols.resize(NumFunctionImports + WasmObj->functions().size()); - GlobalSymbols.resize(NumGlobalImports + WasmObj->globals().size()); + DataSymbols.resize(NumGlobalImports + WasmObj->globals().size()); ArrayRef Funcs = WasmObj->functions(); ArrayRef FuncTypes = WasmObj->functionTypes(); @@ -226,7 +226,7 @@ Symtab->addComdat(C, this); FunctionSymbols.resize(NumFunctionImports + Funcs.size()); - GlobalSymbols.resize(NumGlobalImports + Globals.size()); + DataSymbols.resize(NumGlobalImports + Globals.size()); for (const WasmSegment &S : WasmObj->dataSegments()) { InputSegment *Seg = make(S, this); @@ -242,7 +242,7 @@ Functions.emplace_back(F); } - // Populate `FunctionSymbols` and `GlobalSymbols` based on the WasmSymbols + // Populate `FunctionSymbols` and `DataSymbols` based on the WasmSymbols // in the object for (const SymbolRef &Sym : WasmObj->symbols()) { const WasmSymbol &WasmSym = WasmObj->getWasmSymbol(Sym.getRawDataRefImpl()); @@ -264,14 +264,14 @@ case WasmSymbol::SymbolType::GLOBAL_EXPORT: { InputSegment *Segment = getSegment(WasmSym); if (!isExcludedByComdat(Segment)) { - S = createDefinedGlobal(WasmSym, Segment, getGlobalValue(WasmSym)); + S = createDefinedData(WasmSym, Segment, getGlobalValue(WasmSym)); break; } Segment->Live = false; LLVM_FALLTHROUGH; // Exclude global, and add the symbol as undefined } case WasmSymbol::SymbolType::GLOBAL_IMPORT: - S = createUndefined(WasmSym, Symbol::Kind::UndefinedGlobalKind); + S = createUndefined(WasmSym, Symbol::Kind::UndefinedDataKind); break; } @@ -281,19 +281,19 @@ if (WasmSym.HasAltIndex) FunctionSymbols[WasmSym.AltIndex] = S; } else { - GlobalSymbols[WasmSym.ElementIndex] = S; + DataSymbols[WasmSym.ElementIndex] = S; if (WasmSym.HasAltIndex) - GlobalSymbols[WasmSym.AltIndex] = S; + DataSymbols[WasmSym.AltIndex] = S; } } DEBUG(for (size_t I = 0; I < FunctionSymbols.size(); ++I) assert(FunctionSymbols[I] != nullptr); - for (size_t I = 0; I < GlobalSymbols.size(); ++I) - assert(GlobalSymbols[I] != nullptr);); + for (size_t I = 0; I < DataSymbols.size(); ++I) + assert(DataSymbols[I] != nullptr);); DEBUG(dbgs() << "Functions : " << FunctionSymbols.size() << "\n"); - DEBUG(dbgs() << "Globals : " << GlobalSymbols.size() << "\n"); + DEBUG(dbgs() << "Globals : " << DataSymbols.size() << "\n"); } Symbol *ObjFile::createUndefined(const WasmSymbol &Sym, Symbol::Kind Kind, @@ -308,11 +308,11 @@ return Symtab->addDefinedFunction(Sym.Name, Sym.Flags, this, Function); } -Symbol *ObjFile::createDefinedGlobal(const WasmSymbol &Sym, - InputSegment *Segment, uint32_t Address) { +Symbol *ObjFile::createDefinedData(const WasmSymbol &Sym, InputSegment *Segment, + uint32_t Address) { if (Sym.isBindingLocal()) - return make(Sym.Name, Sym.Flags, this, Segment, Address); - return Symtab->addDefinedGlobal(Sym.Name, Sym.Flags, this, Segment, Address); + return make(Sym.Name, Sym.Flags, this, Segment, Address); + return Symtab->addDefinedData(Sym.Name, Sym.Flags, this, Segment, Address); } void ArchiveFile::parse() { Index: lld/trunk/wasm/MarkLive.cpp =================================================================== --- lld/trunk/wasm/MarkLive.cpp +++ lld/trunk/wasm/MarkLive.cpp @@ -83,7 +83,7 @@ case R_WEBASSEMBLY_MEMORY_ADDR_LEB: case R_WEBASSEMBLY_MEMORY_ADDR_SLEB: case R_WEBASSEMBLY_MEMORY_ADDR_I32: - Enqueue(C->File->getGlobalSymbol(Reloc.Index)); + Enqueue(C->File->getDataSymbol(Reloc.Index)); break; } } Index: lld/trunk/wasm/SymbolTable.h =================================================================== --- lld/trunk/wasm/SymbolTable.h +++ lld/trunk/wasm/SymbolTable.h @@ -49,16 +49,15 @@ Symbol *addDefinedFunction(StringRef Name, uint32_t Flags, InputFile *F, InputFunction *Function = nullptr); - Symbol *addDefinedGlobal(StringRef Name, uint32_t Flags, InputFile *F, - InputSegment *Segment = nullptr, - uint32_t Address = 0); + Symbol *addDefinedData(StringRef Name, uint32_t Flags, InputFile *F, + InputSegment *Segment = nullptr, uint32_t Address = 0); Symbol *addUndefined(StringRef Name, Symbol::Kind Kind, uint32_t Flags, InputFile *F, const WasmSignature *Signature = nullptr); Symbol *addUndefinedFunction(StringRef Name, const WasmSignature *Type); void addLazy(ArchiveFile *F, const Archive::Symbol *Sym); bool addComdat(StringRef Name, ObjFile *); - DefinedGlobal *addSyntheticGlobal(StringRef Name, uint32_t Flags = 0); + DefinedData *addSyntheticDataSymbol(StringRef Name, uint32_t Flags = 0); DefinedFunction *addSyntheticFunction(StringRef Name, const WasmSignature *Type, uint32_t Flags = 0); Index: lld/trunk/wasm/SymbolTable.cpp =================================================================== --- lld/trunk/wasm/SymbolTable.cpp +++ lld/trunk/wasm/SymbolTable.cpp @@ -81,9 +81,9 @@ // symbols or both are data symbols). if (isa(Existing) != NewIsFunction) { error("symbol type mismatch: " + Existing.getName() + "\n>>> defined as " + - (isa(Existing) ? "Function" : "Global") + " in " + + (isa(Existing) ? "Function" : "Data") + " in " + toString(Existing.getFile()) + "\n>>> defined as " + - (NewIsFunction ? "Function" : "Global") + " in " + F.getName()); + (NewIsFunction ? "Function" : "Data") + " in " + F.getName()); return; } @@ -130,13 +130,14 @@ return replaceSymbol(S, Name, Flags, Type); } -DefinedGlobal *SymbolTable::addSyntheticGlobal(StringRef Name, uint32_t Flags) { - DEBUG(dbgs() << "addSyntheticGlobal: " << Name << "\n"); +DefinedData *SymbolTable::addSyntheticDataSymbol(StringRef Name, + uint32_t Flags) { + DEBUG(dbgs() << "addSyntheticDataSymbol: " << Name << "\n"); Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name); assert(WasInserted); - return replaceSymbol(S, Name, Flags); + return replaceSymbol(S, Name, Flags); } static bool shouldReplace(const Symbol &Existing, InputFile *NewFile, @@ -192,15 +193,15 @@ return S; } -Symbol *SymbolTable::addDefinedGlobal(StringRef Name, uint32_t Flags, +Symbol *SymbolTable::addDefinedData(StringRef Name, uint32_t Flags, InputFile *F, InputSegment *Segment, uint32_t Address) { - DEBUG(dbgs() << "addDefinedGlobal:" << Name << " addr:" << Address << "\n"); + DEBUG(dbgs() << "addDefinedData:" << Name << " addr:" << Address << "\n"); Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name); if (WasInserted || shouldReplace(*S, F, Flags, Segment, false)) - replaceSymbol(S, Name, Flags, F, Segment, Address); + replaceSymbol(S, Name, Flags, F, Segment, Address); return S; } @@ -218,7 +219,7 @@ if (IsFunction) replaceSymbol(S, Name, Flags, F, Type); else - replaceSymbol(S, Name, Flags, F); + replaceSymbol(S, Name, Flags, F); return S; } Index: lld/trunk/wasm/Symbols.h =================================================================== --- lld/trunk/wasm/Symbols.h +++ lld/trunk/wasm/Symbols.h @@ -32,13 +32,13 @@ public: enum Kind { DefinedFunctionKind, - DefinedGlobalKind, + DefinedDataKind, LazyKind, UndefinedFunctionKind, - UndefinedGlobalKind, + UndefinedDataKind, - LastDefinedKind = DefinedGlobalKind, + LastDefinedKind = DefinedDataKind, InvalidKind, }; @@ -47,7 +47,7 @@ bool isLazy() const { return SymbolKind == LazyKind; } bool isDefined() const { return SymbolKind <= LastDefinedKind; } bool isUndefined() const { - return SymbolKind == UndefinedGlobalKind || + return SymbolKind == UndefinedDataKind || SymbolKind == UndefinedFunctionKind; } bool isLocal() const; @@ -136,26 +136,26 @@ } }; -class GlobalSymbol : public Symbol { +class DataSymbol : public Symbol { public: static bool classof(const Symbol *S) { - return S->kind() == DefinedGlobalKind || S->kind() == UndefinedGlobalKind; + return S->kind() == DefinedDataKind || S->kind() == UndefinedDataKind; } protected: - GlobalSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F) + DataSymbol(StringRef Name, Kind K, uint32_t Flags, InputFile *F) : Symbol(Name, K, Flags, F) {} }; -class DefinedGlobal : public GlobalSymbol { +class DefinedData : public DataSymbol { public: - DefinedGlobal(StringRef Name, uint32_t Flags, InputFile *F = nullptr, - InputSegment *Segment = nullptr, uint32_t Address = 0) - : GlobalSymbol(Name, DefinedGlobalKind, Flags, F), Segment(Segment), + DefinedData(StringRef Name, uint32_t Flags, InputFile *F = nullptr, + InputSegment *Segment = nullptr, uint32_t Address = 0) + : DataSymbol(Name, DefinedDataKind, Flags, F), Segment(Segment), VirtualAddress(Address) {} static bool classof(const Symbol *S) { - return S->kind() == DefinedGlobalKind; + return S->kind() == DefinedDataKind; } uint32_t getVirtualAddress() const; @@ -167,12 +167,12 @@ uint32_t VirtualAddress; }; -class UndefinedGlobal : public GlobalSymbol { +class UndefinedData : public DataSymbol { public: - UndefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File = nullptr) - : GlobalSymbol(Name, UndefinedGlobalKind, Flags, File) {} + UndefinedData(StringRef Name, uint32_t Flags, InputFile *File = nullptr) + : DataSymbol(Name, UndefinedDataKind, Flags, File) {} static bool classof(const Symbol *S) { - return S->kind() == UndefinedGlobalKind; + return S->kind() == UndefinedDataKind; } }; @@ -194,25 +194,25 @@ // __stack_pointer // Global that holds the address of the top of the explicit value stack in // linear memory. - static DefinedGlobal *StackPointer; + static DefinedData *StackPointer; // __data_end // Symbol marking the end of the data and bss. - static DefinedGlobal *DataEnd; + static DefinedData *DataEnd; // __heap_base // Symbol marking the end of the data, bss and explicit stack. Any linear // memory following this address is not used by the linked code and can // therefore be used as a backing store for brk()/malloc() implementations. - static DefinedGlobal *HeapBase; + static DefinedData *HeapBase; // __wasm_call_ctors // Function that directly calls all ctors in priority order. static DefinedFunction *CallCtors; // __dso_handle - // Global used in calls to __cxa_atexit to determine current DLL - static DefinedGlobal *DsoHandle; + // Symbol used in calls to __cxa_atexit to determine current DLL + static DefinedData *DsoHandle; }; // A buffer class that is large enough to hold any Symbol-derived @@ -220,10 +220,10 @@ // using the placement new. union SymbolUnion { alignas(DefinedFunction) char A[sizeof(DefinedFunction)]; - alignas(DefinedGlobal) char B[sizeof(DefinedGlobal)]; + alignas(DefinedData) char B[sizeof(DefinedData)]; alignas(LazySymbol) char C[sizeof(LazySymbol)]; alignas(UndefinedFunction) char D[sizeof(UndefinedFunction)]; - alignas(UndefinedGlobal) char E[sizeof(UndefinedFunction)]; + alignas(UndefinedData) char E[sizeof(UndefinedFunction)]; }; template Index: lld/trunk/wasm/Symbols.cpp =================================================================== --- lld/trunk/wasm/Symbols.cpp +++ lld/trunk/wasm/Symbols.cpp @@ -22,10 +22,10 @@ using namespace lld::wasm; DefinedFunction *WasmSym::CallCtors; -DefinedGlobal *WasmSym::DsoHandle; -DefinedGlobal *WasmSym::DataEnd; -DefinedGlobal *WasmSym::HeapBase; -DefinedGlobal *WasmSym::StackPointer; +DefinedData *WasmSym::DsoHandle; +DefinedData *WasmSym::DataEnd; +DefinedData *WasmSym::HeapBase; +DefinedData *WasmSym::StackPointer; bool Symbol::hasOutputIndex() const { if (auto *F = dyn_cast(this)) @@ -45,7 +45,7 @@ InputChunk *Symbol::getChunk() const { if (auto *F = dyn_cast(this)) return F->Function; - if (auto *G = dyn_cast(this)) + if (auto *G = dyn_cast(this)) return G->Segment; return nullptr; } @@ -109,12 +109,12 @@ Function ? &Function->Signature : nullptr), Function(Function) {} -uint32_t DefinedGlobal::getVirtualAddress() const { +uint32_t DefinedData::getVirtualAddress() const { DEBUG(dbgs() << "getVirtualAddress: " << getName() << "\n"); return Segment ? Segment->translateVA(VirtualAddress) : VirtualAddress; } -void DefinedGlobal::setVirtualAddress(uint32_t Value) { +void DefinedData::setVirtualAddress(uint32_t Value) { DEBUG(dbgs() << "setVirtualAddress " << Name << " -> " << Value << "\n"); VirtualAddress = Value; } @@ -130,12 +130,12 @@ switch (Kind) { case wasm::Symbol::DefinedFunctionKind: return "DefinedFunction"; - case wasm::Symbol::DefinedGlobalKind: - return "DefinedGlobal"; + case wasm::Symbol::DefinedDataKind: + return "DefinedData"; case wasm::Symbol::UndefinedFunctionKind: return "UndefinedFunction"; - case wasm::Symbol::UndefinedGlobalKind: - return "UndefinedGlobal"; + case wasm::Symbol::UndefinedDataKind: + return "UndefinedData"; case wasm::Symbol::LazyKind: return "LazyKind"; } Index: lld/trunk/wasm/Writer.cpp =================================================================== --- lld/trunk/wasm/Writer.cpp +++ lld/trunk/wasm/Writer.cpp @@ -119,9 +119,9 @@ std::vector Types; DenseMap TypeIndices; std::vector ImportedFunctions; - std::vector ImportedGlobals; + std::vector ImportedGlobals; std::vector ExportedSymbols; - std::vector DefinedGlobals; + std::vector DefinedDataSymbols; std::vector DefinedFunctions; std::vector IndirectFunctions; std::vector InitFunctions; @@ -226,14 +226,14 @@ } void Writer::createGlobalSection() { - if (DefinedGlobals.empty()) + if (DefinedDataSymbols.empty()) return; SyntheticSection *Section = createSyntheticSection(WASM_SEC_GLOBAL); raw_ostream &OS = Section->getStream(); - writeUleb128(OS, DefinedGlobals.size(), "global count"); - for (const DefinedGlobal *Sym : DefinedGlobals) { + writeUleb128(OS, DefinedDataSymbols.size(), "global count"); + for (const DefinedData *Sym : DefinedDataSymbols) { WasmGlobal Global; Global.Type.Type = WASM_TYPE_I32; Global.Type.Mutable = Sym == WasmSym::StackPointer; @@ -621,7 +621,7 @@ if (auto *F = dyn_cast(Sym)) { F->setOutputIndex(ImportedFunctions.size()); ImportedFunctions.push_back(F); - } else if (auto *G = dyn_cast(Sym)) { + } else if (auto *G = dyn_cast(Sym)) { G->setOutputIndex(ImportedGlobals.size()); ImportedGlobals.push_back(G); } @@ -659,7 +659,7 @@ for (Symbol *Sym : File->getSymbols()) { if (!Sym->isDefined() || File != Sym->getFile()) continue; - if (isa(Sym)) + if (!isa(Sym)) continue; if (!Sym->getChunk()->Live) continue; @@ -670,7 +670,7 @@ } } - for (const Symbol *Sym : DefinedGlobals) { + for (const Symbol *Sym : DefinedDataSymbols) { // Can't export the SP right now because its mutable, and mutuable globals // are yet supported in the official binary format. // TODO(sbc): Remove this if/when the "mutable global" proposal is accepted. @@ -719,21 +719,21 @@ } void Writer::assignIndexes() { - uint32_t GlobalIndex = ImportedGlobals.size() + DefinedGlobals.size(); + uint32_t GlobalIndex = ImportedGlobals.size() + DefinedDataSymbols.size(); uint32_t FunctionIndex = ImportedFunctions.size() + DefinedFunctions.size(); - auto AddDefinedGlobal = [&](DefinedGlobal *Sym) { + auto AddDefinedData = [&](DefinedData *Sym) { if (Sym) { - DefinedGlobals.emplace_back(Sym); + DefinedDataSymbols.emplace_back(Sym); Sym->setOutputIndex(GlobalIndex++); } }; - AddDefinedGlobal(WasmSym::StackPointer); - AddDefinedGlobal(WasmSym::HeapBase); - AddDefinedGlobal(WasmSym::DataEnd); + AddDefinedData(WasmSym::StackPointer); + AddDefinedData(WasmSym::HeapBase); + AddDefinedData(WasmSym::DataEnd); if (Config->Relocatable) - DefinedGlobals.reserve(Symtab->getSymbols().size()); + DefinedDataSymbols.reserve(Symtab->getSymbols().size()); uint32_t TableIndex = kInitialTableOffset; @@ -744,8 +744,8 @@ // Create wasm globals for data symbols defined in this file if (File != Sym->getFile()) continue; - if (auto *G = dyn_cast(Sym)) - AddDefinedGlobal(G); + if (auto *G = dyn_cast(Sym)) + AddDefinedData(G); } } } @@ -893,7 +893,7 @@ if (errorHandler().Verbose) { log("Defined Functions: " + Twine(DefinedFunctions.size())); - log("Defined Globals : " + Twine(DefinedGlobals.size())); + log("Defined Data Syms: " + Twine(DefinedDataSymbols.size())); log("Function Imports : " + Twine(ImportedFunctions.size())); log("Global Imports : " + Twine(ImportedGlobals.size())); log("Total Imports : " +