aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2010-06-08 22:47:50 +0000
committerAnders Carlsson <andersca@mac.com>2010-06-08 22:47:50 +0000
commit18af368c080b9d60e34e670cd01f7d2d3ad2ba48 (patch)
treeeb2f0fa0f7d2df1e1dfa06ab83146fcc7fab458c
parent9dc046e70d189457968e4c3b986da75b5d98ce8e (diff)
On Darwin, initialization and destruction functions should go into the __StaticInit section.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105650 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/TargetInfo.h7
-rw-r--r--lib/Basic/Targets.cpp6
-rw-r--r--lib/CodeGen/CGDeclCXX.cpp5
3 files changed, 17 insertions, 1 deletions
diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h
index 0cef286afe..4c5019ca98 100644
--- a/include/clang/Basic/TargetInfo.h
+++ b/include/clang/Basic/TargetInfo.h
@@ -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;
diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
index 82c6507190..a6548c4402 100644
--- a/lib/Basic/Targets.cpp
+++ b/lib/Basic/Targets.cpp
@@ -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";
+ }
+
};
diff --git a/lib/CodeGen/CGDeclCXX.cpp b/lib/CodeGen/CGDeclCXX.cpp
index 4c0de2f75e..b54f5af754 100644
--- a/lib/CodeGen/CGDeclCXX.cpp
+++ b/lib/CodeGen/CGDeclCXX.cpp
@@ -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;
}