diff --git a/include/llvm/MC/MCSymbolWasm.h b/include/llvm/MC/MCSymbolWasm.h index 10eadb03c43..e043453dc73 100644 --- a/include/llvm/MC/MCSymbolWasm.h +++ b/include/llvm/MC/MCSymbolWasm.h @@ -45,6 +45,7 @@ public: bool isFunction() const { return Type == wasm::WASM_SYMBOL_TYPE_FUNCTION; } bool isData() const { return Type == wasm::WASM_SYMBOL_TYPE_DATA; } bool isGlobal() const { return Type == wasm::WASM_SYMBOL_TYPE_GLOBAL; } + bool isSection() const { return Type == wasm::WASM_SYMBOL_TYPE_SECTION; } wasm::WasmSymbolType getType() const { return Type; } void setType(wasm::WasmSymbolType type) { Type = type; } diff --git a/lib/MC/WasmObjectWriter.cpp b/lib/MC/WasmObjectWriter.cpp index 6ef45705525..26dea0a9746 100644 --- a/lib/MC/WasmObjectWriter.cpp +++ b/lib/MC/WasmObjectWriter.cpp @@ -37,6 +37,29 @@ using namespace llvm; #define DEBUG_TYPE "mc" +static std::string toString(wasm::WasmSymbolType type) { + switch (type) { + case wasm::WASM_SYMBOL_TYPE_FUNCTION: + return "WASM_SYMBOL_TYPE_FUNCTION"; + case wasm::WASM_SYMBOL_TYPE_GLOBAL: + return "WASM_SYMBOL_TYPE_GLOBAL"; + case wasm::WASM_SYMBOL_TYPE_DATA: + return "WASM_SYMBOL_TYPE_DATA"; + case wasm::WASM_SYMBOL_TYPE_SECTION: + return "WASM_SYMBOL_TYPE_SECTION"; + } +} + +static std::string relocTypetoString(uint32_t type) { + switch (type) { +#define WASM_RELOC(NAME, VALUE) case VALUE: return #NAME; +#include "llvm/BinaryFormat/WasmRelocs.def" +#undef WASM_RELOC + default: + llvm_unreachable("uknown reloc type"); + } +} + namespace { // Went we ceate the indirect function table we start at 1, so that there is @@ -163,8 +186,8 @@ struct WasmRelocationEntry { } void print(raw_ostream &Out) const { - Out << "Off=" << Offset << ", Sym=" << *Symbol << ", Addend=" << Addend - << ", Type=" << Type + Out << relocTypetoString(Type) + << " Off=" << Offset << ", Sym=" << *Symbol << ", Addend=" << Addend << ", FixupSection=" << FixupSection->getSectionName(); } @@ -214,7 +237,7 @@ class WasmObjectWriter : public MCObjectWriter { DenseMap TableIndices; // Maps function/global symbols to the (shared) Symbol index space. DenseMap SymbolIndices; - // Maps function/global symbols to the function/global Wasm index space. + // Maps function/global symbols to the function/global/section index space. DenseMap WasmIndices; // Maps data symbols to the Wasm segment and offset/size with the segment. DenseMap DataLocations; @@ -1235,11 +1258,11 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm, continue; const auto &WS = static_cast(S); - DEBUG(dbgs() << "MCSymbol: '" << S << "'" + DEBUG(dbgs() << "MCSymbol: " << toString(WS.getType()) + << " '" << S << "'" << " isDefined=" << S.isDefined() << " isExternal=" << S.isExternal() << " isTemporary=" << S.isTemporary() - << " isFunction=" << WS.isFunction() << " isWeak=" << WS.isWeak() << " isHidden=" << WS.isHidden() << " isVariable=" << WS.isVariable() << "\n"); @@ -1284,7 +1307,7 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm, continue; if (!WS.isDefined()) { - DEBUG(dbgs() << " -> segment index: -1"); + DEBUG(dbgs() << " -> segment index: -1" << "\n"); continue; } @@ -1306,8 +1329,8 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm, static_cast(Layout.getSymbolOffset(WS)), static_cast(Size)}; DataLocations[&WS] = Ref; - DEBUG(dbgs() << " -> segment index: " << Ref.Segment); - } else { + DEBUG(dbgs() << " -> segment index: " << Ref.Segment << "\n"); + } else if (WS.isGlobal()) { // A "true" Wasm global (currently just __stack_pointer) if (WS.isDefined()) report_fatal_error("don't yet support defined globals"); @@ -1315,6 +1338,8 @@ void WasmObjectWriter::writeObject(MCAssembler &Asm, // An import; the index was assigned above DEBUG(dbgs() << " -> global index: " << WasmIndices.find(&WS)->second << "\n"); + } else { + assert(WS.isSection()); } }