Index: llvm/trunk/include/llvm/BinaryFormat/Wasm.h =================================================================== --- llvm/trunk/include/llvm/BinaryFormat/Wasm.h +++ llvm/trunk/include/llvm/BinaryFormat/Wasm.h @@ -74,6 +74,7 @@ uint32_t Index; WasmGlobalType Type; WasmInitExpr InitExpr; + StringRef Name; // from the "linking" or "names" section }; struct WasmImport { @@ -99,7 +100,7 @@ ArrayRef Body; uint32_t CodeSectionOffset; uint32_t Size; - StringRef Name; // from the "names" section + StringRef Name; // from the "linking" or "names" section StringRef Comdat; // from the "comdat info" section }; Index: llvm/trunk/lib/Object/WasmObjectFile.cpp =================================================================== --- llvm/trunk/lib/Object/WasmObjectFile.cpp +++ llvm/trunk/lib/Object/WasmObjectFile.cpp @@ -403,7 +403,7 @@ Info.Name = readString(Ptr); unsigned FuncIndex = Info.ElementIndex - NumImportedFunctions; FunctionType = &Signatures[FunctionTypes[FuncIndex]]; - auto &Function = Functions[FuncIndex]; + wasm::WasmFunction &Function = Functions[FuncIndex]; if (Function.Name.empty()) { // Use the symbol's name to set a name for the Function, but only if // one hasn't already been set. @@ -425,7 +425,13 @@ if (IsDefined) { Info.Name = readString(Ptr); unsigned GlobalIndex = Info.ElementIndex - NumImportedGlobals; - GlobalType = &Globals[GlobalIndex].Type; + wasm::WasmGlobal &Global = Globals[GlobalIndex]; + GlobalType = &Global.Type; + if (Global.Name.empty()) { + // Use the symbol's name to set a name for the Global, but only if + // one hasn't already been set. + Global.Name = Info.Name; + } } else { wasm::WasmImport &Import = *ImportedGlobals[Info.ElementIndex]; Info.Name = Import.Field;