From: Sam Clegg Date: Thu, 26 Apr 2018 17:05:04 +0000 (+0000) Subject: [WebAssembly] objdump: Don't assume all relocations have symbols X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8c4b0ce2b10d1ca9cce2a10d99d144ca8661468b;p=platform%2Fupstream%2Fllvm.git [WebAssembly] objdump: Don't assume all relocations have symbols Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D46134 llvm-svn: 330959 --- diff --git a/llvm/test/tools/llvm-objdump/WebAssembly/relocations.test b/llvm/test/tools/llvm-objdump/WebAssembly/relocations.test index 4f4c1b5..9a8c7b7 100644 --- a/llvm/test/tools/llvm-objdump/WebAssembly/relocations.test +++ b/llvm/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 diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index f32ff06..0a1f0e2 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -920,10 +920,14 @@ static std::error_code getRelocationValueString(const WasmObjectFile *Obj, 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()); }