[cfe-commits] r140030 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGenCXX/apple-kext-linkage.C

John McCall rjmccall at apple.com
Mon Sep 19 11:05:26 PDT 2011


Author: rjmccall
Date: Mon Sep 19 13:05:26 2011
New Revision: 140030

URL: http://llvm.org/viewvc/llvm-project?rev=140030&view=rev
Log:
In apple-kext mode, use external linkage for explicit template instantiations
instead of internal linkage.


Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGenCXX/apple-kext-linkage.C

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=140030&r1=140029&r2=140030&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Sep 19 13:05:26 2011
@@ -400,7 +400,12 @@
   // definition somewhere else, so we can use available_externally linkage.
   if (Linkage == GVA_C99Inline)
     return llvm::Function::AvailableExternallyLinkage;
-  
+
+  // Note that Apple's kernel linker doesn't support symbol
+  // coalescing, so we need to avoid linkonce and weak linkages there.
+  // Normally, this means we just map to internal, but for explicit
+  // instantiations we'll map to external.
+
   // In C++, the compiler has to emit a definition in every translation unit
   // that references the function.  We should use linkonce_odr because
   // a) if all references in this translation unit are optimized away, we
@@ -419,7 +424,7 @@
   if (Linkage == GVA_ExplicitTemplateInstantiation)
     return !Context.getLangOptions().AppleKext
              ? llvm::Function::WeakODRLinkage
-             : llvm::Function::InternalLinkage;
+             : llvm::Function::ExternalLinkage;
   
   // Otherwise, we have strong external linkage.
   assert(Linkage == GVA_StrongExternal);

Modified: cfe/trunk/test/CodeGenCXX/apple-kext-linkage.C
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/apple-kext-linkage.C?rev=140030&r1=140029&r2=140030&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/apple-kext-linkage.C (original)
+++ cfe/trunk/test/CodeGenCXX/apple-kext-linkage.C Mon Sep 19 13:05:26 2011
@@ -13,13 +13,21 @@
   Derived d1;			// ok
 }
 
+// CHECK: define internal i32 @_Z1fj(
 inline unsigned f(unsigned n) { return n == 0 ? 0 : n + f(n-1); }
 
 unsigned g(unsigned n) { return f(n); }
 
+// rdar://problem/10133200: give explicit instantiations external linkage in kernel mode
+// CHECK: define void @_Z3barIiEvv()
+template <typename T> void bar() {}
+template void bar<int>();
 
+// CHECK: define internal i32 @_Z5identIiET_S0_(
 template <typename X> X ident(X x) { return x; }
+
 int foo(int n) { return ident(n); }
 
-// CHECK-NOT: define linkonce_odr
-// CHECK 5 : define internal
+// CHECK: define internal void @_ZN7DerivedD1Ev(
+// CHECK: define internal void @_ZN7DerivedD0Ev(
+// CHECK: define internal void @_ZN7DeriveddlEPv(





More information about the cfe-commits mailing list