uint32_t Index;
WasmGlobalType Type;
WasmInitExpr InitExpr;
+ StringRef Name; // from the "linking" or "names" section
};
struct WasmImport {
ArrayRef<uint8_t> 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
};
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.
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;