From 5376db4ce8f5f46f519de315d8b74186cb6aebd3 Mon Sep 17 00:00:00 2001 From: Konstantin Zhuravlyov Date: Sat, 14 Oct 2017 16:43:46 +0000 Subject: [PATCH] llvm-readobj: Print AMDGPU note type names Differential Revision: https://reviews.llvm.org/D38751 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315813 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGen/AMDGPU/elf-notes.ll | 28 ++++++++++++++++++ .../AMDGPU/hsa-metadata-from-llvm-ir-full.ll | 12 ++++---- tools/llvm-readobj/ELFDumper.cpp | 29 +++++++++++++++++-- 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/test/CodeGen/AMDGPU/elf-notes.ll b/test/CodeGen/AMDGPU/elf-notes.ll index 663a352c7a9..79779e4b319 100644 --- a/test/CodeGen/AMDGPU/elf-notes.ll +++ b/test/CodeGen/AMDGPU/elf-notes.ll @@ -24,6 +24,10 @@ ; OSABI-PAL-NOT: .amd_amdgpu_hsa_metadata ; OSABI-PAL: .amd_amdgpu_pal_metadata +; RUN: llc -mtriple=amdgcn-amd-unknown -mcpu=gfx800 -mattr=+code-object-v3 -filetype=obj < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck --check-prefix=GCN --check-prefix=OSABI-UNK-ELF --check-prefix=GFX800 %s +; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx800 -mattr=+code-object-v3 -filetype=obj < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck --check-prefix=GCN --check-prefix=OSABI-HSA-ELF --check-prefix=GFX800 %s +; RUN: llc -mtriple=amdgcn-amd-amdpal -mcpu=gfx800 -mattr=+code-object-v3 -filetype=obj < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck --check-prefix=GCN --check-prefix=OSABI-PAL-ELF --check-prefix=GFX800 %s + ; R600-NOT: .hsa_code_object_version ; R600-NOT: .hsa_code_object_isa ; R600-NOT: .amd_amdgpu_isa @@ -33,3 +37,27 @@ define amdgpu_kernel void @elf_notes() { ret void } + +; OSABI-UNK-ELF-NOT: Unknown note type +; OSABI-UNK-ELF: NT_AMD_AMDGPU_ISA (ISA Version) +; OSABI-UNK-ELF-NOT: Unknown note type +; OSABI-UNK-ELF-NOT: NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata) +; OSABI-UNK-ELF-NOT: Unknown note type +; OSABI-UNK-ELF-NOT: NT_AMD_AMDGPU_PAL_METADATA (PAL Metadata) +; OSABI-UNK-ELF-NOT: Unknown note type + +; OSABI-HSA-ELF-NOT: Unknown note type +; OSABI-HSA-ELF: NT_AMD_AMDGPU_ISA (ISA Version) +; OSABI-HSA-ELF-NOT: Unknown note type +; OSABI-HSA-ELF: NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata) +; OSABI-HSA-ELF-NOT: Unknown note type +; OSABI-HSA-ELF-NOT: NT_AMD_AMDGPU_PAL_METADATA (PAL Metadata) +; OSABI-HSA-ELF-NOT: Unknown note type + +; OSABI-PAL-ELF-NOT: Unknown note type +; OSABI-PAL-ELF: NT_AMD_AMDGPU_ISA (ISA Version) +; OSABI-PAL-ELF-NOT: Unknown note type +; OSABI-PAL-ELF-NOT: NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata) +; OSABI-PAL-ELF-NOT: Unknown note type +; OSABI-PAL-ELF: NT_AMD_AMDGPU_PAL_METADATA (PAL Metadata) +; OSABI-PAL-ELF-NOT: Unknown note type diff --git a/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll b/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll index 8fd529026e4..9e899000b91 100644 --- a/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll +++ b/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll @@ -1293,11 +1293,11 @@ attributes #0 = { "runtime-handle"="__test_block_invoke_kernel_runtime_handle" } !110 = !{!"__block_literal"} ; NOTES: Displaying notes found at file offset 0x{{[0-9]+}} -; NOTES-NEXT: Owner Data size Description -; NOTES-NEXT: AMD 0x00000008 Unknown note type: (0x00000001) -; NOTES-NEXT: AMD 0x0000001b Unknown note type: (0x00000003) -; GFX700: AMD 0x00008f64 Unknown note type: (0x0000000a) -; GFX800: AMD 0x000092e4 Unknown note type: (0x0000000a) -; GFX900: AMD 0x00008f64 Unknown note type: (0x0000000a) +; NOTES: Owner Data size Description +; NOTES: AMD 0x00000008 Unknown note type (0x00000001) +; NOTES: AMD 0x0000001b Unknown note type (0x00000003) +; GFX700: AMD 0x00008f64 NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata) +; GFX800: AMD 0x000092e4 NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata) +; GFX900: AMD 0x00008f64 NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata) ; PARSER: AMDGPU HSA Metadata Parser Test: PASS diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp index 037ffd2c79c..24139d66b1f 100644 --- a/tools/llvm-readobj/ELFDumper.cpp +++ b/tools/llvm-readobj/ELFDumper.cpp @@ -3393,7 +3393,7 @@ static std::string getGNUNoteTypeName(const uint32_t NT) { std::string string; raw_string_ostream OS(string); OS << format("Unknown note type (0x%08x)", NT); - return string; + return OS.str(); } static std::string getFreeBSDNoteTypeName(const uint32_t NT) { @@ -3421,7 +3421,30 @@ static std::string getFreeBSDNoteTypeName(const uint32_t NT) { std::string string; raw_string_ostream OS(string); OS << format("Unknown note type (0x%08x)", NT); - return string; + return OS.str(); +} + +static std::string getAMDGPUNoteTypeName(const uint32_t NT) { + static const struct { + uint32_t ID; + const char *Name; + } Notes[] = { + {ELF::NT_AMD_AMDGPU_HSA_METADATA, + "NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata)"}, + {ELF::NT_AMD_AMDGPU_ISA, + "NT_AMD_AMDGPU_ISA (ISA Version)"}, + {ELF::NT_AMD_AMDGPU_PAL_METADATA, + "NT_AMD_AMDGPU_PAL_METADATA (PAL Metadata)"} + }; + + for (const auto &Note : Notes) + if (Note.ID == NT) + return std::string(Note.Name); + + std::string string; + raw_string_ostream OS(string); + OS << format("Unknown note type (0x%08x)", NT); + return OS.str(); } template @@ -3504,6 +3527,8 @@ void GNUStyle::printNotes(const ELFFile *Obj) { printGNUNote(OS, Type, Descriptor, DescriptorSize); } else if (Name == "FreeBSD") { OS << getFreeBSDNoteTypeName(Type) << '\n'; + } else if (Name == "AMD") { + OS << getAMDGPUNoteTypeName(Type) << '\n'; } else { OS << "Unknown note type: (" << format_hex(Type, 10) << ')'; } -- 2.40.0