Index: include/llvm/BinaryFormat/Wasm.h =================================================================== --- include/llvm/BinaryFormat/Wasm.h +++ 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: lib/Object/WasmObjectFile.cpp =================================================================== --- lib/Object/WasmObjectFile.cpp +++ lib/Object/WasmObjectFile.cpp @@ -425,7 +425,13 @@ if (IsDefined) { Info.Name = readString(Ptr); unsigned GlobalIndex = Info.ElementIndex - NumImportedGlobals; - GlobalType = &Globals[GlobalIndex].Type; + auto &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;