[llvm] 9c69cc1 - [obj2yaml] - SHT_REL*, SHT_DYNAMIC sections: add tests to document the behavior when sh_entsize is broken.

Georgii Rymar via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 19 06:54:47 PDT 2020


Author: Georgii Rymar
Date: 2020-03-19T16:43:40+03:00
New Revision: 9c69cc109bc0da95ae13ac00fef000e0594c3a65

URL: https://github.com/llvm/llvm-project/commit/9c69cc109bc0da95ae13ac00fef000e0594c3a65
DIFF: https://github.com/llvm/llvm-project/commit/9c69cc109bc0da95ae13ac00fef000e0594c3a65.diff

LOG: [obj2yaml] - SHT_REL*, SHT_DYNAMIC sections: add tests to document the behavior when sh_entsize is broken.

We do not have tests that shows the current behavior.
It is needed for D76227 which changes the logic of dumping of `EntSize` fields.

Differential revision: https://reviews.llvm.org/D76282

Added: 
    

Modified: 
    llvm/test/tools/obj2yaml/dynamic-section.test
    llvm/test/tools/obj2yaml/rel-rela-section.yaml
    llvm/test/tools/obj2yaml/relr-section.yaml

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/obj2yaml/dynamic-section.test b/llvm/test/tools/obj2yaml/dynamic-section.test
index 28066dd16adf..69a27fec1a2c 100644
--- a/llvm/test/tools/obj2yaml/dynamic-section.test
+++ b/llvm/test/tools/obj2yaml/dynamic-section.test
@@ -1,10 +1,10 @@
-# RUN: yaml2obj %s -o %t
-# RUN: obj2yaml %t | FileCheck %s
-
 ## Check we can use obj2yaml to yamalize the object containing
 ## .dynamic section. Check that resulting section has the
 ## proper attributes and dynamic tags.
 
+# RUN: yaml2obj -DENTSIZE=0x10 %s -o %t1
+# RUN: obj2yaml %t1 | FileCheck %s
+
 # CHECK:       Sections:
 # CHECK-NEXT:  - Name:            .dynamic
 # CHECK-NEXT:    Type:            SHT_DYNAMIC
@@ -136,7 +136,7 @@ Sections:
     Type:            SHT_DYNAMIC
     Address:         0x0000000000001000
     AddressAlign:    0x0000000000002000
-    EntSize:         0x0000000000000010
+    EntSize:         [[ENTSIZE]]
     Entries:
       - Tag:             DT_NULL
         Value:           0x0000000000000000
@@ -250,3 +250,11 @@ Sections:
         Value:           0x0000000000000036
       - Tag:             DT_USED
         Value:           0x0000000000000001
+
+## Test the behavior when sh_entsize is invalid.
+## Here we use 0xFE as an arbitrary broken value instead of expected 0x16.
+
+# RUN: yaml2obj -DENTSIZE=0xff %s -o %t2
+# RUN: not obj2yaml %t2 2>&1 | FileCheck %s --check-prefix=ENTSIZE
+
+# ENTSIZE: section [index 1] has an invalid sh_entsize: 255

diff  --git a/llvm/test/tools/obj2yaml/rel-rela-section.yaml b/llvm/test/tools/obj2yaml/rel-rela-section.yaml
index a29c2b2cc1e3..18be5ff6f633 100644
--- a/llvm/test/tools/obj2yaml/rel-rela-section.yaml
+++ b/llvm/test/tools/obj2yaml/rel-rela-section.yaml
@@ -29,3 +29,24 @@ Sections:
     Type: SHT_REL
 ## Trigger the .dynsym emission.
 DynamicSymbols: []
+
+## Test the behavior when the sh_entsize field is broken.
+## Here we use the 0xFE value instead of expected 0x18/0x10.
+
+# RUN: yaml2obj -DTYPE=SHT_RELA --docnum=2 %s -o %t2.rela
+# RUN: not obj2yaml %t2.rela 2>&1 | FileCheck %s --check-prefix=ERR
+# RUN: yaml2obj -DTYPE=SHT_REL  --docnum=2 %s -o %t2.rel
+# RUN: not obj2yaml %t2.rel 2>&1 | FileCheck %s --check-prefix=ERR
+
+# ERR: section [index 1] has an invalid sh_entsize: 254
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_DYN
+  Machine: EM_X86_64
+Sections:
+  - Name:    .foo
+    Type:    [[TYPE]]
+    EntSize: 0xFE

