[llvm] r200983 - Don't internalize linkonce_odr non constant variables.

Rafael Espindola rafael.espindola at gmail.com
Fri Feb 7 11:04:43 PST 2014


Author: rafael
Date: Fri Feb  7 13:04:43 2014
New Revision: 200983

URL: http://llvm.org/viewvc/llvm-project?rev=200983&view=rev
Log:
Don't internalize linkonce_odr non constant variables.

Modified:
    llvm/trunk/lib/LTO/LTOModule.cpp
    llvm/trunk/test/LTO/linkonce_odr_func.ll

Modified: llvm/trunk/lib/LTO/LTOModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOModule.cpp?rev=200983&r1=200982&r2=200983&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOModule.cpp (original)
+++ llvm/trunk/lib/LTO/LTOModule.cpp Fri Feb  7 13:04:43 2014
@@ -349,6 +349,7 @@ void LTOModule::addDefinedFunctionSymbol
 }
 
 static bool canBeHidden(const GlobalValue *GV) {
+  // FIXME: this is duplicated with another static function in AsmPrinter.cpp
   GlobalValue::LinkageTypes L = GV->getLinkage();
 
   if (L != GlobalValue::LinkOnceODRLinkage)
@@ -357,6 +358,13 @@ static bool canBeHidden(const GlobalValu
   if (GV->hasUnnamedAddr())
     return true;
 
+  // If it is a non constant variable, it needs to be uniqued across shared
+  // objects.
+  if (const GlobalVariable *Var = dyn_cast<GlobalVariable>(GV)) {
+    if (!Var->isConstant())
+      return false;
+  }
+
   GlobalStatus GS;
   if (GlobalStatus::analyzeGlobal(GV, GS))
     return false;

Modified: llvm/trunk/test/LTO/linkonce_odr_func.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/linkonce_odr_func.ll?rev=200983&r1=200982&r2=200983&view=diff
==============================================================================
--- llvm/trunk/test/LTO/linkonce_odr_func.ll (original)
+++ llvm/trunk/test/LTO/linkonce_odr_func.ll Fri Feb  7 13:04:43 2014
@@ -1,6 +1,6 @@
 ; RUN: llvm-as < %s >%t1
 ; RUN: llvm-lto -o %t2 -dso-symbol=foo1 -dso-symbol=foo2 -dso-symbol=foo3 \
-; RUN:     -dso-symbol=foo4  %t1 -disable-opt
+; RUN:     -dso-symbol=foo4 -dso-symbol=v1 -dso-symbol=v2 %t1 -disable-opt
 ; RUN: llvm-nm %t2 | FileCheck %s
 
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
@@ -26,6 +26,12 @@ define linkonce_odr void @foo4() noinlin
   ret void
 }
 
+; CHECK: r v1
+ at v1 = linkonce_odr constant i32 32
+
+; CHECK: V v2
+ at v2 = linkonce_odr global i32 32
+
 declare void @f(void()*)
 
 declare void @p()





More information about the llvm-commits mailing list