Index: llvm/trunk/lib/Object/WasmObjectFile.cpp =================================================================== --- llvm/trunk/lib/Object/WasmObjectFile.cpp +++ llvm/trunk/lib/Object/WasmObjectFile.cpp @@ -1139,10 +1139,14 @@ return Rel.Offset; } -symbol_iterator WasmObjectFile::getRelocationSymbol(DataRefImpl Rel) const { - llvm_unreachable("not yet implemented"); - SymbolRef Ref; - return symbol_iterator(Ref); +symbol_iterator WasmObjectFile::getRelocationSymbol(DataRefImpl Ref) const { + const wasm::WasmRelocation &Rel = getWasmRelocation(Ref); + if (Rel.Type == wasm::R_WEBASSEMBLY_TYPE_INDEX_LEB) + return symbol_end(); + DataRefImpl Sym; + Sym.d.a = Rel.Index; + Sym.d.b = 0; + return symbol_iterator(SymbolRef(Sym, this)); } uint64_t WasmObjectFile::getRelocationType(DataRefImpl Ref) const { Index: llvm/trunk/test/Object/objdump-relocations.test =================================================================== --- llvm/trunk/test/Object/objdump-relocations.test +++ llvm/trunk/test/Object/objdump-relocations.test @@ -60,9 +60,9 @@ ELF-MIPSEL: R_MIPS_CALL16 SomeOtherFunction WASM: CODE -WASM-NEXT: R_WEBASSEMBLY_MEMORY_ADDR_SLEB 1+0 -WASM-NEXT: R_WEBASSEMBLY_FUNCTION_INDEX_LEB 2+0 -WASM-NEXT: R_WEBASSEMBLY_FUNCTION_INDEX_LEB 3+0 +WASM-NEXT: R_WEBASSEMBLY_MEMORY_ADDR_SLEB .L.str+0 +WASM-NEXT: R_WEBASSEMBLY_FUNCTION_INDEX_LEB puts+0 +WASM-NEXT: R_WEBASSEMBLY_FUNCTION_INDEX_LEB SomeOtherFunction+0 ELF-complex-x86-64: .text ELF-complex-x86-64-NEXT: R_X86_64_8 .data-4 Index: llvm/trunk/test/tools/llvm-objdump/WebAssembly/relocations.test =================================================================== --- llvm/trunk/test/tools/llvm-objdump/WebAssembly/relocations.test +++ llvm/trunk/test/tools/llvm-objdump/WebAssembly/relocations.test @@ -5,4 +5,4 @@ @bar = hidden global i32* @foo2, align 4 ; CHECK: RELOCATION RECORDS FOR [DATA]: -; CHECK-NEXT: 00000018 R_WEBASSEMBLY_MEMORY_ADDR_I32 1+0 +; CHECK-NEXT: 00000018 R_WEBASSEMBLY_MEMORY_ADDR_I32 foo2+0 Index: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp +++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp @@ -917,9 +917,17 @@ const RelocationRef &RelRef, SmallVectorImpl &Result) { const wasm::WasmRelocation& Rel = Obj->getWasmRelocation(RelRef); + symbol_iterator SI = RelRef.getSymbol(); std::string fmtbuf; raw_string_ostream fmt(fmtbuf); - fmt << Rel.Index << (Rel.Addend < 0 ? "" : "+") << Rel.Addend; + Expected SymNameOrErr = SI->getName(); + if (!SymNameOrErr) { + fmt << Rel.Index; + } else { + StringRef SymName = *SymNameOrErr; + Result.append(SymName.begin(), SymName.end()); + } + fmt << (Rel.Addend < 0 ? "" : "+") << Rel.Addend; fmt.flush(); Result.append(fmtbuf.begin(), fmtbuf.end()); return std::error_code();