[llvm-commits] [llvm] r159136 - in /llvm/trunk: include/llvm/GlobalValue.h lib/Transforms/IPO/GlobalOpt.cpp test/Transforms/GlobalOpt/hidden.ll

Matt Beaumont-Gay matthewbg at google.com
Mon Jun 25 18:25:54 PDT 2012


I should also add that this happens at -O2 but not -O1 or lower.

On Mon, Jun 25, 2012 at 6:14 PM, Matt Beaumont-Gay <matthewbg at google.com> wrote:
> Hi Rafael,
>
> This patch is causing us some problems. Our build system links the
> Clang unit tests dynamically, and we're seeing this:
> ld: llvm/tools/clang/unittests/Tooling/ToolingTest.o: in function
> clang::tooling::newFrontendActionFactory_CreatesFrontendActionFactoryFromType_Test::TestBody():llvm/tools/clang/unittests/Tooling/ToolingTest.cpp(.text._ZN5clang7tooling66newFrontendActionFactory_CreatesFrontendActionFactoryFromType_Test8TestBodyEv+0x52):
> error: undefined reference to
> 'clang::SyntaxOnlyAction::~SyntaxOnlyAction()'
>
> I'll work on trying to reproduce this in some reasonably
> self-contained way, but that might take a while; do you have any
> immediate ideas about what might be going wrong?
>
> Thanks,
> Matt
>
> On Mon, Jun 25, 2012 at 7:30 AM, Rafael Espindola
> <rafael.espindola at gmail.com> wrote:
>> Author: rafael
>> Date: Mon Jun 25 09:30:31 2012
>> New Revision: 159136
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=159136&view=rev
>> Log:
>> If a constant or a function has linkonce_odr linkage and unnamed_addr, mark it
>> hidden. Being linkonce_odr guarantees that it is available in every dso that
>> needs it. Being a constant/function with unnamed_addr guarantees that the
>> copies don't have to be merged.
>>
>> Added:
>>    llvm/trunk/test/Transforms/GlobalOpt/hidden.ll
>> Modified:
>>    llvm/trunk/include/llvm/GlobalValue.h
>>    llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
>>
>> Modified: llvm/trunk/include/llvm/GlobalValue.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/GlobalValue.h?rev=159136&r1=159135&r2=159136&view=diff
>> ==============================================================================
>> --- llvm/trunk/include/llvm/GlobalValue.h (original)
>> +++ llvm/trunk/include/llvm/GlobalValue.h Mon Jun 25 09:30:31 2012
>> @@ -122,6 +122,9 @@
>>   static bool isAvailableExternallyLinkage(LinkageTypes Linkage) {
>>     return Linkage == AvailableExternallyLinkage;
>>   }
>> +  static bool isLinkOnceODRLinkage(LinkageTypes Linkage) {
>> +    return Linkage == LinkOnceODRLinkage;
>> +  }
>>   static bool isLinkOnceLinkage(LinkageTypes Linkage) {
>>     return Linkage == LinkOnceAnyLinkage || Linkage == LinkOnceODRLinkage;
>>   }
>> @@ -202,6 +205,9 @@
>>   bool hasAvailableExternallyLinkage() const {
>>     return isAvailableExternallyLinkage(Linkage);
>>   }
>> +  bool hasLinkOnceODRLinkage() const {
>> +    return isLinkOnceODRLinkage(Linkage);
>> +  }
>>   bool hasLinkOnceLinkage() const {
>>     return isLinkOnceLinkage(Linkage);
>>   }
>>
>> Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=159136&r1=159135&r2=159136&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
>> +++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Mon Jun 25 09:30:31 2012
>> @@ -1731,6 +1731,12 @@
>>     return true;
>>   }
>>
>> +  if (GV->hasLinkOnceODRLinkage() && GV->hasUnnamedAddr() && GV->isConstant() &&
>> +      GV->getVisibility() != GlobalValue::HiddenVisibility) {
>> +    GV->setVisibility(GlobalValue::HiddenVisibility);
>> +    return true;
>> +  }
>> +
>>   if (!GV->hasLocalLinkage())
>>     return false;
>>
>> @@ -1743,6 +1749,7 @@
>>   if (!GS.isCompared && !GV->hasUnnamedAddr()) {
>>     GV->setUnnamedAddr(true);
>>     NumUnnamed++;
>> +    return true;
>>   }
>>
>>   if (GV->isConstant() || !GV->hasInitializer())
>> @@ -1917,6 +1924,10 @@
>>       F->eraseFromParent();
>>       Changed = true;
>>       ++NumFnDeleted;
>> +    } else if (F->hasLinkOnceODRLinkage() && F->hasUnnamedAddr() &&
>> +               F->getVisibility() != GlobalValue::HiddenVisibility) {
>> +      F->setVisibility(GlobalValue::HiddenVisibility);
>> +      Changed = true;
>>     } else if (F->hasLocalLinkage()) {
>>       if (F->getCallingConv() == CallingConv::C && !F->isVarArg() &&
>>           !F->hasAddressTaken()) {
>>
>> Added: llvm/trunk/test/Transforms/GlobalOpt/hidden.ll
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/hidden.ll?rev=159136&view=auto
>> ==============================================================================
>> --- llvm/trunk/test/Transforms/GlobalOpt/hidden.ll (added)
>> +++ llvm/trunk/test/Transforms/GlobalOpt/hidden.ll Mon Jun 25 09:30:31 2012
>> @@ -0,0 +1,14 @@
>> +; RUN: opt %s -globalopt -S | FileCheck %s
>> +
>> + at foo = linkonce_odr unnamed_addr constant i32 42
>> +; CHECK: @foo = linkonce_odr hidden unnamed_addr constant i32 42
>> +
>> +define linkonce_odr void @bar() unnamed_addr {
>> +; CHECK: define linkonce_odr hidden void @bar() unnamed_addr {
>> +  ret void
>> +}
>> +
>> +define i32* @zed() {
>> +  call void @bar()
>> +  ret i32* @foo
>> +}
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list