From 040cfb4b2582a47f197dc9c5c734f45166ce3ea4 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Wed, 13 Sep 2017 17:09:20 +0000 Subject: [PATCH] ThinLTO: Correctly follow aliasee references when dead stripping. We were previously handling aliases during dead stripping by adding the aliased global's "original name" GUID to the worklist. This will lead to incorrect behaviour if the global has local linkage because the original name GUID will not correspond to the global's GUID in the summary. Because an alias is just another name for the global that it references, there is no need to mark the referenced global as used, or to follow references from any other copies of the global. So all we need to do is to follow references from the aliasee's summary instead of the alias. Differential Revision: https://reviews.llvm.org/D37789 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313157 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/FunctionImport.cpp | 13 +++++------- .../Resolution/X86/Inputs/dead-strip-alias.ll | 4 ++++ test/LTO/Resolution/X86/dead-strip-alias.ll | 20 +++++++++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 test/LTO/Resolution/X86/Inputs/dead-strip-alias.ll create mode 100644 test/LTO/Resolution/X86/dead-strip-alias.ll diff --git a/lib/Transforms/IPO/FunctionImport.cpp b/lib/Transforms/IPO/FunctionImport.cpp index da763b18d4d..b043687f898 100644 --- a/lib/Transforms/IPO/FunctionImport.cpp +++ b/lib/Transforms/IPO/FunctionImport.cpp @@ -488,17 +488,14 @@ void llvm::computeDeadSymbols( while (!Worklist.empty()) { auto VI = Worklist.pop_back_val(); for (auto &Summary : VI.getSummaryList()) { - for (auto Ref : Summary->refs()) + GlobalValueSummary *Base = Summary.get(); + if (auto *AS = dyn_cast(Base)) + Base = &AS->getAliasee(); + for (auto Ref : Base->refs()) visit(Ref); - if (auto *FS = dyn_cast(Summary.get())) + if (auto *FS = dyn_cast(Base)) for (auto Call : FS->calls()) visit(Call.first); - if (auto *AS = dyn_cast(Summary.get())) { - auto AliaseeGUID = AS->getAliasee().getOriginalName(); - ValueInfo AliaseeVI = Index.getValueInfo(AliaseeGUID); - if (AliaseeVI) - visit(AliaseeVI); - } } } Index.setWithGlobalValueDeadStripping(); diff --git a/test/LTO/Resolution/X86/Inputs/dead-strip-alias.ll b/test/LTO/Resolution/X86/Inputs/dead-strip-alias.ll new file mode 100644 index 00000000000..16154d2c45b --- /dev/null +++ b/test/LTO/Resolution/X86/Inputs/dead-strip-alias.ll @@ -0,0 +1,4 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@external = global i8 42 diff --git a/test/LTO/Resolution/X86/dead-strip-alias.ll b/test/LTO/Resolution/X86/dead-strip-alias.ll new file mode 100644 index 00000000000..d009a484e4f --- /dev/null +++ b/test/LTO/Resolution/X86/dead-strip-alias.ll @@ -0,0 +1,20 @@ +; RUN: opt -module-summary -o %t %s +; RUN: opt -module-summary -o %t2 %S/Inputs/dead-strip-alias.ll +; RUN: llvm-lto2 run %t -r %t,main,px -r %t,alias,p -r %t,external, \ +; RUN: %t2 -r %t2,external,p \ +; RUN: -save-temps -o %t3 +; RUN: llvm-nm %t3.1 | FileCheck %s + +; CHECK: D external + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@alias = alias i8*, i8** @internal + +@internal = internal global i8* @external +@external = external global i8 + +define i8** @main() { + ret i8** @alias +} -- 2.50.1