[llvm] 6a0f074 - [obj2yaml][yaml2obj] - Add note-section.yaml tests.

Georgii Rymar via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 24 04:28:33 PDT 2020


Author: Georgii Rymar
Date: 2020-07-24T14:27:54+03:00
New Revision: 6a0f0746aca0620899e59a70e4e60e19a8219c48

URL: https://github.com/llvm/llvm-project/commit/6a0f0746aca0620899e59a70e4e60e19a8219c48
DIFF: https://github.com/llvm/llvm-project/commit/6a0f0746aca0620899e59a70e4e60e19a8219c48.diff

LOG: [obj2yaml][yaml2obj] - Add note-section.yaml tests.

They were a part of D68983, but were lost in the last
diff and were not committed for unknown reason.

I've renamed (from elf-sht-note.yaml) them and fixed
broken formating a few places. Everything else remained
untouched.

Added: 
    llvm/test/tools/obj2yaml/ELF/note-section.yaml
    llvm/test/tools/yaml2obj/ELF/note-section.yaml

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/obj2yaml/ELF/note-section.yaml b/llvm/test/tools/obj2yaml/ELF/note-section.yaml
new file mode 100644
index 000000000000..c6e03145ed64
--- /dev/null
+++ b/llvm/test/tools/obj2yaml/ELF/note-section.yaml
@@ -0,0 +1,98 @@
+## Check how obj2yaml dumps SHT_NOTE sections.
+
+## We can dump the Name, Desc and Type fields when the note section is valid.
+
+# RUN: yaml2obj --docnum=1 %s -o %t1
+# RUN: obj2yaml %t1 | FileCheck %s --check-prefix=VALID
+
+# VALID:      - Name: .note.foo
+# VALID-NEXT:   Type: SHT_NOTE
+# VALID-NEXT:   Notes:
+# VALID-NEXT:    - Name: ''
+# VALID-NEXT:      Desc: ''
+# VALID-NEXT:      Type: 0x00
+# VALID-NEXT: - Name: .note.bar
+# VALID-NEXT:   Type: SHT_NOTE
+# VALID-NEXT:   Notes:
+# VALID-NEXT:     - Name: ABC
+# VALID-NEXT:       Desc: '001122'
+# VALID-NEXT:       Type: 0xAABBCCDD
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_DYN
+  Machine: EM_X86_64
+Sections:
+  - Name: .note.foo
+    Type: SHT_NOTE
+    Size: 12
+  - Name: .note.bar
+    Type: SHT_NOTE
+    Notes:
+      - Name: ABC
+        Desc: '001122'
+        Type: 0xAABBCCDD
+
+## Check we dump hex digit pairs if the note section is invalid.
+
+# RUN: yaml2obj --docnum=2 %s -o %t2
+# RUN: obj2yaml %t2 | FileCheck %s --check-prefix=INVALID
+
+# INVALID:      - Name:    .note.tooShortNote
+# INVALID-NEXT:   Type:    SHT_NOTE
+# INVALID-NEXT:   Content: '0000000000000000000000'
+# INVALID-NEXT: - Name:    .note.tooLongNameSize
+# INVALID-NEXT:   Type:    SHT_NOTE
+# INVALID-NEXT:   Content: 0100000000000000FF00000000
+# INVALID-NEXT: - Name:    .note.tooLongDescSize
+# INVALID-NEXT:   Type:    SHT_NOTE
+# INVALID-NEXT:   Content: 0000000001000000FF00000000
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_DYN
+  Machine: EM_X86_64
+Sections:
+## Content is less than 12 bytes in size.
+## (12 is the size of n_namesz, n_descsz and n_type 4-bytes fields that must always present).
+  - Name: .note.tooShortNote
+    Type: SHT_NOTE
+    Size: 11
+## We can't dump the Name, Desc and Type fields when the
+## content is shorter than the computed size.
+##
+## Too long name size.
+  - Name: .note.tooLongNameSize
+    Type: SHT_NOTE
+    Content: "0100000000000000ff00000000"
+## Too long description size.
+  - Name: .note.tooLongDescSize
+    Type: SHT_NOTE
+    Content: "0000000001000000ff00000000"
+
+## Check we do not crash when dumping a description that has bytes
+## on its bounds that do not fit into signed byte.
+## This is a completely normal case, but we had a crash before.
+
+# RUN: yaml2obj --docnum=3 %s -o %t3
+# RUN: obj2yaml %t3 | FileCheck %s --check-prefix=HEX-DESC
+
+# HEX-DESC: Desc: FE0000FE
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2MSB
+  Type:    ET_DYN
+  Machine: EM_MIPS
+Sections:
+  - Name:  .note.tag
+    Type:  SHT_NOTE
+    Flags: [ SHF_ALLOC ]
+    Notes:
+      - Desc: 'FE0000FE'
+        Type: 0

