summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-readobj/ELFDumper.cpp
diff options
context:
space:
mode:
authorScott Linder <scott@scottlinder.com>2018-12-12 19:39:27 +0000
committerScott Linder <scott@scottlinder.com>2018-12-12 19:39:27 +0000
commitf5b36e56fb4d89eab442559a37239eeafe7690d3 (patch)
tree049bb5435cb2728f5d3996f1a79cbc958796a046 /llvm/tools/llvm-readobj/ELFDumper.cpp
parent3f8f004daf62d1b1007e5c226e8da2dab96eea14 (diff)
downloadbcm5719-llvm-f5b36e56fb4d89eab442559a37239eeafe7690d3.tar.gz
bcm5719-llvm-f5b36e56fb4d89eab442559a37239eeafe7690d3.zip
[AMDGPU] Emit MessagePack HSA Metadata for v3 code object
Continue to present HSA metadata as YAML in ASM and when output by tools (e.g. llvm-readobj), but encode it in Messagepack in the code object. Differential Revision: https://reviews.llvm.org/D48179 llvm-svn: 348963
Diffstat (limited to 'llvm/tools/llvm-readobj/ELFDumper.cpp')
-rw-r--r--llvm/tools/llvm-readobj/ELFDumper.cpp75
1 files changed, 65 insertions, 10 deletions
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 83fb4864cb3..8e2b43cba1b 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -28,6 +28,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
+#include "llvm/BinaryFormat/AMDGPUMetadataVerifier.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/Object/ELF.h"
#include "llvm/Object/ELFObjectFile.h"
@@ -3628,7 +3629,7 @@ static std::string getFreeBSDNoteTypeName(const uint32_t NT) {
return OS.str();
}
-static std::string getAMDGPUNoteTypeName(const uint32_t NT) {
+static std::string getAMDNoteTypeName(const uint32_t NT) {
static const struct {
uint32_t ID;
const char *Name;
@@ -3651,6 +3652,16 @@ static std::string getAMDGPUNoteTypeName(const uint32_t NT) {
return OS.str();
}
+static std::string getAMDGPUNoteTypeName(const uint32_t NT) {
+ if (NT == ELF::NT_AMDGPU_METADATA)
+ return std::string("NT_AMDGPU_METADATA (AMDGPU Metadata)");
+
+ std::string string;
+ raw_string_ostream OS(string);
+ OS << format("Unknown note type (0x%08x)", NT);
+ return OS.str();
+}
+
template <typename ELFT>
static std::string getGNUProperty(uint32_t Type, uint32_t DataSize,
ArrayRef<uint8_t> Data) {
@@ -3808,14 +3819,13 @@ static void printGNUNote(raw_ostream &OS, uint32_t NoteType,
OS << '\n';
}
-struct AMDGPUNote {
- std::string type;
- std::string value;
+struct AMDNote {
+ std::string Type;
+ std::string Value;
};
template <typename ELFT>
-static AMDGPUNote getAMDGPUNote(uint32_t NoteType,
- ArrayRef<uint8_t> Desc) {
+static AMDNote getAMDNote(uint32_t NoteType, ArrayRef<uint8_t> Desc) {
switch (NoteType) {
default:
return {"", ""};
@@ -3841,6 +3851,41 @@ static AMDGPUNote getAMDGPUNote(uint32_t NoteType,
}
}
+struct AMDGPUNote {
+ std::string Type;
+ std::string Value;
+};
+
+template <typename ELFT>
+static AMDGPUNote getAMDGPUNote(uint32_t NoteType, ArrayRef<uint8_t> Desc) {
+ switch (NoteType) {
+ default:
+ return {"", ""};
+ case ELF::NT_AMDGPU_METADATA:
+ auto MsgPackString =
+ StringRef(reinterpret_cast<const char *>(Desc.data()), Desc.size());
+ msgpack::Reader MsgPackReader(MsgPackString);
+ auto OptMsgPackNodeOrErr = msgpack::Node::read(MsgPackReader);
+ if (errorToBool(OptMsgPackNodeOrErr.takeError()))
+ return {"AMDGPU Metadata", "Invalid AMDGPU Metadata"};
+ auto &OptMsgPackNode = *OptMsgPackNodeOrErr;
+ if (!OptMsgPackNode)
+ return {"AMDGPU Metadata", "Invalid AMDGPU Metadata"};
+ auto &MsgPackNode = *OptMsgPackNode;
+
+ AMDGPU::HSAMD::V3::MetadataVerifier Verifier(true);
+ if (!Verifier.verify(*MsgPackNode))
+ return {"AMDGPU Metadata", "Invalid AMDGPU Metadata"};
+
+ std::string HSAMetadataString;
+ raw_string_ostream StrOS(HSAMetadataString);
+ yaml::Output YOut(StrOS);
+ YOut << MsgPackNode;
+
+ return {"AMDGPU Metadata", StrOS.str()};
+ }
+}
+
template <class ELFT>
void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
const Elf_Ehdr *e = Obj->getHeader();
@@ -3867,10 +3912,15 @@ void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
} else if (Name == "FreeBSD") {
OS << getFreeBSDNoteTypeName(Type) << '\n';
} else if (Name == "AMD") {
+ OS << getAMDNoteTypeName(Type) << '\n';
+ const AMDNote N = getAMDNote<ELFT>(Type, Descriptor);
+ if (!N.Type.empty())
+ OS << " " << N.Type << ":\n " << N.Value << '\n';
+ } else if (Name == "AMDGPU") {
OS << getAMDGPUNoteTypeName(Type) << '\n';
const AMDGPUNote N = getAMDGPUNote<ELFT>(Type, Descriptor);
- if (!N.type.empty())
- OS << " " << N.type << ":\n " << N.value << '\n';
+ if (!N.Type.empty())
+ OS << " " << N.Type << ":\n " << N.Value << '\n';
} else {
OS << "Unknown note type: (" << format_hex(Type, 10) << ')';
}
@@ -4533,10 +4583,15 @@ void LLVMStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
} else if (Name == "FreeBSD") {
W.printString("Type", getFreeBSDNoteTypeName(Type));
} else if (Name == "AMD") {
+ W.printString("Type", getAMDNoteTypeName(Type));
+ const AMDNote N = getAMDNote<ELFT>(Type, Descriptor);
+ if (!N.Type.empty())
+ W.printString(N.Type, N.Value);
+ } else if (Name == "AMDGPU") {
W.printString("Type", getAMDGPUNoteTypeName(Type));
const AMDGPUNote N = getAMDGPUNote<ELFT>(Type, Descriptor);
- if (!N.type.empty())
- W.printString(N.type, N.value);
+ if (!N.Type.empty())
+ W.printString(N.Type, N.Value);
} else {
W.getOStream() << "Unknown note type: (" << format_hex(Type, 10) << ')';
}
OpenPOWER on IntegriCloud