aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Haarman <llvm@inglorion.net>2018-07-27 05:40:29 +0000
committerBob Haarman <llvm@inglorion.net>2018-07-27 05:40:29 +0000
commit10a832fe97fefabc503c8cb257fdb1954da8df0e (patch)
tree68fd2b876e0eafecaeebdd7259c9d77f8159f0e9
parent01a1fe5ce8b72d608f8b7c9852ea780a55492e66 (diff)
[LTO] Don't internalize declarations
Summary: Some links were failing with "Global is external, but doesn't have external or weak linkage!" in ThinLTO builds with debug information. This happened when we elide the body of a global that is referenced by debug info. This results in a declaration, which we would then internalize - but declarations cannot be internal. This change avoids the problem by not internalizing these declarations. Fixes PR38046. Reviewers: pcc, tejohnson Subscribers: mehdi_amini, aprantl, hiraditya, JDevlieghere, steven_wu, dexonsmith, llvm-commits Differential Revision: https://reviews.llvm.org/D49777 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338100 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/LTO/LTO.cpp3
-rw-r--r--test/LTO/X86/pr38046.ll34
2 files changed, 36 insertions, 1 deletions
diff --git a/lib/LTO/LTO.cpp b/lib/LTO/LTO.cpp
index 32b48ddfef7..68d210cb7d7 100644
--- a/lib/LTO/LTO.cpp
+++ b/lib/LTO/LTO.cpp
@@ -872,7 +872,8 @@ Error LTO::runRegularLTO(AddStreamFn AddStream) {
GlobalValue *GV =
RegularLTO.CombinedModule->getNamedValue(R.second.IRName);
// Ignore symbols defined in other partitions.
- if (!GV || GV->hasLocalLinkage())
+ // Also skip declarations, which are not allowed to have internal linkage.
+ if (!GV || GV->hasLocalLinkage() || GV->isDeclaration())
continue;
GV->setUnnamedAddr(R.second.UnnamedAddr ? GlobalValue::UnnamedAddr::Global
: GlobalValue::UnnamedAddr::None);
diff --git a/test/LTO/X86/pr38046.ll b/test/LTO/X86/pr38046.ll
new file mode 100644
index 00000000000..6743121b715
--- /dev/null
+++ b/test/LTO/X86/pr38046.ll
@@ -0,0 +1,34 @@
+; RUN: opt -module-summary -o %t.o %s
+; RUN: llvm-lto2 run -save-temps -o %t.lto.o %t.o \
+; RUN: -r=%t.o,foo,plx \
+; RUN: -r=%t.o,get,pl
+; RUN: llvm-dis %t.lto.o.0.2.internalize.bc >/dev/null 2>%t.dis.stderr || true
+; RUN: FileCheck -allow-empty %s < %t.dis.stderr
+
+; CHECK-NOT: Global is external, but doesn't have external or weak linkage
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @foo() {
+ call void @llvm.dbg.value(metadata i32 ()* @get, metadata !7, metadata !DIExpression()), !dbg !DILocation(scope: !6)
+ ret i32 0
+}
+
+define i32 @get() {
+ ret i32 0
+}
+
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1)
+!1 = !DIFile(filename: "t.cc", directory: "/tmp/t")
+!2 = !{i32 2, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{i32 1, !"ThinLTO", i32 0}
+!6 = distinct !DISubprogram(unit: !0)
+!7 = !DILocalVariable(name: "get", scope: !6)