diff --git a/llvm/test/tools/llvm-readobj/ELF/gnu-note-size.test b/llvm/test/tools/llvm-readobj/ELF/gnu-note-size.test --- a/llvm/test/tools/llvm-readobj/ELF/gnu-note-size.test +++ b/llvm/test/tools/llvm-readobj/ELF/gnu-note-size.test @@ -5,6 +5,7 @@ # GNU: Owner Data size Description # GNU-NEXT: GNU 0x00000004 NT_GNU_ABI_TAG (ABI version tag) # GNU-NEXT: +# GNU-EMPTY: # LLVM: Notes [ # LLVM-NEXT: NoteSection { @@ -15,6 +16,9 @@ # LLVM-NEXT: Data size: 0x4 # LLVM-NEXT: Type: NT_GNU_ABI_TAG (ABI version tag) # LLVM-NEXT: ABI: +# LLVM-NEXT: Description data ( +# LLVM-NEXT: 0000: 00000000 |....| +# LLVM-NEXT: ) # LLVM-NEXT: } # LLVM-NEXT: } # LLVM-NEXT: ] diff --git a/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test b/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test --- a/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test +++ b/llvm/test/tools/llvm-readobj/ELF/gnu-notes.test @@ -12,16 +12,23 @@ # GNU-NEXT: GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag) # GNU-NEXT: OS: Linux, ABI: 2.6.32 -# GNU:Displaying notes found at file offset 0x00000098 with length 0x00000020: +# GNU-NEXT:Displaying notes found at file offset 0x00000098 with length 0x00000020: # GNU-NEXT: Owner Data size Description # GNU-NEXT: GNU 0x00000010 NT_GNU_BUILD_ID (unique build ID bitstring) # GNU-NEXT: Build ID: 4fcb712aa6387724a9f465a32cd8c14b -# GNU:Displaying notes found at file offset 0x000000b8 with length 0x0000001c: +# GNU-NEXT:Displaying notes found at file offset 0x000000b8 with length 0x0000001c: # GNU-NEXT: Owner Data size Description # GNU-NEXT: GNU 0x00000009 NT_GNU_GOLD_VERSION (gold version) # GNU-NEXT: Version: gold 1.11 +# GNU-NEXT:Displaying notes found at file offset 0x000000d4 with length 0x00000014: +# GNU-NEXT: Owner Data size Description +# GNU-NEXT: GNU 0x00000004 Unknown note type: (0x0000abcd) +# GNU-NEXT: Description data: 61 62 63 64 + +# GNU-EMPTY: + # LLVM: Notes [ # LLVM-NEXT: NoteSection { # LLVM-NEXT: Offset: 0x78 @@ -54,6 +61,18 @@ # LLVM-NEXT: Version: gold 1.11 # LLVM-NEXT: } # LLVM-NEXT: } +# LLVM-NEXT: NoteSection { +# LLVM-NEXT: Offset: 0xD4 +# LLVM-NEXT: Size: 0x14 +# LLVM-NEXT: Note { +# LLVM-NEXT: Owner: GNU +# LLVM-NEXT: Data size: 0x4 +# LLVM-NEXT: Type: Unknown note type: (0x0000abcd) +# LLVM-NEXT: Description data ( +# LLVM-NEXT: 0000: 61626364 |abcd| +# LLVM-NEXT: ) +# LLVM-NEXT: } +# LLVM-NEXT: } # LLVM-NEXT: ] # LLVM-STRIPPED: Notes [ @@ -95,6 +114,10 @@ Type: SHT_NOTE AddressAlign: 0x0000000000000004 Content: 040000000900000004000000474E5500676F6C6420312E3131000000 + - Name: .note.gnu.unknown + Type: SHT_NOTE + AddressAlign: 0x0000000000000004 + Content: 0400000004000000cdab0000474E550061626364 ProgramHeaders: - Type: PT_NOTE FileSize: 0x20 diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -4840,17 +4840,18 @@ } template -static void printGNUNote(raw_ostream &OS, uint32_t NoteType, +static bool printGNUNote(raw_ostream &OS, uint32_t NoteType, ArrayRef Desc) { switch (NoteType) { default: - return; + return false; case ELF::NT_GNU_ABI_TAG: { const GNUAbiTag &AbiTag = getGNUAbiTag(Desc); - if (!AbiTag.IsValid) - OS << " "; - else - OS << " OS: " << AbiTag.OSName << ", ABI: " << AbiTag.ABI; + if (!AbiTag.IsValid) { + OS << " \n"; + return true; // Don't print the raw contents in GNU output mode + } + OS << " OS: " << AbiTag.OSName << ", ABI: " << AbiTag.ABI; break; } case ELF::NT_GNU_BUILD_ID: { @@ -4867,6 +4868,7 @@ break; } OS << '\n'; + return true; } struct AMDNote { @@ -5030,15 +5032,20 @@ // Print the description, or fallback to printing raw bytes for unknown // owners. if (Name == "GNU") { - printGNUNote(OS, Type, Descriptor); + if (printGNUNote(OS, Type, Descriptor)) + return; } else if (Name == "AMD") { const AMDNote N = getAMDNote(Type, Descriptor); - if (!N.Type.empty()) + if (!N.Type.empty()) { OS << " " << N.Type << ":\n " << N.Value << '\n'; + return; + } } else if (Name == "AMDGPU") { const AMDGPUNote N = getAMDGPUNote(Type, Descriptor); - if (!N.Type.empty()) + if (!N.Type.empty()) { OS << " " << N.Type << ":\n " << N.Value << '\n'; + return; + } } else if (Name == "CORE") { if (Type == ELF::NT_FILE) { DataExtractor DescExtractor(Descriptor, @@ -5049,8 +5056,10 @@ printCoreNote(OS, *Note); else reportWarning(Note.takeError(), this->FileName); + return; } - } else if (!Descriptor.empty()) { + } + if (!Descriptor.empty()) { OS << " Description data:"; for (uint8_t B : Descriptor) OS << " " << format("%02x", B); @@ -6172,15 +6181,16 @@ } template -static void printGNUNoteLLVMStyle(uint32_t NoteType, ArrayRef Desc, +static bool printGNUNoteLLVMStyle(uint32_t NoteType, ArrayRef Desc, ScopedPrinter &W) { switch (NoteType) { default: - return; + return false; case ELF::NT_GNU_ABI_TAG: { const GNUAbiTag &AbiTag = getGNUAbiTag(Desc); if (!AbiTag.IsValid) { W.printString("ABI", ""); + return false; } else { W.printString("OS", AbiTag.OSName); W.printString("ABI", AbiTag.ABI); @@ -6200,6 +6210,7 @@ W.printString(Property); break; } + return true; } static void printCoreNoteLLVMStyle(const CoreNote &Note, ScopedPrinter &W) { @@ -6254,15 +6265,20 @@ // Print the description, or fallback to printing raw bytes for unknown // owners. if (Name == "GNU") { - printGNUNoteLLVMStyle(Type, Descriptor, W); + if (printGNUNoteLLVMStyle(Type, Descriptor, W)) + return; } else if (Name == "AMD") { const AMDNote N = getAMDNote(Type, Descriptor); - if (!N.Type.empty()) + if (!N.Type.empty()) { W.printString(N.Type, N.Value); + return; + } } else if (Name == "AMDGPU") { const AMDGPUNote N = getAMDGPUNote(Type, Descriptor); - if (!N.Type.empty()) + if (!N.Type.empty()) { W.printString(N.Type, N.Value); + return; + } } else if (Name == "CORE") { if (Type == ELF::NT_FILE) { DataExtractor DescExtractor(Descriptor, @@ -6273,8 +6289,10 @@ printCoreNoteLLVMStyle(*Note, W); else reportWarning(Note.takeError(), this->FileName); + return; } - } else if (!Descriptor.empty()) { + } + if (!Descriptor.empty()) { W.printBinaryBlock("Description data", Descriptor); } };