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,8 @@ # GNU: Owner Data size Description # GNU-NEXT: GNU 0x00000004 NT_GNU_ABI_TAG (ABI version tag) # GNU-NEXT: +# GNU-NEXT: description data: 00 00 00 00 +# GNU-EMPTY: # LLVM: Notes [ # LLVM-NEXT: NoteSection { @@ -15,6 +17,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/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 @@ -5117,17 +5117,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 false; + } + OS << " OS: " << AbiTag.OSName << ", ABI: " << AbiTag.ABI; break; } case ELF::NT_GNU_BUILD_ID: { @@ -5144,6 +5145,7 @@ break; } OS << '\n'; + return true; } struct AMDNote { @@ -5307,15 +5309,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, @@ -5326,8 +5333,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); @@ -6448,15 +6457,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); @@ -6476,6 +6486,7 @@ W.printString(Property); break; } + return true; } static void printCoreNoteLLVMStyle(const CoreNote &Note, ScopedPrinter &W) { @@ -6530,15 +6541,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, @@ -6549,8 +6565,10 @@ printCoreNoteLLVMStyle(*Note, W); else reportWarning(Note.takeError(), this->FileName); + return; } - } else if (!Descriptor.empty()) { + } + if (!Descriptor.empty()) { W.printBinaryBlock("Description data", Descriptor); } };