diff options
author | Pete Cooper <peter_cooper@apple.com> | 2016-03-24 00:36:37 +0000 |
---|---|---|
committer | Pete Cooper <peter_cooper@apple.com> | 2016-03-24 00:36:37 +0000 |
commit | 3f564a52d074adc5b94c08968c59f70ea8d4fb70 (patch) | |
tree | 52ea48c1526a0f1b792f9131606b2bd3b2066e8d | |
parent | 0945a64767d9c79ee97833b9f9ab15264be74ee1 (diff) | |
download | bcm5719-llvm-3f564a52d074adc5b94c08968c59f70ea8d4fb70.tar.gz bcm5719-llvm-3f564a52d074adc5b94c08968c59f70ea8d4fb70.zip |
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.
llvm-svn: 264228
-rw-r--r-- | lld/lib/ReaderWriter/MachO/MachONormalizedFile.h | 5 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp | 25 | ||||
-rw-r--r-- | lld/test/mach-o/arm64-relocs-errors-delta64-offset.yaml | 2 | ||||
-rw-r--r-- | lld/test/mach-o/dso_handle.yaml | 2 | ||||
-rw-r--r-- | lld/test/mach-o/hello-world-x86_64.yaml | 4 | ||||
-rw-r--r-- | lld/test/mach-o/interposing-section.yaml | 2 | ||||
-rw-r--r-- | lld/test/mach-o/mh_bundle_header.yaml | 2 | ||||
-rw-r--r-- | lld/test/mach-o/mh_dylib_header.yaml | 2 | ||||
-rw-r--r-- | lld/test/mach-o/objc_export_list.yaml | 2 | ||||
-rw-r--r-- | lld/test/mach-o/parse-cfstring32.yaml | 2 | ||||
-rw-r--r-- | lld/test/mach-o/parse-compact-unwind64.yaml | 2 | ||||
-rw-r--r-- | lld/test/mach-o/parse-data.yaml | 4 | ||||
-rw-r--r-- | lld/test/mach-o/parse-eh-frame.yaml | 2 | ||||
-rw-r--r-- | lld/test/mach-o/unwind-info-simple-arm64.yaml | 2 |
14 files changed, 42 insertions, 16 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h b/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h index 400a30b8930..7934a6c0336 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFile.h @@ -105,6 +105,9 @@ typedef std::vector<uint32_t> IndirectSymbols; /// 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; diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp index 5ae9204f72b..aa3b042b557 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp @@ -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:" diff --git a/lld/test/mach-o/arm64-relocs-errors-delta64-offset.yaml b/lld/test/mach-o/arm64-relocs-errors-delta64-offset.yaml index 09c59612489..08e41bc65ff 100644 --- a/lld/test/mach-o/arm64-relocs-errors-delta64-offset.yaml +++ b/lld/test/mach-o/arm64-relocs-errors-delta64-offset.yaml @@ -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, diff --git a/lld/test/mach-o/dso_handle.yaml b/lld/test/mach-o/dso_handle.yaml index d39d2c23080..400e2c899c9 100644 --- a/lld/test/mach-o/dso_handle.yaml +++ b/lld/test/mach-o/dso_handle.yaml @@ -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: diff --git a/lld/test/mach-o/hello-world-x86_64.yaml b/lld/test/mach-o/hello-world-x86_64.yaml index 082ed208b8f..8803c4476c3 100644 --- a/lld/test/mach-o/hello-world-x86_64.yaml +++ b/lld/test/mach-o/hello-world-x86_64.yaml @@ -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, diff --git a/lld/test/mach-o/interposing-section.yaml b/lld/test/mach-o/interposing-section.yaml index 76e33904d11..4f6bafc200f 100644 --- a/lld/test/mach-o/interposing-section.yaml +++ b/lld/test/mach-o/interposing-section.yaml @@ -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 ] diff --git a/lld/test/mach-o/mh_bundle_header.yaml b/lld/test/mach-o/mh_bundle_header.yaml index 87b35e7bdd5..e440141c568 100644 --- a/lld/test/mach-o/mh_bundle_header.yaml +++ b/lld/test/mach-o/mh_bundle_header.yaml @@ -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: diff --git a/lld/test/mach-o/mh_dylib_header.yaml b/lld/test/mach-o/mh_dylib_header.yaml index 07429b30c94..96b67aacae2 100644 --- a/lld/test/mach-o/mh_dylib_header.yaml +++ b/lld/test/mach-o/mh_dylib_header.yaml @@ -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: diff --git a/lld/test/mach-o/objc_export_list.yaml b/lld/test/mach-o/objc_export_list.yaml index 9eb0af77726..e67a4c7ece7 100644 --- a/lld/test/mach-o/objc_export_list.yaml +++ b/lld/test/mach-o/objc_export_list.yaml @@ -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, diff --git a/lld/test/mach-o/parse-cfstring32.yaml b/lld/test/mach-o/parse-cfstring32.yaml index 657e733a779..8e746f27666 100644 --- a/lld/test/mach-o/parse-cfstring32.yaml +++ b/lld/test/mach-o/parse-cfstring32.yaml @@ -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, diff --git a/lld/test/mach-o/parse-compact-unwind64.yaml b/lld/test/mach-o/parse-compact-unwind64.yaml index b61961a3d0b..af8967476e1 100644 --- a/lld/test/mach-o/parse-compact-unwind64.yaml +++ b/lld/test/mach-o/parse-compact-unwind64.yaml @@ -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, diff --git a/lld/test/mach-o/parse-data.yaml b/lld/test/mach-o/parse-data.yaml index 61d77290d10..3b422e04cae 100644 --- a/lld/test/mach-o/parse-data.yaml +++ b/lld/test/mach-o/parse-data.yaml @@ -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 diff --git a/lld/test/mach-o/parse-eh-frame.yaml b/lld/test/mach-o/parse-eh-frame.yaml index 69324800e99..6453474024b 100644 --- a/lld/test/mach-o/parse-eh-frame.yaml +++ b/lld/test/mach-o/parse-eh-frame.yaml @@ -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, diff --git a/lld/test/mach-o/unwind-info-simple-arm64.yaml b/lld/test/mach-o/unwind-info-simple-arm64.yaml index 8e87230e283..2ef6dda8f3a 100644 --- a/lld/test/mach-o/unwind-info-simple-arm64.yaml +++ b/lld/test/mach-o/unwind-info-simple-arm64.yaml @@ -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, |