[llvm] r303014 - [COFF] Gracefully handle empty .drectve sections

Shoaib Meenai via llvm-commits llvm-commits at lists.llvm.org
Sun May 14 11:34:56 PDT 2017


Author: smeenai
Date: Sun May 14 13:34:56 2017
New Revision: 303014

URL: http://llvm.org/viewvc/llvm-project?rev=303014&view=rev
Log:
[COFF] Gracefully handle empty .drectve sections

Running `llvm-readobj -coff-directives msvcrt.lib` resulted in this error:

    Invalid data was encountered while parsing the file

This happened because some of the object files in the archive have empty
`.drectve` sections. These empty sections result in a `parse_failed` error being
returned from `COFFObjectFile::getSectionContents()`, which in turn caused
`llvm-readobj` to stop. With this change, `getSectionContents` now returns
success, and like before the resulting array is empty.

Patch by Dave Lee.

Differential Revision: https://reviews.llvm.org/D32652

Added:
    llvm/trunk/test/Object/Inputs/COFF/empty-drectve.yaml
    llvm/trunk/test/Object/coff-empty-drectve.test
Modified:
    llvm/trunk/lib/Object/COFFObjectFile.cpp

Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=303014&r1=303013&r2=303014&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Sun May 14 13:34:56 2017
@@ -1062,7 +1062,7 @@ COFFObjectFile::getSectionContents(const
   // In COFF, a virtual section won't have any in-file
   // content, so the file pointer to the content will be zero.
   if (Sec->PointerToRawData == 0)
-    return object_error::parse_failed;
+    return std::error_code();
   // The only thing that we need to verify is that the contents is contained
   // within the file bounds. We don't need to make sure it doesn't cover other
   // data, as there's nothing that says that is not allowed.

Added: llvm/trunk/test/Object/Inputs/COFF/empty-drectve.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/COFF/empty-drectve.yaml?rev=303014&view=auto
==============================================================================
--- llvm/trunk/test/Object/Inputs/COFF/empty-drectve.yaml (added)
+++ llvm/trunk/test/Object/Inputs/COFF/empty-drectve.yaml Sun May 14 13:34:56 2017
@@ -0,0 +1,14 @@
+--- !COFF
+header:
+  Machine:           IMAGE_FILE_MACHINE_I386
+sections:
+  - Name:            .drectve
+    Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
+    SectionData:     ''
+symbols:
+  - Name:            .drectve
+    Value:           0
+    SectionNumber:   1
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_STATIC

Added: llvm/trunk/test/Object/coff-empty-drectve.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/coff-empty-drectve.test?rev=303014&view=auto
==============================================================================
--- llvm/trunk/test/Object/coff-empty-drectve.test (added)
+++ llvm/trunk/test/Object/coff-empty-drectve.test Sun May 14 13:34:56 2017
@@ -0,0 +1,3 @@
+RUN: yaml2obj %p/Inputs/COFF/empty-drectve.yaml | llvm-readobj -coff-directives - | FileCheck %s
+
+CHECK: Directive(s): {{$}}




More information about the llvm-commits mailing list