llvm.org GIT mirror llvm / 10a832f
[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 Bob Haarman 1 year, 1 month ago
2 changed file(s) with 36 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
871871 GlobalValue *GV =
872872 RegularLTO.CombinedModule->getNamedValue(R.second.IRName);
873873 // Ignore symbols defined in other partitions.
874 if (!GV || GV->hasLocalLinkage())
874 // Also skip declarations, which are not allowed to have internal linkage.
875 if (!GV || GV->hasLocalLinkage() || GV->isDeclaration())
875876 continue;
876877 GV->setUnnamedAddr(R.second.UnnamedAddr ? GlobalValue::UnnamedAddr::Global
877878 : GlobalValue::UnnamedAddr::None);
0 ; RUN: opt -module-summary -o %t.o %s
1 ; RUN: llvm-lto2 run -save-temps -o %t.lto.o %t.o \
2 ; RUN: -r=%t.o,foo,plx \
3 ; RUN: -r=%t.o,get,pl
4 ; RUN: llvm-dis %t.lto.o.0.2.internalize.bc >/dev/null 2>%t.dis.stderr || true
5 ; RUN: FileCheck -allow-empty %s < %t.dis.stderr
6
7 ; CHECK-NOT: Global is external, but doesn't have external or weak linkage
8
9 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
10 target triple = "x86_64-unknown-linux-gnu"
11
12 define i32 @foo() {
13 call void @llvm.dbg.value(metadata i32 ()* @get, metadata !7, metadata !DIExpression()), !dbg !DILocation(scope: !6)
14 ret i32 0
15 }
16
17 define i32 @get() {
18 ret i32 0
19 }
20
21 declare void @llvm.dbg.value(metadata, metadata, metadata)
22
23 !llvm.dbg.cu = !{!0}
24 !llvm.module.flags = !{!2, !3, !4, !5}
25
26 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1)
27 !1 = !DIFile(filename: "t.cc", directory: "/tmp/t")
28 !2 = !{i32 2, !"Dwarf Version", i32 4}
29 !3 = !{i32 2, !"Debug Info Version", i32 3}
30 !4 = !{i32 1, !"wchar_size", i32 4}
31 !5 = !{i32 1, !"ThinLTO", i32 0}
32 !6 = distinct !DISubprogram(unit: !0)
33 !7 = !DILocalVariable(name: "get", scope: !6)