diff --git a/llvm/test/tools/llvm-readobj/ELF/note-amd.s b/llvm/test/tools/llvm-readobj/ELF/note-amd.s --- a/llvm/test/tools/llvm-readobj/ELF/note-amd.s +++ b/llvm/test/tools/llvm-readobj/ELF/note-amd.s @@ -8,10 +8,11 @@ // GNU-NEXT: Owner Data size Description // GNU-NEXT: AMD 0x00000000 NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata) // GNU-NEXT: HSA Metadata: -// GNU-NEXT: {{^ +$}} +// GNU-NEXT: {{^ $}} // GNU-NEXT: AMD 0x00000000 NT_AMD_AMDGPU_ISA (ISA Version) // GNU-NEXT: ISA Version: -// GNU-NEXT: {{^ +$}} +// GNU-NEXT: {{^ $}} +// GNU-EMPTY: // GNU-NEXT: Displaying notes found in: .note.desc // GNU-NEXT: Owner Data size Description // GNU-NEXT: AMD 0x0000000a NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata) @@ -20,9 +21,11 @@ // GNU-NEXT: AMD 0x00000009 NT_AMD_AMDGPU_ISA (ISA Version) // GNU-NEXT: ISA Version: // GNU-NEXT: isa_blah +// GNU-EMPTY: // GNU-NEXT: Displaying notes found in: .note.other // GNU-NEXT: Owner Data size Description // GNU-NEXT: AMD 0x00000000 NT_AMD_AMDGPU_PAL_METADATA (PAL Metadata) +// GNU-EMPTY: // LLVM: Notes [ // LLVM-NEXT: NoteSection { diff --git a/llvm/test/tools/llvm-readobj/ELF/note-amdgpu-invalid.s b/llvm/test/tools/llvm-readobj/ELF/note-amdgpu-invalid.s --- a/llvm/test/tools/llvm-readobj/ELF/note-amdgpu-invalid.s +++ b/llvm/test/tools/llvm-readobj/ELF/note-amdgpu-invalid.s @@ -20,6 +20,7 @@ # GNU-NEXT: .vgpr_count: 7 # GNU-NEXT: .wavefront_size: 5 # GNU-NEXT: ... +# GNU-EMPTY: # LLVM: Notes [ # LLVM-NEXT: NoteSection { diff --git a/llvm/test/tools/llvm-readobj/ELF/note-core-ntfile.test b/llvm/test/tools/llvm-readobj/ELF/note-core-ntfile.test --- a/llvm/test/tools/llvm-readobj/ELF/note-core-ntfile.test +++ b/llvm/test/tools/llvm-readobj/ELF/note-core-ntfile.test @@ -60,7 +60,7 @@ # GNU-NEXT: /path/to/libc.so # GNU-NEXT: 0x0000000000007000 0x0000000000008000 0x0000000000009000 # GNU-NEXT: [stack] -# GNU-NOT: {{.}} +# GNU-EMPTY: # LLVM: Notes [ # LLVM-NEXT: NoteSection { diff --git a/llvm/test/tools/llvm-readobj/ELF/note-core.test b/llvm/test/tools/llvm-readobj/ELF/note-core.test --- a/llvm/test/tools/llvm-readobj/ELF/note-core.test +++ b/llvm/test/tools/llvm-readobj/ELF/note-core.test @@ -252,6 +252,7 @@ # CHECK-GNU: Owner Data size Description # CHECK-GNU-NEXT: CORE 0x00000000 [[DESC]] +# CHECK-GNU-EMPTY: # CHECK-LLVM: Note { # CHECK-LLVM-NEXT: Owner: CORE diff --git a/llvm/test/tools/llvm-readobj/ELF/note-freebsd.s b/llvm/test/tools/llvm-readobj/ELF/note-freebsd.s --- a/llvm/test/tools/llvm-readobj/ELF/note-freebsd.s +++ b/llvm/test/tools/llvm-readobj/ELF/note-freebsd.s @@ -8,13 +8,16 @@ // GNU-NEXT: Owner Data size Description // GNU-NEXT: FreeBSD 0x00000000 NT_THRMISC (thrmisc structure) // GNU-NEXT: FreeBSD 0x00000000 NT_PROCSTAT_PROC (proc data) +// GNU-EMPTY: // GNU-NEXT: Displaying notes found in: .note.bar // GNU-NEXT: Owner Data size Description // GNU-NEXT: FreeBSD 0x00000000 NT_PROCSTAT_FILES (files data) +// GNU-EMPTY: // GNU-NEXT: Displaying notes found in: .note.baz // GNU-NEXT: Owner Data size Description // GNU-NEXT: FreeBSD 0x0000001c Unknown note type: (0x00000003) // GNU-NEXT: description data: 4c 6f 72 65 6d 20 69 70 73 75 6d 20 64 6f 6c 6f 72 20 73 69 74 20 61 6d 65 74 00 00 +// GNU-EMPTY: // LLVM: Notes [ // LLVM-NEXT: NoteSection { diff --git a/llvm/test/tools/llvm-readobj/ELF/note-generic.s b/llvm/test/tools/llvm-readobj/ELF/note-generic.s --- a/llvm/test/tools/llvm-readobj/ELF/note-generic.s +++ b/llvm/test/tools/llvm-readobj/ELF/note-generic.s @@ -1,24 +1,24 @@ // REQUIRES: x86-registered-target // RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o %t.o -// RUN: llvm-readobj --notes %t.o | FileCheck %s --check-prefix=LLVM -// RUN: llvm-readelf --notes %t.o | FileCheck %s --check-prefix=GNU +// RUN: llvm-readobj --notes %t.o | FileCheck %s --check-prefix=LLVM --strict-whitespace +// RUN: llvm-readelf --notes %t.o | FileCheck %s --check-prefix=GNU --strict-whitespace -// GNU: Displaying notes found in: .note.version -// GNU-NEXT: Owner Data size Description -// GNU-NEXT: XYZ 0x00000000 NT_VERSION (version) - -// GNU: Displaying notes found in: .note.arch -// GNU-NEXT: Owner Data size Description -// GNU-NEXT: XYZ 0x00000000 NT_ARCH (architecture) - -// GNU: Displaying notes found in: .note.open -// GNU-NEXT: Owner Data size Description -// GNU-NEXT: XYZ 0x00000000 OPEN - -// GNU: Displaying notes found in: .note.func -// GNU-NEXT: Owner Data size Description -// GNU-NEXT: XYZ 0x00000000 func +// GNU: Displaying notes found in: .note.version{{$}} +// GNU-NEXT: Owner Data size Description +// GNU-NEXT: XYZ 0x00000000 NT_VERSION (version) +// GNU-EMPTY: +// GNU-NEXT: Displaying notes found in: .note.arch{{$}} +// GNU-NEXT: Owner Data size Description +// GNU-NEXT: XYZ 0x00000000 NT_ARCH (architecture) +// GNU-EMPTY: +// GNU-NEXT: Displaying notes found in: .note.open{{$}} +// GNU-NEXT: Owner Data size Description +// GNU-NEXT: XYZ 0x00000000 OPEN +// GNU-EMPTY: +// GNU-NEXT: Displaying notes found in: .note.func{{$}} +// GNU-NEXT: Owner Data size Description +// GNU-NEXT: XYZ 0x00000000 func // LLVM: Notes [ // LLVM-NEXT: NoteSection { diff --git a/llvm/test/tools/llvm-readobj/ELF/note-unknown.s b/llvm/test/tools/llvm-readobj/ELF/note-unknown.s --- a/llvm/test/tools/llvm-readobj/ELF/note-unknown.s +++ b/llvm/test/tools/llvm-readobj/ELF/note-unknown.s @@ -7,10 +7,12 @@ // GNU: Displaying notes found in: .note.foo // GNU-NEXT: Owner Data size Description // GNU-NEXT: XYZ 0x00000000 Unknown note type: (0x00000003) +// GNU-EMPTY: // GNU-NEXT: Displaying notes found in: .note.bar // GNU-NEXT: Owner Data size Description // GNU-NEXT: XYZ 0x0000001c Unknown note type: (0x00000003) // GNU-NEXT: description data: 4c 6f 72 65 6d 20 69 70 73 75 6d 20 64 6f 6c 6f 72 20 73 69 74 20 61 6d 65 74 00 00 +// GNU-EMPTY: // LLVM: Notes [ // LLVM-NEXT: NoteSection { 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 @@ -5232,9 +5232,17 @@ } template void GNUELFDumper::printNotes() { + bool IsFirstHeader = true; auto PrintHeader = [&](Optional SecName, const typename ELFT::Off Offset, const typename ELFT::Addr Size) { + // Print a newline between notes sections to match GNU readelf. + if (!IsFirstHeader) { + OS << '\n'; + } else { + IsFirstHeader = false; + } + OS << "Displaying notes found "; if (SecName)