summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
diff options
context:
space:
mode:
authorPete Cooper <peter_cooper@apple.com>2016-01-14 23:35:05 +0000
committerPete Cooper <peter_cooper@apple.com>2016-01-14 23:35:05 +0000
commitd7b5c5bcefa6662ce632920191c2921702fd4836 (patch)
treec4726dc51f50629b64c6ce22a46e6732d1742712 /lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
parentedbe56857326ab54f6dee8f21443afb22093106c (diff)
downloadbcm5719-llvm-d7b5c5bcefa6662ce632920191c2921702fd4836.tar.gz
bcm5719-llvm-d7b5c5bcefa6662ce632920191c2921702fd4836.zip
Error check the size of the __objc_imageinfo section
llvm-svn: 257841
Diffstat (limited to 'lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp')
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
index 827dca86959..2cebe539ad6 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
@@ -867,6 +867,45 @@ std::error_code addEHFrameReferences(const NormalizedFile &normalizedFile,
return ehFrameErr;
}
+std::error_code parseObjCImageInfo(const NormalizedFile &normalizedFile,
+ MachOFile &file) {
+
+ const Section *imageInfoSection = nullptr;
+ for (auto &section : normalizedFile.sections) {
+ if (section.segmentName == "__OBJC" &&
+ section.sectionName == "__image_info") {
+ imageInfoSection = &section;
+ break;
+ }
+ if (section.segmentName == "__DATA" &&
+ section.sectionName == "__objc_imageinfo") {
+ imageInfoSection = &section;
+ break;
+ }
+ }
+
+ // No image info section so nothing to do.
+ if (!imageInfoSection)
+ return std::error_code();
+
+ // struct objc_image_info {
+ // uint32_t version; // initially 0
+ // uint32_t flags;
+ // };
+ // #define OBJC_IMAGE_SUPPORTS_GC 2
+ // #define OBJC_IMAGE_GC_ONLY 4
+ // #define OBJC_IMAGE_IS_SIMULATED 32
+ //
+ ArrayRef<uint8_t> content = imageInfoSection->content;
+ if (content.size() != 8)
+ return make_dynamic_error_code(imageInfoSection->segmentName + "/" +
+ imageInfoSection->sectionName +
+ " in file " + file.path() +
+ " should be 8 bytes in size");
+
+ return std::error_code();
+}
+
/// Converts normalized mach-o file into an lld::File and lld::Atoms.
ErrorOr<std::unique_ptr<lld::File>>
@@ -948,6 +987,11 @@ normalizedObjectToAtoms(MachOFile *file,
if (std::error_code ec = addEHFrameReferences(normalizedFile, *file, *handler))
return ec;
+ // If the file contains an objc_image_info struct, then we should parse the
+ // ObjC flags and Swift version.
+ if (std::error_code ec = parseObjCImageInfo(normalizedFile, *file))
+ return ec;
+
// Process mach-o data-in-code regions array. That information is encoded in
// atoms as References at each transition point.
unsigned nextIndex = 0;
OpenPOWER on IntegriCloud