diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp index 78c930bac0fd..c99d6396cfa1 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp @@ -892,10 +892,12 @@ std::error_code parseObjCImageInfo(const NormalizedFile &normalizedFile, // 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 - // + enum { + OBJC_IMAGE_SUPPORTS_GC=2, + OBJC_IMAGE_GC_ONLY=4, + OBJC_IMAGE_IS_SIMULATED=32, + }; + ArrayRef content = imageInfoSection->content; if (content.size() != 8) return make_dynamic_error_code(imageInfoSection->segmentName + "/" + @@ -912,6 +914,12 @@ std::error_code parseObjCImageInfo(const NormalizedFile &normalizedFile, " should have version=0"); uint32_t flags = read32(content.data() + 4, isBig); + if (flags & (OBJC_IMAGE_SUPPORTS_GC|OBJC_IMAGE_GC_ONLY)) + return make_dynamic_error_code(imageInfoSection->segmentName + "/" + + imageInfoSection->sectionName + + " in file " + file.path() + + " uses GC. This is not supported"); + file.setSwiftVersion((flags >> 8) & 0xFF); return std::error_code(); diff --git a/lld/test/mach-o/objc-image-info-unsupported-gc.yaml b/lld/test/mach-o/objc-image-info-unsupported-gc.yaml new file mode 100644 index 000000000000..9f98369a39cb --- /dev/null +++ b/lld/test/mach-o/objc-image-info-unsupported-gc.yaml @@ -0,0 +1,20 @@ +# RUN: not lld -flavor darwin -arch x86_64 -r %s 2>&1 | FileCheck %s + +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ] +compat-version: 0.0 +current-version: 0.0 +has-UUID: false +OS: unknown +sections: + - segment: __DATA + section: __objc_imageinfo + type: S_REGULAR + attributes: [ S_ATTR_NO_DEAD_STRIP ] + address: 0x0000000000000100 + content: [ 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 ] +... + +# CHECK: error: __DATA/__objc_imageinfo in file {{.*}} uses GC. This is not supported \ No newline at end of file