[llvm] Reland "[ObjectYAML][ELF] Take alignment into account when generating notes" (PR #118434)

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 4 07:47:44 PST 2024


https://github.com/igorkudrin updated https://github.com/llvm/llvm-project/pull/118434

>From 10ee40ac091f2c363892160874fc023d297a7fc8 Mon Sep 17 00:00:00 2001
From: Igor Kudrin <ikudrin at accesssoftek.com>
Date: Tue, 3 Dec 2024 08:58:48 +0700
Subject: [PATCH 1/4] Reland "[ObjectYAML][ELF] Take alignment into account
 when generating notes"

This relands #118157 with a fix for the use of an uninitialised variable.

The [System V ABI](https://www.sco.com/developers/gabi/latest/ch5.pheader.html#note_section)
states that the note entries and their descriptor fields must be aligned
to 4 or 8 bytes for 32-bit or 64-bit objects respectively. In practice,
64-bit systems can use both alignments, with the actual format being
determined by the alignment of the segment. For example, the
[Linux gABI extension](https://github.com/hjl-tools/linux-abi/wiki/linux-abi-draft.pdf)
contains a special note on this, see 2.1.7 "Alignment of Note Sections".

This patch adjusts the format of the generated notes to the specified
section alignment. Since `llvm-readobj` was fixed in a similar way in
[D150022](https://reviews.llvm.org/D150022), "[Object] Fix handling of
Elf_Nhdr with sh_addralign=8", the generated notes can now be parsed
successfully by the tool.
---
 llvm/lib/ObjectYAML/ELFEmitter.cpp            |  20 ++-
 .../test/tools/yaml2obj/ELF/note-section.yaml | 129 ++++++++++++++++++
 2 files changed, 147 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index 476334024151a9..5833d100656ede 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -1799,6 +1799,21 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
   if (!Section.Notes)
     return;
 
+  unsigned Align;
+  switch (SHeader.sh_addralign) {
+  case 0:
+  case 4:
+    Align = 4;
+    break;
+  case 8:
+    Align = 8;
+    break;
+  default:
+    reportError(Section.Name + ": invalid alignment for a note section: 0x" +
+                Twine::utohexstr(SHeader.sh_addralign));
+    return;
+  }
+
   uint64_t Offset = CBA.tell();
   for (const ELFYAML::NoteEntry &NE : *Section.Notes) {
     // Write name size.
@@ -1820,14 +1835,15 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
     if (!NE.Name.empty()) {
       CBA.write(NE.Name.data(), NE.Name.size());
       CBA.write('\0');
-      CBA.padToAlignment(4);
     }
 
     // Write description and padding.
     if (NE.Desc.binary_size() != 0) {
+      CBA.padToAlignment(Align);
       CBA.writeAsBinary(NE.Desc);
-      CBA.padToAlignment(4);
     }
+
+    CBA.padToAlignment(Align);
   }
 
   SHeader.sh_size = CBA.tell() - Offset;
diff --git a/llvm/test/tools/yaml2obj/ELF/note-section.yaml b/llvm/test/tools/yaml2obj/ELF/note-section.yaml
index 80359c4ec01833..26b95e1c2379b2 100644
--- a/llvm/test/tools/yaml2obj/ELF/note-section.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/note-section.yaml
@@ -333,3 +333,132 @@ Sections:
       - Name: ABC
         Desc: '123456'
         Type: NT_VERSION
+
+## Check that an incorrect alignment is reported
+
+# RUN: not yaml2obj --docnum=16 %s 2>&1 | FileCheck %s --check-prefix=ERR_ALIGN1
+# ERR_ALIGN1: error: .note.foo: invalid alignment for a note section: 0x1
+
+--- !ELF
+FileHeader:
+  Class: ELFCLASS64
+  Data:  ELFDATA2LSB
+  Type:  ET_EXEC
+Sections:
+  - Name:         .note.foo
+    Type:         SHT_NOTE
+    AddressAlign: 1
+    Notes:
+      - Type: 0x1
+
+## Check that note entries and their `Desc` fields are aligned according to the
+## specified section alignment
+
+# RUN: yaml2obj --docnum=17 %s -o - | \
+# RUN:   llvm-readobj --sections --section-data --notes - | \
+# RUN:   FileCheck %s --check-prefix=TEST17
+
+# TEST17:      Name: .note.foo4
+# TEST17:      SectionData (
+# TEST17-NEXT:   0000: 05000000 02000000 01000000 41424344  |............ABCD|
+# TEST17-NEXT:   0010: 00000000 01020000 00000000 03000000  |................|
+# TEST17-NEXT:   0020: 02000000 03040500 04000000 00000000  |................|
+# TEST17-NEXT:   0030: 03000000 474E5500                    |....GNU.|
+# TEST17-NEXT: )
+# TEST17:      Name: .note.foo8
+# TEST17:      SectionData (
+# TEST17-NEXT:   0000: 05000000 02000000 01000000 41424344  |............ABCD|
+# TEST17-NEXT:   0010: 00000000 00000000 01020000 00000000  |................|
+# TEST17-NEXT:   0020: 00000000 03000000 02000000 00000000  |................|
+# TEST17-NEXT:   0030: 03040500 00000000 04000000 00000000  |................|
+# TEST17-NEXT:   0040: 03000000 474E5500                    |....GNU.|
+# TEST17-NEXT: )
+# TEST17:      NoteSections [
+# TEST17-NEXT:   NoteSection {
+# TEST17-NEXT:     Name: .note.foo4
+# TEST17-NEXT:     Offset:
+# TEST17-NEXT:     Size:
+# TEST17-NEXT:     Notes [
+# TEST17-NEXT:       {
+# TEST17-NEXT:         Owner: ABCD
+# TEST17-NEXT:         Data size: 0x2
+# TEST17-NEXT:         Type: NT_VERSION (version)
+# TEST17-NEXT:         Description data (
+# TEST17-NEXT:           0000: 0102                                 |..|
+# TEST17-NEXT:         )
+# TEST17-NEXT:       }
+# TEST17-NEXT:       {
+# TEST17-NEXT:         Owner: 
+# TEST17-NEXT:         Data size: 0x3
+# TEST17-NEXT:         Type: NT_ARCH (architecture)
+# TEST17-NEXT:         Description data (
+# TEST17-NEXT:           0000: 030405                               |...|
+# TEST17-NEXT:         )
+# TEST17-NEXT:       }
+# TEST17-NEXT:       {
+# TEST17-NEXT:         Owner: GNU
+# TEST17-NEXT:         Data size: 0x0
+# TEST17-NEXT:         Type: NT_GNU_BUILD_ID (unique build ID bitstring)
+# TEST17-NEXT:         Build ID: 
+# TEST17-NEXT:       }
+# TEST17-NEXT:     ]
+# TEST17-NEXT:   }
+# TEST17-NEXT:   NoteSection {
+# TEST17-NEXT:     Name: .note.foo8
+# TEST17-NEXT:     Offset:
+# TEST17-NEXT:     Size:
+# TEST17-NEXT:     Notes [
+# TEST17-NEXT:       {
+# TEST17-NEXT:         Owner: ABCD
+# TEST17-NEXT:         Data size: 0x2
+# TEST17-NEXT:         Type: NT_VERSION (version)
+# TEST17-NEXT:         Description data (
+# TEST17-NEXT:           0000: 0102                                 |..|
+# TEST17-NEXT:         )
+# TEST17-NEXT:       }
+# TEST17-NEXT:       {
+# TEST17-NEXT:         Owner: 
+# TEST17-NEXT:         Data size: 0x3
+# TEST17-NEXT:         Type: NT_ARCH (architecture)
+# TEST17-NEXT:         Description data (
+# TEST17-NEXT:           0000: 030405                               |...|
+# TEST17-NEXT:         )
+# TEST17-NEXT:       }
+# TEST17-NEXT:       {
+# TEST17-NEXT:         Owner: GNU
+# TEST17-NEXT:         Data size: 0x0
+# TEST17-NEXT:         Type: NT_GNU_BUILD_ID (unique build ID bitstring)
+# TEST17-NEXT:         Build ID: 
+# TEST17-NEXT:       }
+# TEST17-NEXT:     ]
+# TEST17-NEXT:   }
+# TEST17-NEXT: ]
+
+--- !ELF
+FileHeader:
+  Class: ELFCLASS64
+  Data:  ELFDATA2LSB
+  Type:  ET_EXEC
+Sections:
+  - Name:         .note.foo4
+    Type:         SHT_NOTE
+    AddressAlign: 4
+    Notes:
+      - Name: ABCD
+        Type: NT_VERSION
+        Desc: 0102
+      - Type: NT_ARCH
+        Desc: 030405
+      - Name: GNU
+        Type: NT_GNU_BUILD_ID
+  - Name:        .note.foo8
+    Type:         SHT_NOTE
+    AddressAlign: 8
+    Notes:
+      - Name: ABCD
+        Type: NT_VERSION
+        Desc: 0102
+      - Type: NT_ARCH
+        Desc: 030405
+      - Name: GNU
+        Type: NT_GNU_BUILD_ID

>From ca33510020e885384d436d1515b7359c6b31caa1 Mon Sep 17 00:00:00 2001
From: Igor Kudrin <ikudrin at accesssoftek.com>
Date: Tue, 3 Dec 2024 12:28:28 -0800
Subject: [PATCH 2/4] fixup: 'SHeader.sh_addralign' -> 'Section.AddressAlign'

---
 llvm/lib/ObjectYAML/ELFEmitter.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index 5833d100656ede..5daf6c32ec936a 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -1800,7 +1800,7 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
     return;
 
   unsigned Align;
-  switch (SHeader.sh_addralign) {
+  switch (Section.AddressAlign) {
   case 0:
   case 4:
     Align = 4;
@@ -1810,7 +1810,7 @@ void ELFState<ELFT>::writeSectionContent(Elf_Shdr &SHeader,
     break;
   default:
     reportError(Section.Name + ": invalid alignment for a note section: 0x" +
-                Twine::utohexstr(SHeader.sh_addralign));
+                Twine::utohexstr(Section.AddressAlign));
     return;
   }
 

>From 5df8895f6ece3f87bbb1a154a762a67ce5636048 Mon Sep 17 00:00:00 2001
From: Igor Kudrin <ikudrin at accesssoftek.com>
Date: Tue, 3 Dec 2024 12:29:10 -0800
Subject: [PATCH 3/4] fixup: Add a test for 32-bit ELF

---
 .../test/tools/yaml2obj/ELF/note-section.yaml | 191 ++++++++++--------
 1 file changed, 112 insertions(+), 79 deletions(-)

diff --git a/llvm/test/tools/yaml2obj/ELF/note-section.yaml b/llvm/test/tools/yaml2obj/ELF/note-section.yaml
index 26b95e1c2379b2..1f62da30fcbba9 100644
--- a/llvm/test/tools/yaml2obj/ELF/note-section.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/note-section.yaml
@@ -334,7 +334,7 @@ Sections:
         Desc: '123456'
         Type: NT_VERSION
 
-## Check that an incorrect alignment is reported
+## Check that an incorrect alignment is reported.
 
 # RUN: not yaml2obj --docnum=16 %s 2>&1 | FileCheck %s --check-prefix=ERR_ALIGN1
 # ERR_ALIGN1: error: .note.foo: invalid alignment for a note section: 0x1
@@ -352,87 +352,91 @@ Sections:
       - Type: 0x1
 
 ## Check that note entries and their `Desc` fields are aligned according to the
-## specified section alignment
+## specified section alignment.
 
 # RUN: yaml2obj --docnum=17 %s -o - | \
 # RUN:   llvm-readobj --sections --section-data --notes - | \
-# RUN:   FileCheck %s --check-prefix=TEST17
-
-# TEST17:      Name: .note.foo4
-# TEST17:      SectionData (
-# TEST17-NEXT:   0000: 05000000 02000000 01000000 41424344  |............ABCD|
-# TEST17-NEXT:   0010: 00000000 01020000 00000000 03000000  |................|
-# TEST17-NEXT:   0020: 02000000 03040500 04000000 00000000  |................|
-# TEST17-NEXT:   0030: 03000000 474E5500                    |....GNU.|
-# TEST17-NEXT: )
-# TEST17:      Name: .note.foo8
-# TEST17:      SectionData (
-# TEST17-NEXT:   0000: 05000000 02000000 01000000 41424344  |............ABCD|
-# TEST17-NEXT:   0010: 00000000 00000000 01020000 00000000  |................|
-# TEST17-NEXT:   0020: 00000000 03000000 02000000 00000000  |................|
-# TEST17-NEXT:   0030: 03040500 00000000 04000000 00000000  |................|
-# TEST17-NEXT:   0040: 03000000 474E5500                    |....GNU.|
-# TEST17-NEXT: )
-# TEST17:      NoteSections [
-# TEST17-NEXT:   NoteSection {
-# TEST17-NEXT:     Name: .note.foo4
-# TEST17-NEXT:     Offset:
-# TEST17-NEXT:     Size:
-# TEST17-NEXT:     Notes [
-# TEST17-NEXT:       {
-# TEST17-NEXT:         Owner: ABCD
-# TEST17-NEXT:         Data size: 0x2
-# TEST17-NEXT:         Type: NT_VERSION (version)
-# TEST17-NEXT:         Description data (
-# TEST17-NEXT:           0000: 0102                                 |..|
-# TEST17-NEXT:         )
-# TEST17-NEXT:       }
-# TEST17-NEXT:       {
-# TEST17-NEXT:         Owner: 
-# TEST17-NEXT:         Data size: 0x3
-# TEST17-NEXT:         Type: NT_ARCH (architecture)
-# TEST17-NEXT:         Description data (
-# TEST17-NEXT:           0000: 030405                               |...|
-# TEST17-NEXT:         )
-# TEST17-NEXT:       }
-# TEST17-NEXT:       {
-# TEST17-NEXT:         Owner: GNU
-# TEST17-NEXT:         Data size: 0x0
-# TEST17-NEXT:         Type: NT_GNU_BUILD_ID (unique build ID bitstring)
-# TEST17-NEXT:         Build ID: 
-# TEST17-NEXT:       }
-# TEST17-NEXT:     ]
-# TEST17-NEXT:   }
-# TEST17-NEXT:   NoteSection {
-# TEST17-NEXT:     Name: .note.foo8
-# TEST17-NEXT:     Offset:
-# TEST17-NEXT:     Size:
-# TEST17-NEXT:     Notes [
-# TEST17-NEXT:       {
-# TEST17-NEXT:         Owner: ABCD
-# TEST17-NEXT:         Data size: 0x2
-# TEST17-NEXT:         Type: NT_VERSION (version)
-# TEST17-NEXT:         Description data (
-# TEST17-NEXT:           0000: 0102                                 |..|
-# TEST17-NEXT:         )
-# TEST17-NEXT:       }
-# TEST17-NEXT:       {
-# TEST17-NEXT:         Owner: 
-# TEST17-NEXT:         Data size: 0x3
-# TEST17-NEXT:         Type: NT_ARCH (architecture)
-# TEST17-NEXT:         Description data (
-# TEST17-NEXT:           0000: 030405                               |...|
-# TEST17-NEXT:         )
-# TEST17-NEXT:       }
-# TEST17-NEXT:       {
-# TEST17-NEXT:         Owner: GNU
-# TEST17-NEXT:         Data size: 0x0
-# TEST17-NEXT:         Type: NT_GNU_BUILD_ID (unique build ID bitstring)
-# TEST17-NEXT:         Build ID: 
-# TEST17-NEXT:       }
-# TEST17-NEXT:     ]
-# TEST17-NEXT:   }
-# TEST17-NEXT: ]
+# RUN:   FileCheck %s --check-prefix=TEST1718
+
+# RUN: yaml2obj --docnum=18 %s -o - | \
+# RUN:   llvm-readobj --sections --section-data --notes - | \
+# RUN:   FileCheck %s --check-prefix=TEST1718
+
+# TEST1718:      Name: .note.foo4
+# TEST1718:      SectionData (
+# TEST1718-NEXT:   0000: 05000000 02000000 01000000 41424344  |............ABCD|
+# TEST1718-NEXT:   0010: 00000000 01020000 00000000 03000000  |................|
+# TEST1718-NEXT:   0020: 02000000 03040500 04000000 00000000  |................|
+# TEST1718-NEXT:   0030: 03000000 474E5500                    |....GNU.|
+# TEST1718-NEXT: )
+# TEST1718:      Name: .note.foo8
+# TEST1718:      SectionData (
+# TEST1718-NEXT:   0000: 05000000 02000000 01000000 41424344  |............ABCD|
+# TEST1718-NEXT:   0010: 00000000 00000000 01020000 00000000  |................|
+# TEST1718-NEXT:   0020: 00000000 03000000 02000000 00000000  |................|
+# TEST1718-NEXT:   0030: 03040500 00000000 04000000 00000000  |................|
+# TEST1718-NEXT:   0040: 03000000 474E5500                    |....GNU.|
+# TEST1718-NEXT: )
+# TEST1718:      NoteSections [
+# TEST1718-NEXT:   NoteSection {
+# TEST1718-NEXT:     Name: .note.foo4
+# TEST1718-NEXT:     Offset:
+# TEST1718-NEXT:     Size:
+# TEST1718-NEXT:     Notes [
+# TEST1718-NEXT:       {
+# TEST1718-NEXT:         Owner: ABCD
+# TEST1718-NEXT:         Data size: 0x2
+# TEST1718-NEXT:         Type: NT_VERSION (version)
+# TEST1718-NEXT:         Description data (
+# TEST1718-NEXT:           0000: 0102                                 |..|
+# TEST1718-NEXT:         )
+# TEST1718-NEXT:       }
+# TEST1718-NEXT:       {
+# TEST1718-NEXT:         Owner: 
+# TEST1718-NEXT:         Data size: 0x3
+# TEST1718-NEXT:         Type: NT_ARCH (architecture)
+# TEST1718-NEXT:         Description data (
+# TEST1718-NEXT:           0000: 030405                               |...|
+# TEST1718-NEXT:         )
+# TEST1718-NEXT:       }
+# TEST1718-NEXT:       {
+# TEST1718-NEXT:         Owner: GNU
+# TEST1718-NEXT:         Data size: 0x0
+# TEST1718-NEXT:         Type: NT_GNU_BUILD_ID (unique build ID bitstring)
+# TEST1718-NEXT:         Build ID: 
+# TEST1718-NEXT:       }
+# TEST1718-NEXT:     ]
+# TEST1718-NEXT:   }
+# TEST1718-NEXT:   NoteSection {
+# TEST1718-NEXT:     Name: .note.foo8
+# TEST1718-NEXT:     Offset:
+# TEST1718-NEXT:     Size:
+# TEST1718-NEXT:     Notes [
+# TEST1718-NEXT:       {
+# TEST1718-NEXT:         Owner: ABCD
+# TEST1718-NEXT:         Data size: 0x2
+# TEST1718-NEXT:         Type: NT_VERSION (version)
+# TEST1718-NEXT:         Description data (
+# TEST1718-NEXT:           0000: 0102                                 |..|
+# TEST1718-NEXT:         )
+# TEST1718-NEXT:       }
+# TEST1718-NEXT:       {
+# TEST1718-NEXT:         Owner: 
+# TEST1718-NEXT:         Data size: 0x3
+# TEST1718-NEXT:         Type: NT_ARCH (architecture)
+# TEST1718-NEXT:         Description data (
+# TEST1718-NEXT:           0000: 030405                               |...|
+# TEST1718-NEXT:         )
+# TEST1718-NEXT:       }
+# TEST1718-NEXT:       {
+# TEST1718-NEXT:         Owner: GNU
+# TEST1718-NEXT:         Data size: 0x0
+# TEST1718-NEXT:         Type: NT_GNU_BUILD_ID (unique build ID bitstring)
+# TEST1718-NEXT:         Build ID: 
+# TEST1718-NEXT:       }
+# TEST1718-NEXT:     ]
+# TEST1718-NEXT:   }
+# TEST1718-NEXT: ]
 
 --- !ELF
 FileHeader:
@@ -462,3 +466,32 @@ Sections:
         Desc: 030405
       - Name: GNU
         Type: NT_GNU_BUILD_ID
+
+--- !ELF
+FileHeader:
+  Class: ELFCLASS32
+  Data:  ELFDATA2LSB
+  Type:  ET_REL
+Sections:
+  - Name:         .note.foo4
+    Type:         SHT_NOTE
+    AddressAlign: 4
+    Notes:
+      - Name: ABCD
+        Type: NT_VERSION
+        Desc: 0102
+      - Type: NT_ARCH
+        Desc: 030405
+      - Name: GNU
+        Type: NT_GNU_BUILD_ID
+  - Name:        .note.foo8
+    Type:         SHT_NOTE
+    AddressAlign: 8
+    Notes:
+      - Name: ABCD
+        Type: NT_VERSION
+        Desc: 0102
+      - Type: NT_ARCH
+        Desc: 030405
+      - Name: GNU
+        Type: NT_GNU_BUILD_ID

>From f2abc4e6444eba8b15c96fcb4e0b620e71d40baa Mon Sep 17 00:00:00 2001
From: Igor Kudrin <ikudrin at accesssoftek.com>
Date: Wed, 4 Dec 2024 07:47:22 -0800
Subject: [PATCH 4/4] fixup: use `-D ELFCLASS=` and remove the duplicate YAML
 document

---
 .../test/tools/yaml2obj/ELF/note-section.yaml | 191 ++++++++----------
 1 file changed, 81 insertions(+), 110 deletions(-)

diff --git a/llvm/test/tools/yaml2obj/ELF/note-section.yaml b/llvm/test/tools/yaml2obj/ELF/note-section.yaml
index 1f62da30fcbba9..09957f12ff9fe5 100644
--- a/llvm/test/tools/yaml2obj/ELF/note-section.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/note-section.yaml
@@ -354,93 +354,93 @@ Sections:
 ## Check that note entries and their `Desc` fields are aligned according to the
 ## specified section alignment.
 
-# RUN: yaml2obj --docnum=17 %s -o - | \
+# RUN: yaml2obj --docnum=17 -D ELFCLASS=64 %s -o - | \
 # RUN:   llvm-readobj --sections --section-data --notes - | \
-# RUN:   FileCheck %s --check-prefix=TEST1718
+# RUN:   FileCheck %s --check-prefix=TEST17
 
-# RUN: yaml2obj --docnum=18 %s -o - | \
+# RUN: yaml2obj --docnum=17 -D ELFCLASS=32 %s -o - | \
 # RUN:   llvm-readobj --sections --section-data --notes - | \
-# RUN:   FileCheck %s --check-prefix=TEST1718
-
-# TEST1718:      Name: .note.foo4
-# TEST1718:      SectionData (
-# TEST1718-NEXT:   0000: 05000000 02000000 01000000 41424344  |............ABCD|
-# TEST1718-NEXT:   0010: 00000000 01020000 00000000 03000000  |................|
-# TEST1718-NEXT:   0020: 02000000 03040500 04000000 00000000  |................|
-# TEST1718-NEXT:   0030: 03000000 474E5500                    |....GNU.|
-# TEST1718-NEXT: )
-# TEST1718:      Name: .note.foo8
-# TEST1718:      SectionData (
-# TEST1718-NEXT:   0000: 05000000 02000000 01000000 41424344  |............ABCD|
-# TEST1718-NEXT:   0010: 00000000 00000000 01020000 00000000  |................|
-# TEST1718-NEXT:   0020: 00000000 03000000 02000000 00000000  |................|
-# TEST1718-NEXT:   0030: 03040500 00000000 04000000 00000000  |................|
-# TEST1718-NEXT:   0040: 03000000 474E5500                    |....GNU.|
-# TEST1718-NEXT: )
-# TEST1718:      NoteSections [
-# TEST1718-NEXT:   NoteSection {
-# TEST1718-NEXT:     Name: .note.foo4
-# TEST1718-NEXT:     Offset:
-# TEST1718-NEXT:     Size:
-# TEST1718-NEXT:     Notes [
-# TEST1718-NEXT:       {
-# TEST1718-NEXT:         Owner: ABCD
-# TEST1718-NEXT:         Data size: 0x2
-# TEST1718-NEXT:         Type: NT_VERSION (version)
-# TEST1718-NEXT:         Description data (
-# TEST1718-NEXT:           0000: 0102                                 |..|
-# TEST1718-NEXT:         )
-# TEST1718-NEXT:       }
-# TEST1718-NEXT:       {
-# TEST1718-NEXT:         Owner: 
-# TEST1718-NEXT:         Data size: 0x3
-# TEST1718-NEXT:         Type: NT_ARCH (architecture)
-# TEST1718-NEXT:         Description data (
-# TEST1718-NEXT:           0000: 030405                               |...|
-# TEST1718-NEXT:         )
-# TEST1718-NEXT:       }
-# TEST1718-NEXT:       {
-# TEST1718-NEXT:         Owner: GNU
-# TEST1718-NEXT:         Data size: 0x0
-# TEST1718-NEXT:         Type: NT_GNU_BUILD_ID (unique build ID bitstring)
-# TEST1718-NEXT:         Build ID: 
-# TEST1718-NEXT:       }
-# TEST1718-NEXT:     ]
-# TEST1718-NEXT:   }
-# TEST1718-NEXT:   NoteSection {
-# TEST1718-NEXT:     Name: .note.foo8
-# TEST1718-NEXT:     Offset:
-# TEST1718-NEXT:     Size:
-# TEST1718-NEXT:     Notes [
-# TEST1718-NEXT:       {
-# TEST1718-NEXT:         Owner: ABCD
-# TEST1718-NEXT:         Data size: 0x2
-# TEST1718-NEXT:         Type: NT_VERSION (version)
-# TEST1718-NEXT:         Description data (
-# TEST1718-NEXT:           0000: 0102                                 |..|
-# TEST1718-NEXT:         )
-# TEST1718-NEXT:       }
-# TEST1718-NEXT:       {
-# TEST1718-NEXT:         Owner: 
-# TEST1718-NEXT:         Data size: 0x3
-# TEST1718-NEXT:         Type: NT_ARCH (architecture)
-# TEST1718-NEXT:         Description data (
-# TEST1718-NEXT:           0000: 030405                               |...|
-# TEST1718-NEXT:         )
-# TEST1718-NEXT:       }
-# TEST1718-NEXT:       {
-# TEST1718-NEXT:         Owner: GNU
-# TEST1718-NEXT:         Data size: 0x0
-# TEST1718-NEXT:         Type: NT_GNU_BUILD_ID (unique build ID bitstring)
-# TEST1718-NEXT:         Build ID: 
-# TEST1718-NEXT:       }
-# TEST1718-NEXT:     ]
-# TEST1718-NEXT:   }
-# TEST1718-NEXT: ]
+# RUN:   FileCheck %s --check-prefix=TEST17
+
+# TEST17:      Name: .note.foo4
+# TEST17:      SectionData (
+# TEST17-NEXT:   0000: 05000000 02000000 01000000 41424344  |............ABCD|
+# TEST17-NEXT:   0010: 00000000 01020000 00000000 03000000  |................|
+# TEST17-NEXT:   0020: 02000000 03040500 04000000 00000000  |................|
+# TEST17-NEXT:   0030: 03000000 474E5500                    |....GNU.|
+# TEST17-NEXT: )
+# TEST17:      Name: .note.foo8
+# TEST17:      SectionData (
+# TEST17-NEXT:   0000: 05000000 02000000 01000000 41424344  |............ABCD|
+# TEST17-NEXT:   0010: 00000000 00000000 01020000 00000000  |................|
+# TEST17-NEXT:   0020: 00000000 03000000 02000000 00000000  |................|
+# TEST17-NEXT:   0030: 03040500 00000000 04000000 00000000  |................|
+# TEST17-NEXT:   0040: 03000000 474E5500                    |....GNU.|
+# TEST17-NEXT: )
+# TEST17:      NoteSections [
+# TEST17-NEXT:   NoteSection {
+# TEST17-NEXT:     Name: .note.foo4
+# TEST17-NEXT:     Offset:
+# TEST17-NEXT:     Size:
+# TEST17-NEXT:     Notes [
+# TEST17-NEXT:       {
+# TEST17-NEXT:         Owner: ABCD
+# TEST17-NEXT:         Data size: 0x2
+# TEST17-NEXT:         Type: NT_VERSION (version)
+# TEST17-NEXT:         Description data (
+# TEST17-NEXT:           0000: 0102                                 |..|
+# TEST17-NEXT:         )
+# TEST17-NEXT:       }
+# TEST17-NEXT:       {
+# TEST17-NEXT:         Owner: 
+# TEST17-NEXT:         Data size: 0x3
+# TEST17-NEXT:         Type: NT_ARCH (architecture)
+# TEST17-NEXT:         Description data (
+# TEST17-NEXT:           0000: 030405                               |...|
+# TEST17-NEXT:         )
+# TEST17-NEXT:       }
+# TEST17-NEXT:       {
+# TEST17-NEXT:         Owner: GNU
+# TEST17-NEXT:         Data size: 0x0
+# TEST17-NEXT:         Type: NT_GNU_BUILD_ID (unique build ID bitstring)
+# TEST17-NEXT:         Build ID: 
+# TEST17-NEXT:       }
+# TEST17-NEXT:     ]
+# TEST17-NEXT:   }
+# TEST17-NEXT:   NoteSection {
+# TEST17-NEXT:     Name: .note.foo8
+# TEST17-NEXT:     Offset:
+# TEST17-NEXT:     Size:
+# TEST17-NEXT:     Notes [
+# TEST17-NEXT:       {
+# TEST17-NEXT:         Owner: ABCD
+# TEST17-NEXT:         Data size: 0x2
+# TEST17-NEXT:         Type: NT_VERSION (version)
+# TEST17-NEXT:         Description data (
+# TEST17-NEXT:           0000: 0102                                 |..|
+# TEST17-NEXT:         )
+# TEST17-NEXT:       }
+# TEST17-NEXT:       {
+# TEST17-NEXT:         Owner: 
+# TEST17-NEXT:         Data size: 0x3
+# TEST17-NEXT:         Type: NT_ARCH (architecture)
+# TEST17-NEXT:         Description data (
+# TEST17-NEXT:           0000: 030405                               |...|
+# TEST17-NEXT:         )
+# TEST17-NEXT:       }
+# TEST17-NEXT:       {
+# TEST17-NEXT:         Owner: GNU
+# TEST17-NEXT:         Data size: 0x0
+# TEST17-NEXT:         Type: NT_GNU_BUILD_ID (unique build ID bitstring)
+# TEST17-NEXT:         Build ID: 
+# TEST17-NEXT:       }
+# TEST17-NEXT:     ]
+# TEST17-NEXT:   }
+# TEST17-NEXT: ]
 
 --- !ELF
 FileHeader:
-  Class: ELFCLASS64
+  Class: ELFCLASS[[ELFCLASS]]
   Data:  ELFDATA2LSB
   Type:  ET_EXEC
 Sections:
@@ -466,32 +466,3 @@ Sections:
         Desc: 030405
       - Name: GNU
         Type: NT_GNU_BUILD_ID
-
---- !ELF
-FileHeader:
-  Class: ELFCLASS32
-  Data:  ELFDATA2LSB
-  Type:  ET_REL
-Sections:
-  - Name:         .note.foo4
-    Type:         SHT_NOTE
-    AddressAlign: 4
-    Notes:
-      - Name: ABCD
-        Type: NT_VERSION
-        Desc: 0102
-      - Type: NT_ARCH
-        Desc: 030405
-      - Name: GNU
-        Type: NT_GNU_BUILD_ID
-  - Name:        .note.foo8
-    Type:         SHT_NOTE
-    AddressAlign: 8
-    Notes:
-      - Name: ABCD
-        Type: NT_VERSION
-        Desc: 0102
-      - Type: NT_ARCH
-        Desc: 030405
-      - Name: GNU
-        Type: NT_GNU_BUILD_ID



More information about the llvm-commits mailing list