[lld] r264228 - Parsed alignment should be a power of 2.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 23 17:36:37 PDT 2016


Author: pete
Date: Wed Mar 23 19:36:37 2016
New Revision: 264228

URL: http://llvm.org/viewvc/llvm-project?rev=264228&view=rev
Log:
Parsed alignment should be a power of 2.

The .o path always makes sure to store a power of 2 value in the
Section alignment.  However, the YAML code didn't verify this.

Added verification and updated all the tests which had a 3 but meant
to have 2^3.

Modified:
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp
    lld/trunk/test/mach-o/arm64-relocs-errors-delta64-offset.yaml
    lld/trunk/test/mach-o/dso_handle.yaml
    lld/trunk/test/mach-o/hello-world-x86_64.yaml
    lld/trunk/test/mach-o/interposing-section.yaml
    lld/trunk/test/mach-o/mh_bundle_header.yaml
    lld/trunk/test/mach-o/mh_dylib_header.yaml
    lld/trunk/test/mach-o/objc_export_list.yaml
    lld/trunk/test/mach-o/parse-cfstring32.yaml
    lld/trunk/test/mach-o/parse-compact-unwind64.yaml
    lld/trunk/test/mach-o/parse-data.yaml
    lld/trunk/test/mach-o/parse-eh-frame.yaml
    lld/trunk/test/mach-o/unwind-info-simple-arm64.yaml

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h?rev=264228&r1=264227&r2=264228&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h Wed Mar 23 19:36:37 2016
@@ -105,6 +105,9 @@ typedef std::vector<uint32_t> IndirectSy
 /// A typedef so that YAML I/O can encode/decode section attributes.
 LLVM_YAML_STRONG_TYPEDEF(uint32_t, SectionAttr)
 
