Index: test/tools/llvm-objdump/WebAssembly/relocations.test =================================================================== --- test/tools/llvm-objdump/WebAssembly/relocations.test +++ test/tools/llvm-objdump/WebAssembly/relocations.test @@ -1,8 +1,16 @@ ; RUN: llc -mtriple=wasm32-unknown-unknown-wasm -filetype=obj %s -o - | llvm-objdump -r - | FileCheck %s -@foo1 = hidden global i32 1, align 4 -@foo2 = hidden global i32 1, align 4 -@bar = hidden global i32* @foo2, align 4 +@foo = external global i32, align 4 +@bar = global i32* @foo, align 4 + +define void @make_call(void ()* nocapture %func) { +entry: + call void %func() + ret void +} + +; CHECK: RELOCATION RECORDS FOR [CODE]: +; CHECK-NEXT: 00000006 R_WEBASSEMBLY_TYPE_INDEX_LEB 1+0 ; CHECK: RELOCATION RECORDS FOR [DATA]: -; CHECK-NEXT: 00000018 R_WEBASSEMBLY_MEMORY_ADDR_I32 foo2+0 +; CHECK-NEXT: 00000006 R_WEBASSEMBLY_MEMORY_ADDR_I32 foo+0 Index: tools/llvm-objdump/llvm-objdump.cpp =================================================================== --- tools/llvm-objdump/llvm-objdump.cpp +++ tools/llvm-objdump/llvm-objdump.cpp @@ -920,10 +920,14 @@ symbol_iterator SI = RelRef.getSymbol(); std::string fmtbuf; raw_string_ostream fmt(fmtbuf); - Expected SymNameOrErr = SI->getName(); - if (!SymNameOrErr) { + if (SI == Obj->symbol_end()) { + // Not all wasm relocations have symbols associated with them. + // In particular R_WEBASSEMBLY_TYPE_INDEX_LEB. fmt << Rel.Index; } else { + Expected SymNameOrErr = SI->getName(); + if (!SymNameOrErr) + return errorToErrorCode(SymNameOrErr.takeError()); StringRef SymName = *SymNameOrErr; Result.append(SymName.begin(), SymName.end()); }