summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2019-10-25 08:40:24 -0700
committerTeresa Johnson <tejohnson@google.com>2019-10-25 12:36:01 -0700
commitcc0b9647b76178bc3869bbfff80535ad86366472 (patch)
tree30cc0a4d69e47b2357ef0bd7133e9fc7d5d13b3f /llvm/lib
parenta4783ef58d3dd52b2079e885e9b4467c6b0b3a16 (diff)
downloadbcm5719-llvm-cc0b9647b76178bc3869bbfff80535ad86366472.tar.gz
bcm5719-llvm-cc0b9647b76178bc3869bbfff80535ad86366472.zip
[LLD][ThinLTO] Handle GUID collision in import global processing
Summary: If there are a GUID collision between two globals checking the summarylist from the import index to make assumption can be dangerous. Do not assume that a GlobalValue that has a GlobalVarSummary actually is a GlobalVariable as it can be another GlobalValue with the same GUID that the summary is connected to. Patch by Joel Klinghed (the_jk@opera.com) Reviewers: evgeny777, tejohnson Reviewed By: tejohnson Subscribers: tejohnson, dblaikie, MaskRay, mehdi_amini, inglorion, hiraditya, steven_wu, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67322
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Utils/FunctionImportUtils.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
index 76b4635ad50..3109224dc2c 100644
--- a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -239,11 +239,17 @@ void FunctionImportGlobalProcessing::processGlobalForThinLTO(GlobalValue &GV) {
// propagateConstants hasn't been run. We can't internalize GV
// in such case.
if (!GV.isDeclaration() && VI && ImportIndex.withGlobalValueDeadStripping()) {
- const auto &SL = VI.getSummaryList();
- auto *GVS = SL.empty() ? nullptr : dyn_cast<GlobalVarSummary>(SL[0].get());
- // At this stage "maybe" is "definitely"
- if (GVS && (GVS->maybeReadOnly() || GVS->maybeWriteOnly()))
- cast<GlobalVariable>(&GV)->addAttribute("thinlto-internalize");
+ if (GlobalVariable *V = dyn_cast<GlobalVariable>(&GV)) {
+ // We can have more than one local with the same GUID, in the case of
+ // same-named locals in different but same-named source files that were
+ // compiled in their respective directories (so the source file name
+ // and resulting GUID is the same). Find the one in this module.
+ auto* GVS = dyn_cast<GlobalVarSummary>(
+ ImportIndex.findSummaryInModule(VI, M.getModuleIdentifier()));
+ // At this stage "maybe" is "definitely"
+ if (GVS && (GVS->maybeReadOnly() || GVS->maybeWriteOnly()))
+ V->addAttribute("thinlto-internalize");
+ }
}
bool DoPromote = false;
OpenPOWER on IntegriCloud