[PATCH] D80635: [llvm-readobj][test] - unwind.test: add comments, document the current behavior.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 27 08:05:44 PDT 2020


grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: rupprecht, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Here I've added comments, added testing for llvm-readelf and documented
the behavior that we already have.

It was discussed in the D80380 <https://reviews.llvm.org/D80380> thread that we want to improve the
"p_memsz does not match p_filesz for GNU_EH_FRAME" message reported
(and probably convert error to a warning). This patch is a preparation
for that.


https://reviews.llvm.org/D80635

Files:
  llvm/test/tools/llvm-readobj/ELF/unwind.test


Index: llvm/test/tools/llvm-readobj/ELF/unwind.test
===================================================================
--- llvm/test/tools/llvm-readobj/ELF/unwind.test
+++ llvm/test/tools/llvm-readobj/ELF/unwind.test
@@ -1,5 +1,16 @@
-# RUN: yaml2obj --docnum=1 %s -o %t1.exe
-# RUN: llvm-readobj --unwind %t1.exe | FileCheck %s
+## In this test we check how the unwind information is dumped with the use of --unwind.
+
+## First, check that both llvm-readobj and llvm-readelf are able to dump a valid unwind information.
+## Check that the output is the same for these tools.
+## The memory size of the PT_GNU_EH_FRAME equals its file size and they both are equal to 0x3c.
+## 0x3c is the size of the .eh_frame_hdr section.
+# RUN: yaml2obj --docnum=1 %s -DMEMSIZE=0x3c -DFILESIZE=0x3c -o %t1.valid
+# RUN: llvm-readobj --unwind %t1.valid | FileCheck %s
+# RUN: llvm-readelf --sections --unwind %t1.valid | FileCheck %s --check-prefixes=SIZE,CHECK
+
+## Validate the size of the .eh_frame_hdr section.
+# SIZE: [Nr] Name          Type     Address          Off    Size
+# SIZE: [ 2] .eh_frame_hdr PROGBITS 00000000004013c0 0000bc 00003c
 
 # CHECK:      EHFrameHeader {
 # CHECK-NEXT:  Address: 0x4013c0
@@ -202,19 +213,45 @@
     Value:           0x0000000000400000
     Binding:         STB_GLOBAL
 ProgramHeaders:
-  - Type: PT_LOAD
-    Flags: [ PF_X, PF_R ]
-    VAddr: 0x00400000
-    PAddr: 0x00400000
+  - Type:     PT_LOAD
+    Flags:    [ PF_X, PF_R ]
+    VAddr:    0x00400000
+    PAddr:    0x00400000
     Sections:
       - Section: .text
   - Type: PT_GNU_EH_FRAME
     Flags: [ PF_X, PF_R ]
     VAddr: 0x004013C0
     PAddr: 0x004013C0
+    MemSize:  [[MEMSIZE]]
+    FileSize: [[FILESIZE]]
     Sections:
       - Section: .eh_frame_hdr
-...
+
+## Document we report a error when the memory size of the PT_GNU_EH_FRAME does not match its file size.
+## TODO: we want to report a warning and continue dumping instead.
+# RUN: yaml2obj --docnum=1 %s -DMEMSIZE=0x3b -DFILESIZE=0x3c -o %t1.size.mismatch
+# RUN: not llvm-readobj --unwind %t1.size.mismatch 2>&1 | \
+# RUN:   FileCheck -DFILE=%t1.size.mismatch %s --check-prefix=SIZE-MISMATCH
+# RUN: not llvm-readelf --unwind %t1.size.mismatch 2>&1 | \
+# RUN:   FileCheck -DFILE=%t1.size.mismatch %s --check-prefix=SIZE-MISMATCH
+
+# SIZE-MISMATCH: error: '[[FILE]]': p_memsz does not match p_filesz for GNU_EH_FRAME
+
+## Check we dump the unwind information partially when the PT_GNU_EH_FRAME segment points to a truncated data.
+# RUN: yaml2obj --docnum=1 %s -DMEMSIZE=0x1 -DFILESIZE=0x1 -o %t1.truncated
+# RUN: not llvm-readobj --unwind %t1.truncated 2>&1 | FileCheck -DFILE=%t1.truncated %s --check-prefix=TRUNCATED
+# RUN: not llvm-readelf --unwind %t1.truncated 2>&1 | FileCheck -DFILE=%t1.truncated %s --check-prefix=TRUNCATED
+
+# TRUNCATED:      EHFrameHeader {
+# TRUNCATED-NEXT:   Address: 0x4013c0
+# TRUNCATED-NEXT:   Offset: 0xbc
+# TRUNCATED-NEXT:   Size: 0x1
+# TRUNCATED-NEXT:   Corresponding Section: .eh_frame_hdr
+# TRUNCATED-NEXT:   Header {
+# TRUNCATED-NEXT:     version: 1
+# TRUNCATED-NEXT:     eh_frame_ptr_enc: 0x0
+# TRUNCATED-NEXT: error: '[[FILE]]': unexpected encoding eh_frame_ptr_enc
 
 ## Check we report an error when the tool is unable to parse .eh_frame section.
 # RUN: yaml2obj --docnum=2 %s -o %t2.exe


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80635.266547.patch
Type: text/x-patch
Size: 3310 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200527/c18addaa/attachment.bin>


More information about the llvm-commits mailing list