aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2018-12-05 00:09:36 +0000
committerChih-Hung Hsieh <chh@google.com>2018-12-05 11:36:53 -0800
commitf07c0194186ad2dfb47ad6adf42a2b86c1dee26d (patch)
tree288266d484f7172ca32f1bbf15c714407eb01729
parent217657f2dbaf8ce5e685c718a8698fe75dab6f22 (diff)
downloadllvm-f07c0194186ad2dfb47ad6adf42a2b86c1dee26d.tar.gz
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 Change-Id: I84f5d3860beed2953078b3bd9ea0c6d2c334e3cb git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348321 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/LTO/LTO.cpp5
-rw-r--r--test/LTO/Resolution/X86/available-externally.ll16
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/LTO/LTO.cpp b/lib/LTO/LTO.cpp
index 6b11f690ef3..d8e5d6ed6be 100644
--- a/lib/LTO/LTO.cpp
+++ b/lib/LTO/LTO.cpp
@@ -356,7 +356,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/test/LTO/Resolution/X86/available-externally.ll b/test/LTO/Resolution/X86/available-externally.ll
new file mode 100644
index 00000000000..eb17693c0a9
--- /dev/null
+++ b/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
+}