[cfe-commits] r125585 - in /cfe/trunk: lib/CodeGen/CGDeclCXX.cpp test/CodeGenCXX/apple-kext-no-staticinit-section.C

Fariborz Jahanian fjahanian at apple.com
Tue Feb 15 10:54:47 PST 2011


Author: fjahanian
Date: Tue Feb 15 12:54:46 2011
New Revision: 125585

URL: http://llvm.org/viewvc/llvm-project?rev=125585&view=rev
Log:
In -fapple-kext mode, global object construction code 
ends up in the text segment. // rdar://8825235.

Added:
    cfe/trunk/test/CodeGenCXX/apple-kext-no-staticinit-section.C
Modified:
    cfe/trunk/lib/CodeGen/CGDeclCXX.cpp

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=125585&r1=125584&r2=125585&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Tue Feb 15 12:54:46 2011
@@ -159,11 +159,12 @@
   llvm::Function *Fn =
     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);
+  if (!CGM.getContext().getLangOptions().AppleKext) {
+    // Set the section if needed.
+    if (const char *Section = 
+          CGM.getContext().Target.getStaticInitSectionSpecifier())
+      Fn->setSection(Section);
+  }
 
   if (!CGM.getLangOptions().Exceptions)
     Fn->setDoesNotThrow();

Added: cfe/trunk/test/CodeGenCXX/apple-kext-no-staticinit-section.C
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/apple-kext-no-staticinit-section.C?rev=125585&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/apple-kext-no-staticinit-section.C (added)
+++ cfe/trunk/test/CodeGenCXX/apple-kext-no-staticinit-section.C Tue Feb 15 12:54:46 2011
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fapple-kext -fno-rtti -emit-llvm -o - %s | FileCheck %s
+// rdar://8825235
+/**
+1) Normally, global object construction code ends up in __StaticInit segment of text section
+   .section __TEXT,__StaticInit,regular,pure_instructions
+   In kext mode, they end up in the __text segment.
+*/
+
+class foo {
+public:
+  foo();
+  virtual ~foo();
+};
+
+foo a;
+foo b;
+foo c;
+foo::~foo() {}
+
+// CHECK-NOT: __TEXT,__StaticInit,regular,pure_instructions





More information about the cfe-commits mailing list