Index: lld/test/wasm/debuginfo.test =================================================================== --- lld/test/wasm/debuginfo.test +++ lld/test/wasm/debuginfo.test @@ -45,7 +45,7 @@ CHECK: DW_TAG_variable CHECK-NEXT: DW_AT_name ("y") -CHECK-NEXT: DW_AT_type (0x000000a1 "int[2]") +CHECK-NEXT: DW_AT_type (0x000000a7 "int[2]") CHECK-NEXT: DW_AT_external (true) CHECK-NEXT: DW_AT_decl_file ("{{.*}}hi_foo.c") CHECK-NEXT: DW_AT_decl_line (1) @@ -67,14 +67,14 @@ CHECK: DW_TAG_variable CHECK-NEXT: DW_AT_name ("z") -CHECK-NEXT: DW_AT_type (0x000000a1 "int[2]") +CHECK-NEXT: DW_AT_type (0x000000a7 "int[2]") CHECK-NEXT: DW_AT_external (true) CHECK-NEXT: DW_AT_decl_file ("{{.*}}hi_foo.c") CHECK-NEXT: DW_AT_decl_line (8) CHECK-NEXT: DW_AT_location (DW_OP_addr 0x0) CHECK: DW_TAG_subprogram -CHECK-NEXT: DW_AT_low_pc +CHECK-NEXT: DW_AT_low_pc CHECK-NEXT: DW_AT_high_pc CHECK-NEXT: DW_AT_frame_base CHECK-NEXT: DW_AT_name ("foo") Index: lld/wasm/InputChunks.cpp =================================================================== --- lld/wasm/InputChunks.cpp +++ lld/wasm/InputChunks.cpp @@ -68,6 +68,7 @@ case R_WASM_MEMORY_ADDR_I32: case R_WASM_FUNCTION_OFFSET_I32: case R_WASM_SECTION_OFFSET_I32: + case R_WASM_GLOBAL_INDEX_I32: existingValue = static_cast(read32le(loc)); break; default: @@ -77,7 +78,8 @@ if (bytesRead && bytesRead != 5) warn("expected LEB at relocation site be 5-byte padded"); - if (rel.Type != R_WASM_GLOBAL_INDEX_LEB) { + if (rel.Type != R_WASM_GLOBAL_INDEX_LEB || + rel.Type != R_WASM_GLOBAL_INDEX_I32) { uint32_t expectedValue = file->calcExpectedValue(rel); if (expectedValue != existingValue) warn("unexpected existing value for " + relocTypeToString(rel.Type) + @@ -132,6 +134,7 @@ case R_WASM_MEMORY_ADDR_I32: case R_WASM_FUNCTION_OFFSET_I32: case R_WASM_SECTION_OFFSET_I32: + case R_WASM_GLOBAL_INDEX_I32: write32le(loc, value); break; default: Index: lld/wasm/InputFiles.cpp =================================================================== --- lld/wasm/InputFiles.cpp +++ lld/wasm/InputFiles.cpp @@ -152,6 +152,7 @@ return reloc.Index; case R_WASM_FUNCTION_INDEX_LEB: case R_WASM_GLOBAL_INDEX_LEB: + case R_WASM_GLOBAL_INDEX_I32: case R_WASM_EVENT_INDEX_LEB: { const WasmSymbol &sym = wasmObj->syms()[reloc.Index]; return sym.Info.ElementIndex; @@ -199,6 +200,7 @@ case R_WASM_FUNCTION_INDEX_LEB: return getFunctionSymbol(reloc.Index)->getFunctionIndex(); case R_WASM_GLOBAL_INDEX_LEB: + case R_WASM_GLOBAL_INDEX_I32: if (auto gs = dyn_cast(sym)) return gs->getGlobalIndex(); return sym->getGOTIndex(); Index: lld/wasm/Relocations.cpp =================================================================== --- lld/wasm/Relocations.cpp +++ lld/wasm/Relocations.cpp @@ -84,6 +84,7 @@ out.elemSec->addEntry(cast(sym)); break; case R_WASM_GLOBAL_INDEX_LEB: + case R_WASM_GLOBAL_INDEX_I32: if (!isa(sym)) addGOTEntry(sym); break; Index: llvm/include/llvm/BinaryFormat/Dwarf.def =================================================================== --- llvm/include/llvm/BinaryFormat/Dwarf.def +++ llvm/include/llvm/BinaryFormat/Dwarf.def @@ -664,6 +664,7 @@ HANDLE_DW_OP(0xe0, GNU_push_tls_address, 0, GNU) // Extensions for WebAssembly. HANDLE_DW_OP(0xed, WASM_location, 0, WASM) +HANDLE_DW_OP(0xee, WASM_location_int, 0, WASM) // The GNU entry value extension. HANDLE_DW_OP(0xf3, GNU_entry_value, 0, GNU) // Extensions for Fission proposal. Index: llvm/include/llvm/BinaryFormat/WasmRelocs.def =================================================================== --- llvm/include/llvm/BinaryFormat/WasmRelocs.def +++ llvm/include/llvm/BinaryFormat/WasmRelocs.def @@ -15,3 +15,4 @@ WASM_RELOC(R_WASM_EVENT_INDEX_LEB, 10) WASM_RELOC(R_WASM_MEMORY_ADDR_REL_SLEB, 11) WASM_RELOC(R_WASM_TABLE_INDEX_REL_SLEB, 12) +WASM_RELOC(R_WASM_GLOBAL_INDEX_I32, 13) Index: llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h =================================================================== --- llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h +++ llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h @@ -42,6 +42,7 @@ SizeRefAddr = 6, SizeBlock = 7, ///< Preceding operand contains block size BaseTypeRef = 8, + WasmLocationArg = 30, SignBit = 0x80, SignedSize1 = SignBit | Size1, SignedSize2 = SignBit | Size2, Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -37,6 +37,7 @@ #include "llvm/MC/MCSection.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCSymbolWasm.h" #include "llvm/MC/MachineLocation.h" #include "llvm/Support/Casting.h" #include "llvm/Target/TargetLoweringObjectFile.h" @@ -420,13 +421,37 @@ break; } case TargetFrameLowering::DwarfFrameBase::WasmFrameBase: { - DIELoc *Loc = new (DIEValueAllocator) DIELoc; - DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc); - DIExpressionCursor Cursor({}); - DwarfExpr.addWasmLocation(FrameBase.Location.WasmLoc.Kind, - FrameBase.Location.WasmLoc.Index); - DwarfExpr.addExpression(std::move(Cursor)); - addBlock(*SPDie, dwarf::DW_AT_frame_base, DwarfExpr.finalize()); + // FIXME: duplicated from Target/WebAssembly/WebAssembly.h + // don't want to depend on target specific headers in this code? + const unsigned TI_GLOBAL_RELOC = 3; + if (FrameBase.Location.WasmLoc.Kind == TI_GLOBAL_RELOC) { + // These need to be relocatable. + assert(FrameBase.Location.WasmLoc.Index == 0); // Only SP so far. + auto SPSym = cast( + Asm->GetExternalSymbolSymbol("__stack_pointer")); + // FIXME: this repeats what WebAssemblyMCInstLower:: + // GetExternalSymbolSymbol does, since if there's no code that + // refers to this symbol, we have to set it here. + SPSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL); + // FIXME: need to check subtarget to see if its wasm64, but we + // can't cast to WebAssemblySubtarget here. + SPSym->setGlobalType(wasm::WasmGlobalType{wasm::WASM_TYPE_I32, true}); + DIELoc *Loc = new (DIEValueAllocator) DIELoc; + addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_WASM_location); + addSInt(*Loc, dwarf::DW_FORM_sdata, FrameBase.Location.WasmLoc.Kind); + addLabel(*Loc, dwarf::DW_FORM_udata, SPSym); + DD->addArangeLabel(SymbolCU(this, SPSym)); + addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value); + addBlock(*SPDie, dwarf::DW_AT_frame_base, Loc); + } else { + DIELoc *Loc = new (DIEValueAllocator) DIELoc; + DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc); + DIExpressionCursor Cursor({}); + DwarfExpr.addWasmLocation(FrameBase.Location.WasmLoc.Kind, + FrameBase.Location.WasmLoc.Index); + DwarfExpr.addExpression(std::move(Cursor)); + addBlock(*SPDie, dwarf::DW_AT_frame_base, DwarfExpr.finalize()); + } break; } } Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2400,7 +2400,7 @@ TargetIndexLocation Loc = Value.getTargetIndexLocation(); // TODO TargetIndexLocation is a target-independent. Currently only the WebAssembly-specific // encoding is supported. - DwarfExpr.addWasmLocation(Loc.Index, Loc.Offset); + DwarfExpr.addWasmLocation(Loc.Index, static_cast(Loc.Offset)); } else if (Value.isConstantFP()) { APInt RawBytes = Value.getConstantFP()->getValueAPF().bitcastToAPInt(); DwarfExpr.addUnsignedConstant(RawBytes); Index: llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h +++ llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h @@ -342,7 +342,7 @@ /// Emit location information expressed via WebAssembly location + offset /// The Index is an identifier for locals, globals or operand stack. - void addWasmLocation(unsigned Index, int64_t Offset); + void addWasmLocation(unsigned Index, uint64_t Offset); }; /// DwarfExpression implementation for .debug_loc entries. Index: llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp @@ -582,10 +582,10 @@ emitOp(dwarf::DW_OP_and); } -void DwarfExpression::addWasmLocation(unsigned Index, int64_t Offset) { +void DwarfExpression::addWasmLocation(unsigned Index, uint64_t Offset) { assert(LocationKind == Implicit || LocationKind == Unknown); LocationKind = Implicit; emitOp(dwarf::DW_OP_WASM_location); emitUnsigned(Index); - emitSigned(Offset); + emitUnsigned(Offset); } Index: llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp =================================================================== --- llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp +++ llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp @@ -94,7 +94,7 @@ Desc(Op::Dwarf3, Op::SizeLEB, Op::SizeBlock); Descriptions[DW_OP_stack_value] = Desc(Op::Dwarf3); Descriptions[DW_OP_WASM_location] = - Desc(Op::Dwarf4, Op::SizeLEB, Op::SignedSizeLEB); + Desc(Op::Dwarf4, Op::SizeLEB, Op::WasmLocationArg); Descriptions[DW_OP_GNU_push_tls_address] = Desc(Op::Dwarf3); Descriptions[DW_OP_addrx] = Desc(Op::Dwarf4, Op::SizeLEB); Descriptions[DW_OP_GNU_addr_index] = Desc(Op::Dwarf4, Op::SizeLEB); @@ -170,6 +170,19 @@ case Operation::BaseTypeRef: Operands[Operand] = Data.getULEB128(&Offset); break; + case Operation::WasmLocationArg: + assert(Operand == 1); + switch (Operands[0]) { + case 0: case 1: case 2: + Operands[Operand] = Data.getULEB128(&Offset); + break; + case 3: // global as uint32 + Operands[Operand] = Data.getU32(&Offset); + break; + default: + return false; // Unknown Wasm location + } + break; case Operation::SizeBlock: // We need a size, so this cannot be the first operand if (Operand == 0) @@ -273,6 +286,15 @@ OS << " 0x0"; else prettyPrintBaseTypeRef(U, OS, Operands, Operand); + } else if (Size == Operation::WasmLocationArg) { + assert(Operand == 1); + switch (Operands[0]) { + case 0: case 1: case 2: + case 3: // global as uint32 + OS << format(" 0x%" PRIx64, Operands[Operand]); + break; + default: assert(false); + } } else if (Size == Operation::SizeBlock) { uint64_t Offset = Operands[Operand]; for (unsigned i = 0; i < Operands[Operand - 1]; ++i) Index: llvm/lib/MC/WasmObjectWriter.cpp =================================================================== --- llvm/lib/MC/WasmObjectWriter.cpp +++ llvm/lib/MC/WasmObjectWriter.cpp @@ -537,7 +537,9 @@ // useable. uint32_t WasmObjectWriter::getProvisionalValue(const WasmRelocationEntry &RelEntry) { - if (RelEntry.Type == wasm::R_WASM_GLOBAL_INDEX_LEB && !RelEntry.Symbol->isGlobal()) { + if ((RelEntry.Type == wasm::R_WASM_GLOBAL_INDEX_LEB || + RelEntry.Type == wasm::R_WASM_GLOBAL_INDEX_I32) && + !RelEntry.Symbol->isGlobal()) { assert(GOTIndices.count(RelEntry.Symbol) > 0 && "symbol not found in GOT index space"); return GOTIndices[RelEntry.Symbol]; } @@ -556,6 +558,7 @@ return getRelocationIndexValue(RelEntry); case wasm::R_WASM_FUNCTION_INDEX_LEB: case wasm::R_WASM_GLOBAL_INDEX_LEB: + case wasm::R_WASM_GLOBAL_INDEX_I32: case wasm::R_WASM_EVENT_INDEX_LEB: // Provisional value is function/global/event Wasm index assert(WasmIndices.count(RelEntry.Symbol) > 0 && "symbol not found in wasm index space"); @@ -660,6 +663,7 @@ case wasm::R_WASM_MEMORY_ADDR_I32: case wasm::R_WASM_FUNCTION_OFFSET_I32: case wasm::R_WASM_SECTION_OFFSET_I32: + case wasm::R_WASM_GLOBAL_INDEX_I32: writeI32(Stream, Value, Offset); break; case wasm::R_WASM_TABLE_INDEX_SLEB: Index: llvm/lib/Object/RelocationResolver.cpp =================================================================== --- llvm/lib/Object/RelocationResolver.cpp +++ llvm/lib/Object/RelocationResolver.cpp @@ -498,6 +498,7 @@ case wasm::R_WASM_FUNCTION_OFFSET_I32: case wasm::R_WASM_SECTION_OFFSET_I32: case wasm::R_WASM_EVENT_INDEX_LEB: + case wasm::R_WASM_GLOBAL_INDEX_I32: return true; default: return false; @@ -517,6 +518,7 @@ case wasm::R_WASM_FUNCTION_OFFSET_I32: case wasm::R_WASM_SECTION_OFFSET_I32: case wasm::R_WASM_EVENT_INDEX_LEB: + case wasm::R_WASM_GLOBAL_INDEX_I32: // For wasm section, its offset at 0 -- ignoring Value return A; default: Index: llvm/lib/Object/WasmObjectFile.cpp =================================================================== --- llvm/lib/Object/WasmObjectFile.cpp +++ llvm/lib/Object/WasmObjectFile.cpp @@ -798,6 +798,11 @@ return make_error("Bad relocation global index", object_error::parse_failed); break; + case wasm::R_WASM_GLOBAL_INDEX_I32: + if (!isValidGlobalSymbol(Reloc.Index)) + return make_error("Bad relocation global index", + object_error::parse_failed); + break; case wasm::R_WASM_EVENT_INDEX_LEB: if (!isValidEventSymbol(Reloc.Index)) return make_error("Bad relocation event index", @@ -837,7 +842,8 @@ if (Reloc.Type == wasm::R_WASM_TABLE_INDEX_I32 || Reloc.Type == wasm::R_WASM_MEMORY_ADDR_I32 || Reloc.Type == wasm::R_WASM_SECTION_OFFSET_I32 || - Reloc.Type == wasm::R_WASM_FUNCTION_OFFSET_I32) + Reloc.Type == wasm::R_WASM_FUNCTION_OFFSET_I32 || + Reloc.Type == wasm::R_WASM_GLOBAL_INDEX_I32) Size = 4; if (Reloc.Offset + Size > EndOffset) return make_error("Bad relocation offset", Index: llvm/lib/ObjectYAML/WasmEmitter.cpp =================================================================== --- llvm/lib/ObjectYAML/WasmEmitter.cpp +++ llvm/lib/ObjectYAML/WasmEmitter.cpp @@ -530,12 +530,7 @@ writeUint8(OS, Reloc.Type); encodeULEB128(Reloc.Offset, OS); encodeULEB128(Reloc.Index, OS); - switch (Reloc.Type) { - case wasm::R_WASM_MEMORY_ADDR_LEB: - case wasm::R_WASM_MEMORY_ADDR_SLEB: - case wasm::R_WASM_MEMORY_ADDR_I32: - case wasm::R_WASM_FUNCTION_OFFSET_I32: - case wasm::R_WASM_SECTION_OFFSET_I32: + if (wasm::relocTypeHasAddend(Reloc.Type)) { encodeULEB128(Reloc.Addend, OS); } } Index: llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp =================================================================== --- llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp +++ llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp @@ -103,6 +103,8 @@ case FK_Data_4: if (SymA.isFunction()) return wasm::R_WASM_TABLE_INDEX_I32; + if (SymA.isGlobal()) + return wasm::R_WASM_GLOBAL_INDEX_I32; if (auto Section = static_cast( getFixupSection(Fixup.getValue()))) { if (Section->getKind().isText()) Index: llvm/lib/Target/WebAssembly/WebAssembly.h =================================================================== --- llvm/lib/Target/WebAssembly/WebAssembly.h +++ llvm/lib/Target/WebAssembly/WebAssembly.h @@ -78,7 +78,16 @@ void initializeWebAssemblyPeepholePass(PassRegistry &); namespace WebAssembly { -enum TargetIndex { TI_LOCAL_START, TI_GLOBAL_START, TI_OPERAND_STACK_START }; +enum TargetIndex { + // Followed by a local index (ULEB). + TI_LOCAL, + // Followed by an absolute global index (ULEB). DEPRECATED. + TI_GLOBAL_FIXED, + TI_OPERAND_STACK, + // Followed by a compilation unit relative global index (uint32_t) + // that will have an associated relocation. + TI_GLOBAL_RELOC +}; } // end namespace WebAssembly } // end namespace llvm Index: llvm/lib/Target/WebAssembly/WebAssemblyDebugValueManager.cpp =================================================================== --- llvm/lib/Target/WebAssembly/WebAssemblyDebugValueManager.cpp +++ llvm/lib/Target/WebAssembly/WebAssemblyDebugValueManager.cpp @@ -48,6 +48,6 @@ void WebAssemblyDebugValueManager::replaceWithLocal(unsigned LocalId) { for (auto *DBI : DbgValues) { MachineOperand &Op = DBI->getOperand(0); - Op.ChangeToTargetIndex(llvm::WebAssembly::TI_LOCAL_START, LocalId); + Op.ChangeToTargetIndex(llvm::WebAssembly::TI_LOCAL, LocalId); } } Index: llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp =================================================================== --- llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp +++ llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp @@ -266,12 +266,11 @@ const WebAssemblyFunctionInfo &MFI = *MF.getInfo(); if (needsSP(MF) && MFI.isFrameBaseVirtual()) { unsigned LocalNum = MFI.getFrameBaseLocal(); - Loc.Location.WasmLoc = {WebAssembly::TI_LOCAL_START, LocalNum}; + Loc.Location.WasmLoc = {WebAssembly::TI_LOCAL, LocalNum}; } else { // TODO: This should work on a breakpoint at a function with no frame, // but probably won't work for traversing up the stack. - // TODO: This needs a relocation for correct __stack_pointer - Loc.Location.WasmLoc = {WebAssembly::TI_GLOBAL_START, 0}; + Loc.Location.WasmLoc = {WebAssembly::TI_GLOBAL_RELOC, 0}; } return Loc; } Index: llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp =================================================================== --- llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp +++ llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp @@ -235,8 +235,9 @@ ArrayRef> WebAssemblyInstrInfo::getSerializableTargetIndices() const { static const std::pair TargetIndices[] = { - {WebAssembly::TI_LOCAL_START, "wasm-local-start"}, - {WebAssembly::TI_GLOBAL_START, "wasm-global-start"}, - {WebAssembly::TI_OPERAND_STACK_START, "wasm-operator-stack-start"}}; + {WebAssembly::TI_LOCAL, "wasm-local"}, + {WebAssembly::TI_GLOBAL_FIXED, "wasm-global-fixed"}, + {WebAssembly::TI_OPERAND_STACK, "wasm-operand-stack"}, + {WebAssembly::TI_GLOBAL_RELOC, "wasm-global-reloc"}}; return makeArrayRef(TargetIndices); } Index: llvm/test/CodeGen/WebAssembly/debugtest-opt.ll =================================================================== --- llvm/test/CodeGen/WebAssembly/debugtest-opt.ll +++ llvm/test/CodeGen/WebAssembly/debugtest-opt.ll @@ -11,7 +11,7 @@ ; CHECK-NEXT: DW_AT_low_pc ; CHECK-NEXT: DW_AT_high_pc ;; Check that we fall back to the default frame base (the global) -; CHECK-NEXT: DW_AT_frame_base (DW_OP_WASM_location 0x1 +0, DW_OP_stack_value) +; CHECK-NEXT: DW_AT_frame_base (DW_OP_WASM_location_int 0x3 0x0, DW_OP_stack_value) ; TODO: Find a more-reduced test case for The fix in WebAssemblyRegColoring Index: llvm/test/DebugInfo/WebAssembly/dbg-value-dwarfdump.ll =================================================================== --- llvm/test/DebugInfo/WebAssembly/dbg-value-dwarfdump.ll +++ llvm/test/DebugInfo/WebAssembly/dbg-value-dwarfdump.ll @@ -21,11 +21,11 @@ %a.010 = phi i32 [ %b.011, %for.body ], [ 0, %entry ] %i.09 = phi i32 [ %inc, %for.body ], [ 0, %entry ] -; CHECK: DW_OP_WASM_location 0x0 +[[LOCAL_1:[0-9]+]] +; CHECK: DW_OP_WASM_location 0x0 0x[[LOCAL_1:[0-9]+]] call void @llvm.dbg.value(metadata i32 %b.011, metadata !16, metadata !DIExpression()), !dbg !19 -; CHECK-NOT: DW_OP_WASM_location 0x0 +[[LOCAL_1]] -; CHECK: DW_OP_WASM_location 0x0 +[[LOCAL_2:[0-9]+]] +; CHECK-NOT: DW_OP_WASM_location 0x0 0x[[LOCAL_1]] +; CHECK: DW_OP_WASM_location 0x0 0x[[LOCAL_2:[0-9]+]] %add = add nsw i32 %b.011, %a.010, !dbg !26 %inc = add nuw nsw i32 %i.09, 1, !dbg !28 call void @llvm.dbg.value(metadata i32 %add, metadata !16, metadata !DIExpression()), !dbg !19 Index: llvm/test/MC/WebAssembly/debug-info.ll =================================================================== --- llvm/test/MC/WebAssembly/debug-info.ll +++ llvm/test/MC/WebAssembly/debug-info.ll @@ -11,33 +11,33 @@ ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: IMPORT (0x2) -; CHECK-NEXT: Size: 58 +; CHECK-NEXT: Size: 81 ; CHECK-NEXT: Offset: 18 ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: FUNCTION (0x3) ; CHECK-NEXT: Size: 2 -; CHECK-NEXT: Offset: 82 +; CHECK-NEXT: Offset: 105 ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: ELEM (0x9) ; CHECK-NEXT: Size: 7 -; CHECK-NEXT: Offset: 90 +; CHECK-NEXT: Offset: 113 ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: DATACOUNT (0xC) ; CHECK-NEXT: Size: 1 -; CHECK-NEXT: Offset: 103 +; CHECK-NEXT: Offset: 126 ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CODE (0xA) ; CHECK-NEXT: Size: 4 -; CHECK-NEXT: Offset: 110 +; CHECK-NEXT: Offset: 133 ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: DATA (0xB) ; CHECK-NEXT: Size: 19 -; CHECK-NEXT: Offset: 120 +; CHECK-NEXT: Offset: 143 ; CHECK-NEXT: Segments [ ; CHECK-NEXT: Segment { ; CHECK-NEXT: Name: .data.foo @@ -54,79 +54,79 @@ ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 86 -; CHECK-NEXT: Offset: 145 +; CHECK-NEXT: Offset: 168 ; CHECK-NEXT: Name: .debug_abbrev ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) -; CHECK-NEXT: Size: 111 -; CHECK-NEXT: Offset: 251 +; CHECK-NEXT: Size: 114 +; CHECK-NEXT: Offset: 274 ; CHECK-NEXT: Name: .debug_info ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 121 -; CHECK-NEXT: Offset: 380 +; CHECK-NEXT: Offset: 406 ; CHECK-NEXT: Name: .debug_str ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 42 -; CHECK-NEXT: Offset: 518 +; CHECK-NEXT: Offset: 544 ; CHECK-NEXT: Name: .debug_pubnames ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 26 -; CHECK-NEXT: Offset: 582 +; CHECK-NEXT: Offset: 608 ; CHECK-NEXT: Name: .debug_pubtypes ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 57 -; CHECK-NEXT: Offset: 630 +; CHECK-NEXT: Offset: 656 ; CHECK-NEXT: Name: .debug_line ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) -; CHECK-NEXT: Size: 88 -; CHECK-NEXT: Offset: 705 +; CHECK-NEXT: Size: 91 +; CHECK-NEXT: Offset: 731 ; CHECK-NEXT: Name: linking ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 9 -; CHECK-NEXT: Offset: 807 +; CHECK-NEXT: Offset: 836 ; CHECK-NEXT: Name: reloc.DATA ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) -; CHECK-NEXT: Size: 58 -; CHECK-NEXT: Offset: 833 +; CHECK-NEXT: Size: 61 +; CHECK-NEXT: Offset: 862 ; CHECK-NEXT: Name: reloc..debug_info ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 6 -; CHECK-NEXT: Offset: 915 +; CHECK-NEXT: Offset: 947 ; CHECK-NEXT: Name: reloc..debug_pubnames ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 6 -; CHECK-NEXT: Offset: 949 +; CHECK-NEXT: Offset: 981 ; CHECK-NEXT: Name: reloc..debug_pubtypes ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 6 -; CHECK-NEXT: Offset: 983 +; CHECK-NEXT: Offset: 1015 ; CHECK-NEXT: Name: reloc..debug_line ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 77 -; CHECK-NEXT: Offset: 1013 +; CHECK-NEXT: Offset: 1045 ; CHECK-NEXT: Name: producers ; CHECK-NEXT: } ; CHECK-NEXT:] @@ -148,7 +148,8 @@ ; CHECK-NEXT: 0x44 R_WASM_SECTION_OFFSET_I32 .debug_str 113 ; CHECK-NEXT: 0x50 R_WASM_MEMORY_ADDR_I32 ptr2 0 ; CHECK-NEXT: 0x5B R_WASM_FUNCTION_OFFSET_I32 f2 0 -; CHECK-NEXT: 0x68 R_WASM_SECTION_OFFSET_I32 .debug_str 118 +; CHECK-NEXT: 0x66 R_WASM_GLOBAL_INDEX_I32 __stack_pointer +; CHECK-NEXT: 0x6B R_WASM_SECTION_OFFSET_I32 .debug_str 118 ; CHECK-NEXT: } ; CHECK-NEXT: Section (11) .debug_pubnames { ; CHECK-NEXT: 0x6 R_WASM_SECTION_OFFSET_I32 .debug_info 0 @@ -213,6 +214,16 @@ ; CHECK-NEXT: ElementIndex: 0x8 ; CHECK-NEXT: } ; CHECK-NEXT: Symbol { +; CHECK-NEXT: Name: __stack_pointer +; CHECK-NEXT: Type: GLOBAL (0x2) +; CHECK-NEXT: Flags [ (0x10) +; CHECK-NEXT: UNDEFINED (0x10) +; CHECK-NEXT: ] +; CHECK-NEXT: ImportName: __stack_pointer +; CHECK-NEXT: ImportModule: env +; CHECK-NEXT: ElementIndex: 0x0 +; CHECK-NEXT: } +; CHECK-NEXT: Symbol { ; CHECK-NEXT: Name: .debug_str ; CHECK-NEXT: Type: SECTION (0x3) ; CHECK-NEXT: Flags [ (0x2) Index: llvm/test/MC/WebAssembly/debug-localvar.ll =================================================================== --- llvm/test/MC/WebAssembly/debug-localvar.ll +++ llvm/test/MC/WebAssembly/debug-localvar.ll @@ -80,7 +80,7 @@ ; CHECK-LABEL: DW_TAG_subprogram ; CHECK-NEXT: DW_AT_low_pc (0x0000000000000002) ; CHECK-NEXT: DW_AT_high_pc (0x0000000000000039) -; CHECK-NEXT: DW_AT_frame_base (DW_OP_WASM_location 0x0 +1, DW_OP_stack_value) +; CHECK-NEXT: DW_AT_frame_base (DW_OP_WASM_location 0x0 0x1, DW_OP_stack_value) ; CHECK-NEXT: DW_AT_name ("foo") ; CHECK-NEXT: DW_AT_decl_file ("/s/llvm-upstream{{(/|\\)}}debugtest.c") ; CHECK-NEXT: DW_AT_decl_line (1) Index: llvm/test/MC/WebAssembly/dwarfdump.ll =================================================================== --- llvm/test/MC/WebAssembly/dwarfdump.ll +++ llvm/test/MC/WebAssembly/dwarfdump.ll @@ -1,7 +1,7 @@ ; RUN: llc -filetype=obj %s -o - | llvm-dwarfdump - | FileCheck %s ; CHECK: .debug_info contents: -; CHECK-NEXT: 0x00000000: Compile Unit: length = 0x0000006b version = 0x0004 abbr_offset = 0x0000 addr_size = 0x04 (next unit at 0x0000006f) +; CHECK-NEXT: 0x00000000: Compile Unit: length = 0x0000006e version = 0x0004 abbr_offset = 0x0000 addr_size = 0x04 (next unit at 0x00000072) ; CHECK: 0x0000000b: DW_TAG_compile_unit ; CHECK-NEXT: DW_AT_producer ("clang version 6.0.0 (trunk 315924) (llvm/trunk 315960)") @@ -46,14 +46,14 @@ ; CHECK: 0x0000005a: DW_TAG_subprogram ; CHECK-NEXT: DW_AT_low_pc (0x0000000000000002) ; CHECK-NEXT: DW_AT_high_pc (0x0000000000000004) -; CHECK-NEXT: DW_AT_frame_base (DW_OP_WASM_location 0x1 +0, DW_OP_stack_value) +; CHECK-NEXT: DW_AT_frame_base (DW_OP_WASM_location 0x3 0x0, DW_OP_stack_value) ; CHECK-NEXT: DW_AT_name ("f2") ; CHECK-NEXT: DW_AT_decl_file ("/usr/local/google/home/sbc/dev/wasm/simple{{[/\\]}}test.c") ; CHECK-NEXT: DW_AT_decl_line (2) ; CHECK-NEXT: DW_AT_prototyped (true) ; CHECK-NEXT: DW_AT_external (true) -; CHECK: 0x0000006e: NULL +; CHECK: 0x00000071: NULL target triple = "wasm32-unknown-unknown" Index: llvm/tools/llvm-readobj/WasmDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/WasmDumper.cpp +++ llvm/tools/llvm-readobj/WasmDumper.cpp @@ -93,18 +93,8 @@ if (SI != Obj->symbol_end()) SymName = unwrapOrError(Obj->getFileName(), SI->getName()); - bool HasAddend = false; - switch (RelocType) { - case wasm::R_WASM_MEMORY_ADDR_LEB: - case wasm::R_WASM_MEMORY_ADDR_SLEB: - case wasm::R_WASM_MEMORY_ADDR_I32: - case wasm::R_WASM_FUNCTION_OFFSET_I32: - case wasm::R_WASM_SECTION_OFFSET_I32: - HasAddend = true; - break; - default: - break; - } + bool HasAddend = wasm::relocTypeHasAddend(static_cast(RelocType)); + if (opts::ExpandRelocs) { DictScope Group(W, "Relocation"); W.printNumber("Type", RelocTypeName, RelocType);