diff  --git a/llvm/test/tools/obj2yaml/relr-section.yaml b/llvm/test/tools/obj2yaml/relr-section.yaml
index 37ddf2c2e671..11ca6ff896c0 100644
--- a/llvm/test/tools/obj2yaml/relr-section.yaml
+++ b/llvm/test/tools/obj2yaml/relr-section.yaml
@@ -1,69 +1,93 @@
-## Test how we dump SHT_RELR sections for 32 and 64-bit targets.
-
-## Test we use the "Entries" property when it is possible do
-## dump values correctly.
-
-# RUN: yaml2obj --docnum=1 -D BITS=32 -D ENCODE=LSB %s -o %t.32le
-# RUN: obj2yaml %t.32le | FileCheck %s --check-prefix=ELF32LE
-# RUN: yaml2obj --docnum=1 -D BITS=32 -D ENCODE=MSB %s -o %t.32be
-# RUN: obj2yaml %t.32be | FileCheck %s --check-prefix=ELF32BE
-# RUN: yaml2obj --docnum=1 -D BITS=64 -D ENCODE=LSB %s -o %t.64le
-# RUN: obj2yaml %t.64le | FileCheck %s --check-prefix=ELF64LE
-# RUN: yaml2obj --docnum=1 -D BITS=64 -D ENCODE=MSB %s -o %t.64be
-# RUN: obj2yaml %t.64be | FileCheck %s --check-prefix=ELF64BE
-
-# ELF64LE:      Sections:
-# ELF64LE-NEXT:   - Name:    .relr.dyn
-# ELF64LE-NEXT:     Type:    SHT_RELR
-# ELF64LE-NEXT:     EntSize: 0x0000000000000008
-# ELF64LE-NEXT:     Entries: [ 0x8877665544332211 ]
-
-# ELF32LE:      Sections:
-# ELF32LE-NEXT:   - Name:    .relr.dyn
-# ELF32LE-NEXT:     Type:    SHT_RELR
-# ELF32LE-NEXT:     EntSize: 0x0000000000000004
-# ELF32LE-NEXT:     Entries: [ 0x0000000044332211, 0x0000000088776655 ]
-
-# ELF64BE:      Sections:
-# ELF64BE-NEXT:   - Name:    .relr.dyn
-# ELF64BE-NEXT:     Type:    SHT_RELR
-# ELF64BE-NEXT:     EntSize: 0x0000000000000008
-# ELF64BE-NEXT:     Entries: [ 0x1122334455667788 ]
-
-# ELF32BE:      Sections:
-# ELF32BE-NEXT:  - Name:    .relr.dyn
-# ELF32BE-NEXT:    Type:    SHT_RELR
-# ELF32BE-NEXT:    EntSize: 0x0000000000000004
-# ELF32BE-NEXT:    Entries: [ 0x0000000011223344, 0x0000000055667788 ]
-
---- !ELF
-FileHeader:
-  Class:   ELFCLASS[[BITS]]
-  Data:    ELFDATA2[[ENCODE]]
-  Type:    ET_DYN
-  Machine: EM_X86_64
-Sections:
-  - Name: .relr.dyn
-    Type: SHT_RELR
-    Content: "1122334455667788"
-
-## Test we use the "Content" property when a SHT_RELR section is truncated.
-
-# RUN: yaml2obj --docnum=2 %s -o %t.content
-# RUN: obj2yaml %t.content | FileCheck %s --check-prefix=CONTENT
-
-# CONTENT:      - Name:    .relr.dyn
-# CONTENT-NEXT:   Type:    SHT_RELR
-# CONTENT-NEXT:   EntSize: 0x0000000000000008
-# CONTENT-NEXT:   Content: '11223344556677'
-
---- !ELF
-FileHeader:
-  Class:   ELFCLASS64
-  Data:    ELFDATA2MSB
-  Type:    ET_DYN
-  Machine: EM_X86_64
-Sections:
-  - Name: .relr.dyn
-    Type: SHT_RELR
-    Content: "11223344556677"
+## Test how we dump SHT_RELR sections for 32 and 64-bit targets.
+
+## Test we use the "Entries" property when it is possible do
+## dump values correctly.
+
+# RUN: yaml2obj --docnum=1 -D BITS=32 -D ENCODE=LSB %s -o %t.32le
+# RUN: obj2yaml %t.32le | FileCheck %s --check-prefix=ELF32LE
+# RUN: yaml2obj --docnum=1 -D BITS=32 -D ENCODE=MSB %s -o %t.32be
+# RUN: obj2yaml %t.32be | FileCheck %s --check-prefix=ELF32BE
+# RUN: yaml2obj --docnum=1 -D BITS=64 -D ENCODE=LSB %s -o %t.64le
+# RUN: obj2yaml %t.64le | FileCheck %s --check-prefix=ELF64LE
+# RUN: yaml2obj --docnum=1 -D BITS=64 -D ENCODE=MSB %s -o %t.64be
+# RUN: obj2yaml %t.64be | FileCheck %s --check-prefix=ELF64BE
+
+# ELF64LE:      Sections:
+# ELF64LE-NEXT:   - Name:    .relr.dyn
+# ELF64LE-NEXT:     Type:    SHT_RELR
+# ELF64LE-NEXT:     EntSize: 0x0000000000000008
+# ELF64LE-NEXT:     Entries: [ 0x8877665544332211 ]
+
+# ELF32LE:      Sections:
+# ELF32LE-NEXT:   - Name:    .relr.dyn
+# ELF32LE-NEXT:     Type:    SHT_RELR
+# ELF32LE-NEXT:     EntSize: 0x0000000000000004
+# ELF32LE-NEXT:     Entries: [ 0x0000000044332211, 0x0000000088776655 ]
+
+# ELF64BE:      Sections:
+# ELF64BE-NEXT:   - Name:    .relr.dyn
+# ELF64BE-NEXT:     Type:    SHT_RELR
+# ELF64BE-NEXT:     EntSize: 0x0000000000000008
+# ELF64BE-NEXT:     Entries: [ 0x1122334455667788 ]
+
+# ELF32BE:      Sections:
+# ELF32BE-NEXT:  - Name:    .relr.dyn
+# ELF32BE-NEXT:    Type:    SHT_RELR
+# ELF32BE-NEXT:    EntSize: 0x0000000000000004
+# ELF32BE-NEXT:    Entries: [ 0x0000000011223344, 0x0000000055667788 ]
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS[[BITS]]
+  Data:    ELFDATA2[[ENCODE]]
+  Type:    ET_DYN
+  Machine: EM_X86_64
+Sections:
+  - Name: .relr.dyn
+    Type: SHT_RELR
+    Content: "1122334455667788"
+
+## Test we use the "Content" property when a SHT_RELR section is truncated.
+
+# RUN: yaml2obj --docnum=2 %s -o %t.content
+# RUN: obj2yaml %t.content | FileCheck %s --check-prefix=CONTENT
+
+# CONTENT:      - Name:    .relr.dyn
+# CONTENT-NEXT:   Type:    SHT_RELR
+# CONTENT-NEXT:   EntSize: 0x0000000000000008
+# CONTENT-NEXT:   Content: '11223344556677'
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2MSB
+  Type:    ET_DYN
+  Machine: EM_X86_64
+Sections:
+  - Name: .relr.dyn
+    Type: SHT_RELR
+    Content: "11223344556677"
+
+## Test we are able to dump a SHT_RELR section when sh_entsize is invalid.
+## Here we use 0xFE as a value instead of expected 0x8.
+
+# RUN: yaml2obj --docnum=3 %s -o %t.entsize
+# RUN: obj2yaml %t.entsize | FileCheck %s --check-prefix=ENTSIZE
+
+# ENTSIZE:        - Name:    .relr.dyn
+# ENTSIZE-NEXT:     Type:    SHT_RELR
+# ENTSIZE-NEXT:     EntSize: 0x00000000000000FE
+# ENTSIZE-NEXT:     Content: '1122334455667788'
+# ENTSIZE-NEXT: ...
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2MSB
+  Type:    ET_DYN
+  Machine: EM_X86_64
+Sections:
+  - Name:    .relr.dyn
+    Type:    SHT_RELR
+    EntSize: 0xFE
+    Content: "1122334455667788"


        


More information about the llvm-commits mailing list