diff  --git a/llvm/test/tools/yaml2obj/ELF/note-section.yaml b/llvm/test/tools/yaml2obj/ELF/note-section.yaml
new file mode 100644
index 000000000000..4ea6fcaef8a4
--- /dev/null
+++ b/llvm/test/tools/yaml2obj/ELF/note-section.yaml
@@ -0,0 +1,317 @@
+## Check how yaml2obj produces SHT_NOTE sections.
+
+## Check we can describe SHT_NOTE using the "Notes" tag. We can define
+## notes using names, descriptions and types.
+## Check we produce a valid name size and description size fields.
+## Check we produce valid paddings.
+
+# RUN: yaml2obj --docnum=1 %s -o %t1
+# RUN: llvm-readobj --sections --section-data %t1 | FileCheck %s --check-prefix=NOTE
+
+# NOTE:      Section {
+# NOTE:        Index: 1
+# NOTE-NEXT:   Name: .note.foo (1)
+# NOTE-NEXT:   Type: SHT_NOTE (0x7)
+# NOTE-NEXT:   Flags [ (0x2)
+# NOTE-NEXT:     SHF_ALLOC (0x2)
+# NOTE-NEXT:   ]
+# NOTE-NEXT:   Address:
+# NOTE-NEXT:   Offset:
+# NOTE-NEXT:   Size: 36
+# NOTE-NEXT:   Link: 0
+# NOTE-NEXT:   Info: 0
+# NOTE-NEXT:   AddressAlignment: 0
+# NOTE-NEXT:   EntrySize: 0
+# NOTE-NEXT:   SectionData (
+## namesz == (0x03000000) == sizeof("AB") + NUL terminator.
+## descsz == (0x00000000) for an empty description.
+## Check we produce a valid 2 bytes zeroes padding after the Name.
+# NOTE-NEXT:     0000: 03000000 00000000 FF000000 41420000  |............AB..|
+## namesz == (0x04000000) == sizeof("ABC") + NUL terminator.
+## descsz == (0x06000000) == sizeof("123456").
+## Check we produce a valid (zero align to 4) 1 byte padding after the Name.
+## Check we produce a valid (zero align to 4) 2 bytes padding after the Desc.
+# NOTE-NEXT:     0010: 04000000 03000000 FE000000 41424300  |............ABC.|
+# NOTE-NEXT:     0020: 12345600                             |.4V.|
+# NOTE-NEXT:   )
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_X86_64
+Sections:
+  - Name:  .note.foo
+    Type:  SHT_NOTE
+    Flags: [ SHF_ALLOC ]
+    Notes:
+      - Name: AB
+        Desc: ''
+        Type: 0xFF
+      - Name: ABC
+        Desc: '123456'
+        Type: 254
+
+## Check that for 32-bit little-endian case we produce the same section content.
+
+# RUN: yaml2obj --docnum=2 %s -o %t2
+# RUN: llvm-readobj --sections --section-data %t2 | FileCheck %s --check-prefix=NOTE
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_386
+Sections:
+  - Name:  .note.foo
+    Type:  SHT_NOTE
+    Flags: [ SHF_ALLOC ]
+    Notes:
+      - Name: AB
+        Desc: ''
+        Type: 0xFF
+      - Name: ABC
+        Desc: '123456'
+        Type: 254
+
+## Check big-endian 32/64 bit cases.
+## Check they produce the same content.
+
+# RUN: yaml2obj --docnum=3 %s -o %t3
+# RUN: llvm-readobj --sections --section-data %t3 | FileCheck %s --check-prefix=NOTE-BE
+# RUN: yaml2obj --docnum=4 %s -o %t4
+# RUN: llvm-readobj --sections --section-data %t4 | FileCheck %s --check-prefix=NOTE-BE
+
+# NOTE-BE:      Name: .note.foo
+# NOTE-BE:      SectionData (
+# NOTE-BE-NEXT:   0000: 00000004 00000003 000000FE 41424300  |
+# NOTE-BE-NEXT:   0010: 12345600                             |
+# NOTE-BE-NEXT: )
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:    ELFDATA2MSB
+  Type:    ET_REL
+  Machine: EM_MIPS
+Sections:
+  - Name: .note.foo
+    Type: SHT_NOTE
+    Notes:
+      - Name: ABC
+        Desc: '123456'
+        Type: 254
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2MSB
+  Type:    ET_REL
+  Machine: EM_MIPS
+Sections:
+  - Name: .note.foo
+    Type: SHT_NOTE
+    Notes:
+      - Name: ABC
+        Desc: '123456'
+        Type: 254
+
+## Check that 'Type' field is mandatory. 
+
+# RUN: not yaml2obj --docnum=5 %s 2>&1 | FileCheck %s --check-prefix=TYPE-REQ
+# TYPE-REQ: error: missing required key 'Type'
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_X86_64
+Sections:
+  - Name: .note.foo
+    Type: SHT_NOTE
+    Notes:
+      - Name: ''
+        Desc: ''
+
+## Check that neither `Name` nor `Desc` are mandatory fields.
+
+# RUN: yaml2obj --docnum=6 %s -o %t6
+# RUN: llvm-readobj --sections --section-data %t6 | FileCheck %s --check-prefix=NAME-DESC
+
+# NAME-DESC:      Name: .note.foo
+# NAME-DESC:      SectionData (
+# NAME-DESC-NEXT:   0000: 00000000 00000000 FF000000 |
+# NAME-DESC-NEXT: )
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_X86_64
+Sections:
+  - Name: .note.foo
+    Type: SHT_NOTE
+    Notes:
+      - Type: 0xFF
+
+## Check we can use the "Content" tag to specify any data for SHT_NOTE sections.
+
+# RUN: yaml2obj --docnum=7 %s -o %t7
+# RUN: llvm-readobj --sections --section-data %t7 | FileCheck %s --check-prefix=CONTENT
+
+# CONTENT:      Name: .note.foo
+# CONTENT:      SectionData (
+# CONTENT-NEXT:   0000: 11223344 55 |
+# CONTENT-NEXT: )
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_DYN
+  Machine: EM_X86_64
+Sections:
+  - Name:    .note.foo
+    Type:    SHT_NOTE
+    Content: "1122334455"
+
+## Either "Content", "Size" or "Notes" must be specifed for SHT_NOTE sections.
+
+# RUN: not yaml2obj --docnum=8 %s 2>&1 | FileCheck %s --check-prefix=NO-TAGS
+
+# NO-TAGS: error: one of "Content", "Size" or "Notes" must be specified
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_DYN
+  Machine: EM_X86_64
+Sections:
+  - Name: .note.foo
+    Type: SHT_NOTE
+
+## "Content" and "Notes" cannot be used together to describe the SHT_NOTE section.
+
+# RUN: not yaml2obj --docnum=9 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-NOTES
+
+# CONTENT-NOTES: error: "Notes" cannot be used with "Content" or "Size"
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_DYN
+  Machine: EM_X86_64
+Sections:
+  - Name:    .note.foo
+    Type:    SHT_NOTE
+    Content: ""
+    Notes:   []
+
+## "Size" and "Notes" cannot be used together to describe the SHT_NOTE section.
+
+# RUN: not yaml2obj --docnum=10 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-NOTES
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_DYN
+  Machine: EM_X86_64
+Sections:
+  - Name:  .note.foo
+    Type:  SHT_NOTE
+    Size:  1
+    Notes: []
+
+## Check we can use only "Size" to create a SHT_NOTE section.
+
+# RUN: yaml2obj --docnum=11 %s -o %t11
+# RUN: llvm-readobj --sections --section-data %t11 | FileCheck %s --check-prefix=SIZE
+
+# SIZE:      Name: .note.foo
+# SIZE:      SectionData (
+# SIZE-NEXT:   0000: 00000000 00000000 00000000 00000000  |
+# SIZE-NEXT:   0010: 00                                   |
+# SIZE-NEXT: )
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  Machine: EM_X86_64
+Sections:
+  - Name: .note.foo
+    Type: SHT_NOTE
+    Size: 0x11
+
+## Check we can use "Size" and "Content" together to create a SHT_NOTE section.
+
+# RUN: yaml2obj --docnum=12 %s -o %t12
+# RUN: llvm-readobj --sections --section-data %t12 | FileCheck %s --check-prefix=SIZE-CONTENT
+
+# SIZE-CONTENT:      Name: .note.sizegr
+# SIZE-CONTENT:      SectionData (
+# SIZE-CONTENT-NEXT:   0000: 11223300 00 |
+# SIZE-CONTENT-NEXT: )
+
+# SIZE-CONTENT:      Name: .note.sizeeq
+# SIZE-CONTENT:      SectionData (
+# SIZE-CONTENT-NEXT:   0000: 112233 |
+# SIZE-CONTENT-NEXT: )
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  Machine: EM_X86_64
+Sections:
+  - Name:    .note.sizegr
+    Type:    SHT_NOTE
+    Size:    0x5
+    Content: "112233"
+  - Name:    .note.sizeeq
+    Type:    SHT_NOTE
+    Size:    0x3
+    Content: "112233"
+
+## Check that when "Size" and "Content" are used together, the size
+## must be greater than or equal to the content size.
+
+# RUN: not yaml2obj --docnum=13 %s 2>&1 | FileCheck %s --check-prefix=SIZE-CONTENT-ERR
+# SIZE-CONTENT-ERR: error: "Size" must be greater than or equal to the content size
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  Machine: EM_X86_64
+Sections:
+  - Name:    .note
+    Type:    SHT_NOTE
+    Size:    0x1
+    Content: "1122"
+
+## Check we can't use "Size" and "Notes" tags together.
+
+# RUN: not yaml2obj --docnum=14 %s 2>&1 | FileCheck %s --check-prefix=CONTENT-NOTES
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  Machine: EM_X86_64
+Sections:
+  - Name:  .note
+    Type:  SHT_NOTE
+    Size:  0x1
+    Notes: []


        


More information about the llvm-commits mailing list