On Darwin, initialization and destruction functions should go into the __StaticInit...
authorAnders Carlsson <andersca@mac.com>
Tue, 8 Jun 2010 22:47:50 +0000 (22:47 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 8 Jun 2010 22:47:50 +0000 (22:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105650 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/TargetInfo.h
lib/Basic/Targets.cpp
lib/CodeGen/CGDeclCXX.cpp

index 0cef286afef38699a0cd71839bbe4725392529ff..4c5019ca98c47c76bf80683f51c6c78e6360f6d5 100644 (file)
@@ -456,7 +456,12 @@ public:
     return -1; 
   }
   
-
+  /// getStaticInitSectionSpecifier - Return the section to use for C++ static 
+  /// initialization functions.
+  virtual const char *getStaticInitSectionSpecifier() const {
+    return 0;
+  }
+  
 protected:
   virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
     return PointerWidth;
index 82c6507190b4cbeae8ca876c486c2ebbb7692cb0..a6548c44025b84f59e01f5e999e162f93579f693 100644 (file)
@@ -160,6 +160,12 @@ public:
     return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section,
                                                        TAA, StubSize);
   }
+  
+  virtual const char *getStaticInitSectionSpecifier() const {
+    // FIXME: We should return 0 when building kexts.
+    return "__TEXT,__StaticInit,regular,pure_instructions";
+  }
+  
 };
 
 
index 4c0de2f75ed0714ef6a056f46dfbfc46bdea9086..b54f5af7540f5cf47c324f9e14122f6530566ed9 100644 (file)
@@ -151,6 +151,11 @@ CreateGlobalInitOrDestructFunction(CodeGenModule &CGM,
     llvm::Function::Create(FTy, llvm::GlobalValue::InternalLinkage,
                            Name, &CGM.getModule());
 
+  // Set the section if needed.
+  if (const char *Section = 
+        CGM.getContext().Target.getStaticInitSectionSpecifier())
+    Fn->setSection(Section);
+
   return Fn;
 }