[llvm] r263692 - [yaml2obj, COFF] Correctly handle section alignment

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 16 22:43:26 PDT 2016


Author: majnemer
Date: Thu Mar 17 00:43:26 2016
New Revision: 263692

URL: http://llvm.org/viewvc/llvm-project?rev=263692&view=rev
Log:
[yaml2obj, COFF] Correctly handle section alignment

The section alignment field was marked optional but not provided a
default value: initialize it with 0.

While we are here, ensure that the section alignment is plausible.

Added:
    llvm/trunk/test/Object/yaml2obj-coff-invalid-alignment.test
Modified:
    llvm/trunk/tools/yaml2obj/yaml2coff.cpp

Added: llvm/trunk/test/Object/yaml2obj-coff-invalid-alignment.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/yaml2obj-coff-invalid-alignment.test?rev=263692&view=auto
==============================================================================
--- llvm/trunk/test/Object/yaml2obj-coff-invalid-alignment.test (added)
+++ llvm/trunk/test/Object/yaml2obj-coff-invalid-alignment.test Thu Mar 17 00:43:26 2016
@@ -0,0 +1,14 @@
+# RUN: not yaml2obj %s 2>&1 | FileCheck %s
+
+# CHECK: Section alignment is too large
+
+---
+header:
+  Machine:         IMAGE_FILE_MACHINE_AMD64
+  Characteristics: []
+sections:
+  - Name:            '.text'
+    Characteristics: []
+    SectionData:     00
+    Alignment:       16384
+symbols:

Modified: llvm/trunk/tools/yaml2obj/yaml2coff.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2coff.cpp?rev=263692&r1=263691&r2=263692&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2coff.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2coff.cpp Thu Mar 17 00:43:26 2016
@@ -76,14 +76,24 @@ struct COFFParser {
         unsigned Index = getStringIndex(Name);
         std::string str = utostr(Index);
         if (str.size() > 7) {
-          errs() << "String table got too large";
+          errs() << "String table got too large\n";
           return false;
         }
         Sec.Header.Name[0] = '/';
         std::copy(str.begin(), str.end(), Sec.Header.Name + 1);
       }
 
-      Sec.Header.Characteristics |= (Log2_32(Sec.Alignment) + 1) << 20;
+      if (Sec.Alignment) {
+        if (Sec.Alignment > 8192) {
+          errs() << "Section alignment is too large\n";
+          return false;
+        }
+        if (!isPowerOf2_32(Sec.Alignment)) {
+          errs() << "Section alignment is not a power of 2\n";
+          return false;
+        }
+        Sec.Header.Characteristics |= (Log2_32(Sec.Alignment) + 1) << 20;
+      }
     }
     return true;
   }




More information about the llvm-commits mailing list