[llvm] r306461 - [WebAssembly] Add support for printing relocations with llvm-objdump
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 27 13:40:53 PDT 2017
Author: sbc
Date: Tue Jun 27 13:40:53 2017
New Revision: 306461
URL: http://llvm.org/viewvc/llvm-project?rev=306461&view=rev
Log:
[WebAssembly] Add support for printing relocations with llvm-objdump
Differential Revision: https://reviews.llvm.org/D34658
Added:
llvm/trunk/test/tools/llvm-objdump/WebAssembly/relocations.test
Modified:
llvm/trunk/include/llvm/Object/Wasm.h
llvm/trunk/lib/Object/WasmObjectFile.cpp
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
Modified: llvm/trunk/include/llvm/Object/Wasm.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Wasm.h?rev=306461&r1=306460&r2=306461&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Wasm.h (original)
+++ llvm/trunk/include/llvm/Object/Wasm.h Tue Jun 27 13:40:53 2017
@@ -215,6 +215,7 @@ private:
std::vector<WasmSymbol> Symbols;
ArrayRef<uint8_t> CodeSection;
uint32_t StartFunction = -1;
+ bool HasLinkingSection = false;
wasm::WasmLinkingData LinkingData;
StringMap<uint32_t> SymbolMap;
Modified: llvm/trunk/lib/Object/WasmObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/WasmObjectFile.cpp?rev=306461&r1=306460&r2=306461&view=diff
==============================================================================
--- llvm/trunk/lib/Object/WasmObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/WasmObjectFile.cpp Tue Jun 27 13:40:53 2017
@@ -294,6 +294,7 @@ Error WasmObjectFile::parseNameSection(c
Error WasmObjectFile::parseLinkingSection(const uint8_t *Ptr,
const uint8_t *End) {
+ HasLinkingSection = true;
while (Ptr < End) {
uint8_t Type = readVarint7(Ptr);
uint32_t Size = readVaruint32(Ptr);
@@ -950,7 +951,9 @@ SubtargetFeatures WasmObjectFile::getFea
return SubtargetFeatures();
}
-bool WasmObjectFile::isRelocatableObject() const { return false; }
+bool WasmObjectFile::isRelocatableObject() const {
+ return HasLinkingSection;
+}
const WasmSection &WasmObjectFile::getWasmSection(DataRefImpl Ref) const {
assert(Ref.d.a < Sections.size());
Added: llvm/trunk/test/tools/llvm-objdump/WebAssembly/relocations.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/WebAssembly/relocations.test?rev=306461&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/WebAssembly/relocations.test (added)
+++ llvm/trunk/test/tools/llvm-objdump/WebAssembly/relocations.test Tue Jun 27 13:40:53 2017
@@ -0,0 +1,8 @@
+; RUN: llc -mtriple=wasm32-unknown-unknown-wasm -filetype=obj %s -o - | llvm-objdump -r - | FileCheck %s
+
+ at foo1 = hidden global i32 1, align 4
+ at foo2 = hidden global i32 1, align 4
+ at bar = hidden global i32* @foo2, align 4
+
+; CHECK: RELOCATION RECORDS FOR [DATA]:
+; CHECK-NEXT: 0000000e R_WEBASSEMBLY_GLOBAL_ADDR_I32 1+0
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=306461&r1=306460&r2=306461&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Tue Jun 27 13:40:53 2017
@@ -41,6 +41,7 @@
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Object/MachO.h"
#include "llvm/Object/ObjectFile.h"
+#include "llvm/Object/Wasm.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
@@ -886,6 +887,18 @@ static void printRelocationTargetName(co
fmt << S;
}
+static std::error_code getRelocationValueString(const WasmObjectFile *Obj,
+ const RelocationRef &RelRef,
+ SmallVectorImpl<char> &Result) {
+ const wasm::WasmRelocation& Rel = Obj->getWasmRelocation(RelRef);
+ std::string fmtbuf;
+ raw_string_ostream fmt(fmtbuf);
+ fmt << Rel.Index << (Rel.Addend < 0 ? "" : "+") << Rel.Addend;
+ fmt.flush();
+ Result.append(fmtbuf.begin(), fmtbuf.end());
+ return std::error_code();
+}
+
static std::error_code getRelocationValueString(const MachOObjectFile *Obj,
const RelocationRef &RelRef,
SmallVectorImpl<char> &Result) {
@@ -1071,8 +1084,11 @@ static std::error_code getRelocationValu
return getRelocationValueString(ELF, Rel, Result);
if (auto *COFF = dyn_cast<COFFObjectFile>(Obj))
return getRelocationValueString(COFF, Rel, Result);
- auto *MachO = cast<MachOObjectFile>(Obj);
- return getRelocationValueString(MachO, Rel, Result);
+ if (auto *Wasm = dyn_cast<WasmObjectFile>(Obj))
+ return getRelocationValueString(Wasm, Rel, Result);
+ if (auto *MachO = dyn_cast<MachOObjectFile>(Obj))
+ return getRelocationValueString(MachO, Rel, Result);
+ llvm_unreachable("unknown object file format");
}
/// @brief Indicates whether this relocation should hidden when listing
More information about the llvm-commits
mailing list