summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2018-12-05 00:09:36 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2018-12-05 00:09:36 +0000
commitff9aaa25e85948f1aebe30c058d9def55ece91ee (patch)
tree43fe6a2bd8d58c8b4b0e746a0af1129eb04117c6
parent8547f4fb7f5b4527c6753b3e3464edeeed9463cc (diff)
downloadbcm5719-llvm-ff9aaa25e85948f1aebe30c058d9def55ece91ee.tar.gz
bcm5719-llvm-ff9aaa25e85948f1aebe30c058d9def55ece91ee.zip
LTO: Don't internalize available_externally globals.
This breaks C and C++ semantics because it can cause the address of the global inside the module to differ from the address outside of the module. Differential Revision: https://reviews.llvm.org/D55237 llvm-svn: 348321
-rw-r--r--llvm/lib/LTO/LTO.cpp5
-rw-r--r--llvm/test/LTO/Resolution/X86/available-externally.ll16
2 files changed, 20 insertions, 1 deletions
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index c1d3cadfaf9..c99d44d1c90 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -365,7 +365,10 @@ static void thinLTOInternalizeAndPromoteGUID(
// Ignore local and appending linkage values since the linker
// doesn't resolve them.
!GlobalValue::isLocalLinkage(S->linkage()) &&
- !GlobalValue::isAppendingLinkage(S->linkage()))
+ S->linkage() != GlobalValue::AppendingLinkage &&
+ // We can't internalize available_externally globals because this
+ // can break function pointer equality.
+ S->linkage() != GlobalValue::AvailableExternallyLinkage)
S->setLinkage(GlobalValue::InternalLinkage);
}
}
diff --git a/llvm/test/LTO/Resolution/X86/available-externally.ll b/llvm/test/LTO/Resolution/X86/available-externally.ll
new file mode 100644
index 00000000000..eb17693c0a9
--- /dev/null
+++ b/llvm/test/LTO/Resolution/X86/available-externally.ll
@@ -0,0 +1,16 @@
+; RUN: opt -module-summary -o %t.bc %s
+; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,px -r %t.bc,bar, -o %t2
+; RUN: llvm-nm %t2.1 | FileCheck %s
+
+; CHECK: U bar
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void ()* @foo() {
+ ret void ()* @bar
+}
+
+define available_externally void @bar() {
+ ret void
+}
OpenPOWER on IntegriCloud