+/// A typedef so that YAML I/O can encode/decode section alignment.
+LLVM_YAML_STRONG_TYPEDEF(uint16_t, SectionAlignment)
+
 /// Mach-O has a 32-bit and 64-bit section record.  This normalized form
 /// can support either kind.
 struct Section {
@@ -115,7 +118,7 @@ struct Section {
   StringRef       sectionName;
   SectionType     type;
   SectionAttr     attributes;
-  uint16_t        alignment;
+  SectionAlignment        alignment;
   Hex64           address;
   ArrayRef<uint8_t> content;
   Relocations     relocations;

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp?rev=264228&r1=264227&r2=264228&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp Wed Mar 23 19:36:37 2016
@@ -237,6 +237,29 @@ struct ScalarBitSetTraits<SectionAttr> {
   }
 };
 
+/// This is a custom formatter for SectionAlignment.  Values are
+/// the power to raise by, ie, the n in 2^n.
+template <> struct ScalarTraits<SectionAlignment> {
+  static void output(const SectionAlignment &value, void *ctxt,
+                     raw_ostream &out) {
+    out << llvm::format("%d", (uint32_t)value);
+  }
+
+  static StringRef input(StringRef scalar, void *ctxt,
+                         SectionAlignment &value) {
+    uint32_t alignment;
+    if (scalar.getAsInteger(0, alignment)) {
+      return "malformed alignment value";
+    }
+    if (!llvm::isPowerOf2_32(alignment))
+      return "alignment must be a power of 2";
+    value = alignment;
+    return StringRef(); // returning empty string means success
+  }
+
+  static bool mustQuote(StringRef) { return false; }
+};
+
 template <>
 struct ScalarEnumerationTraits<NListType> {
   static void enumeration(IO &io, NListType &value) {
@@ -276,7 +299,7 @@ struct MappingTraits<Section> {
     io.mapRequired("section",         sect.sectionName);
     io.mapRequired("type",            sect.type);
     io.mapOptional("attributes",      sect.attributes);
-    io.mapOptional("alignment",       sect.alignment, (uint16_t)1);
+    io.mapOptional("alignment",       sect.alignment, (SectionAlignment)1);
     io.mapRequired("address",         sect.address);
     if (isZeroFillSection(sect.type)) {
       // S_ZEROFILL sections use "size:" instead of "content:"

Modified: lld/trunk/test/mach-o/arm64-relocs-errors-delta64-offset.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/arm64-relocs-errors-delta64-offset.yaml?rev=264228&r1=264227&r2=264228&view=diff
==============================================================================
--- lld/trunk/test/mach-o/arm64-relocs-errors-delta64-offset.yaml (original)
+++ lld/trunk/test/mach-o/arm64-relocs-errors-delta64-offset.yaml Wed Mar 23 19:36:37 2016
@@ -24,7 +24,7 @@ sections:
     section:         __data
     type:            S_REGULAR
     attributes:      [  ]
-    alignment:       3
+    alignment:       8
     address:         0x000000000001C348
     content:         [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,

Modified: lld/trunk/test/mach-o/dso_handle.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/dso_handle.yaml?rev=264228&r1=264227&r2=264228&view=diff
==============================================================================
--- lld/trunk/test/mach-o/dso_handle.yaml (original)
+++ lld/trunk/test/mach-o/dso_handle.yaml Wed Mar 23 19:36:37 2016
@@ -28,7 +28,7 @@ sections:
     section:         __data
     type:            S_REGULAR
     attributes:      [  ]
-    alignment:       3
+    alignment:       8
     address:         0x0000000000000008
     content:         [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]
     relocations:

Modified: lld/trunk/test/mach-o/hello-world-x86_64.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/hello-world-x86_64.yaml?rev=264228&r1=264227&r2=264228&view=diff
==============================================================================
--- lld/trunk/test/mach-o/hello-world-x86_64.yaml (original)
+++ lld/trunk/test/mach-o/hello-world-x86_64.yaml Wed Mar 23 19:36:37 2016
@@ -54,7 +54,7 @@ sections:
     section:         __compact_unwind
     type:            S_REGULAR
     attributes:      [  ]
-    alignment:       3
+    alignment:       8
     address:         0x0000000000000028
     content:         [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
@@ -71,7 +71,7 @@ sections:
     section:         __eh_frame
     type:            S_COALESCED
     attributes:      [  ]
-    alignment:       3
+    alignment:       8
     address:         0x0000000000000048
     content:         [ 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x01, 0x7A, 0x52, 0x00, 0x01, 0x78, 0x10, 0x01,

Modified: lld/trunk/test/mach-o/interposing-section.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/interposing-section.yaml?rev=264228&r1=264227&r2=264228&view=diff
==============================================================================
--- lld/trunk/test/mach-o/interposing-section.yaml (original)
+++ lld/trunk/test/mach-o/interposing-section.yaml Wed Mar 23 19:36:37 2016
@@ -31,7 +31,7 @@ sections:
     section:         __interpose
     type:            S_INTERPOSING
     attributes:      [  ]
-    alignment:       3
+    alignment:       8
     address:         0x0000000000000010
     content:         [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]

Modified: lld/trunk/test/mach-o/mh_bundle_header.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/mh_bundle_header.yaml?rev=264228&r1=264227&r2=264228&view=diff
==============================================================================
--- lld/trunk/test/mach-o/mh_bundle_header.yaml (original)
+++ lld/trunk/test/mach-o/mh_bundle_header.yaml Wed Mar 23 19:36:37 2016
@@ -19,7 +19,7 @@ sections:
     section:         __data
     type:            S_REGULAR
     attributes:      [  ]
-    alignment:       3
+    alignment:       8
     address:         0x0000000000000008
     content:         [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]
     relocations:

Modified: lld/trunk/test/mach-o/mh_dylib_header.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/mh_dylib_header.yaml?rev=264228&r1=264227&r2=264228&view=diff
==============================================================================
--- lld/trunk/test/mach-o/mh_dylib_header.yaml (original)
+++ lld/trunk/test/mach-o/mh_dylib_header.yaml Wed Mar 23 19:36:37 2016
@@ -19,7 +19,7 @@ sections:
     section:         __data
     type:            S_REGULAR
     attributes:      [  ]
-    alignment:       3
+    alignment:       8
     address:         0x0000000000000008
     content:         [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]
     relocations:

Modified: lld/trunk/test/mach-o/objc_export_list.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/objc_export_list.yaml?rev=264228&r1=264227&r2=264228&view=diff
==============================================================================
--- lld/trunk/test/mach-o/objc_export_list.yaml (original)
+++ lld/trunk/test/mach-o/objc_export_list.yaml Wed Mar 23 19:36:37 2016
@@ -15,7 +15,7 @@ sections:
     section:         __objc_data
     type:            S_REGULAR
     attributes:      [  ]
-    alignment:       3
+    alignment:       8
     address:         0x0000000000000000
     content:         [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

Modified: lld/trunk/test/mach-o/parse-cfstring32.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/parse-cfstring32.yaml?rev=264228&r1=264227&r2=264228&view=diff
==============================================================================
--- lld/trunk/test/mach-o/parse-cfstring32.yaml (original)
+++ lld/trunk/test/mach-o/parse-cfstring32.yaml Wed Mar 23 19:36:37 2016
@@ -21,7 +21,7 @@ sections:
     section:         __cfstring
     type:            S_REGULAR
     attributes:      [  ]
-    alignment:       3
+    alignment:       8
     address:         0x0000000000000010
     content:         [ 0x00, 0x00, 0x00, 0x00, 0xC8, 0x07, 0x00, 0x00,
                        0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,

Modified: lld/trunk/test/mach-o/parse-compact-unwind64.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/parse-compact-unwind64.yaml?rev=264228&r1=264227&r2=264228&view=diff
==============================================================================
--- lld/trunk/test/mach-o/parse-compact-unwind64.yaml (original)
+++ lld/trunk/test/mach-o/parse-compact-unwind64.yaml Wed Mar 23 19:36:37 2016
@@ -23,7 +23,7 @@ sections:
     section:         __compact_unwind
     type:            S_REGULAR
     attributes:      [  ]
-    alignment:       3
+    alignment:       8
     address:         0x0000000000000020
     content:         [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,

Modified: lld/trunk/test/mach-o/parse-data.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/parse-data.yaml?rev=264228&r1=264227&r2=264228&view=diff
==============================================================================
--- lld/trunk/test/mach-o/parse-data.yaml (original)
+++ lld/trunk/test/mach-o/parse-data.yaml Wed Mar 23 19:36:37 2016
@@ -22,7 +22,7 @@ sections:
     section:         __data
     type:            S_REGULAR
     attributes:      [  ]
-    alignment:       3
+    alignment:       8
     address:         0x0000000000000000
     content:         [ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                        0x11, 0x12, 0x13, 0x14, 0x21, 0x22, 0x23, 0x24,
@@ -31,7 +31,7 @@ sections:
     section:         __custom
     type:            S_REGULAR
     attributes:      [  ]
-    alignment:       3
+    alignment:       8
     address:         0x0000000000000018
     content:         [ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 ]
   - segment:         __DATA

Modified: lld/trunk/test/mach-o/parse-eh-frame.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/parse-eh-frame.yaml?rev=264228&r1=264227&r2=264228&view=diff
==============================================================================
--- lld/trunk/test/mach-o/parse-eh-frame.yaml (original)
+++ lld/trunk/test/mach-o/parse-eh-frame.yaml Wed Mar 23 19:36:37 2016
@@ -22,7 +22,7 @@ sections:
     section:         __eh_frame
     type:            S_COALESCED
     attributes:      [  ]
-    alignment:       3
+    alignment:       8
     address:         0x0000000000000058
     content:         [ 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x01, 0x7A, 0x52, 0x00, 0x01, 0x78, 0x10, 0x01,

Modified: lld/trunk/test/mach-o/unwind-info-simple-arm64.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/unwind-info-simple-arm64.yaml?rev=264228&r1=264227&r2=264228&view=diff
==============================================================================
--- lld/trunk/test/mach-o/unwind-info-simple-arm64.yaml (original)
+++ lld/trunk/test/mach-o/unwind-info-simple-arm64.yaml Wed Mar 23 19:36:37 2016
@@ -125,7 +125,7 @@ sections:
     section:         __compact_unwind
     type:            S_REGULAR
     attributes:      [  ]
-    alignment:       3
+    alignment:       8
     address:         0x00000000000000A8
     content:         [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,




More information about the llvm-commits mailing list