[lld] r257974 - Give error on binaries containing GC objc image infos.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 15 16:57:08 PST 2016


Author: pete
Date: Fri Jan 15 18:57:07 2016
New Revision: 257974

URL: http://llvm.org/viewvc/llvm-project?rev=257974&view=rev
Log:
Give error on binaries containing GC objc image infos.

The image info struct contains flags for what kind of GC/retain/release is required.

Give an error if we parse GC flags as these are unsupported.

Added:
    lld/trunk/test/mach-o/objc-image-info-unsupported-gc.yaml
Modified:
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp?rev=257974&r1=257973&r2=257974&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp Fri Jan 15 18:57:07 2016
@@ -892,10 +892,12 @@ std::error_code parseObjCImageInfo(const
   //		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<uint8_t> content = imageInfoSection->content;
   if (content.size() != 8)
     return make_dynamic_error_code(imageInfoSection->segmentName + "/" +
@@ -912,6 +914,12 @@ std::error_code parseObjCImageInfo(const
                                    " 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();

Added: lld/trunk/test/mach-o/objc-image-info-unsupported-gc.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/objc-image-info-unsupported-gc.yaml?rev=257974&view=auto
==============================================================================
--- lld/trunk/test/mach-o/objc-image-info-unsupported-gc.yaml (added)
+++ lld/trunk/test/mach-o/objc-image-info-unsupported-gc.yaml Fri Jan 15 18:57:07 2016
@@ -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




More information about the llvm-commits mailing list