From 66f273be345562fa0ebe275f1ef8c5c621c69f1d Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 7 Feb 2014 19:04:43 +0000 Subject: [PATCH] Don't internalize linkonce_odr non constant variables. llvm-svn: 200983 --- llvm/lib/LTO/LTOModule.cpp | 8 ++++++++ llvm/test/LTO/linkonce_odr_func.ll | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp index 669ccbbaab40..68b7313be728 100644 --- a/llvm/lib/LTO/LTOModule.cpp +++ b/llvm/lib/LTO/LTOModule.cpp @@ -349,6 +349,7 @@ void LTOModule::addDefinedFunctionSymbol(const Function *f) { } 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 GlobalValue *GV) { 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(GV)) { + if (!Var->isConstant()) + return false; + } + GlobalStatus GS; if (GlobalStatus::analyzeGlobal(GV, GS)) return false; diff --git a/llvm/test/LTO/linkonce_odr_func.ll b/llvm/test/LTO/linkonce_odr_func.ll index 8a4932672f6d..a67ffc0dd48e 100644 --- a/llvm/test/LTO/linkonce_odr_func.ll +++ b/llvm/test/LTO/linkonce_odr_func.ll @@ -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() noinline { ret void } +; CHECK: r v1 +@v1 = linkonce_odr constant i32 32 + +; CHECK: V v2 +@v2 = linkonce_odr global i32 32 + declare void @f(void()*) declare void @p()