Skip to content

Commit 07b825b

Browse files
committed
Move metadata linking after lazy global materialization/linking.
Summary: Currently, named metadata is linked before the LazilyLinkGlobalValues list is walked and materialized/linked. As a result, references from DISubprogram and DIGlobalVariable metadata to yet unmaterialized functions and variables cause them to be added to the lazy linking list and their definitions are materialized and linked. This makes the llvm-link -only-needed option not have the intended effect when debug information is present, as the otherwise unneeded functions/variables are still linked in. Additionally, for ThinLTO I have implemented a mechanism to only link in debug metadata needed by imported functions. Moving named metadata linking after lazy GV linking will facilitate applying this mechanism to the LTO and "llvm-link -only-needed" cases as well. Reviewers: dexonsmith, tra, dblaikie Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D14195 llvm-svn: 251926
1 parent 04e5877 commit 07b825b

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

llvm/lib/Linker/LinkModules.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,15 +1940,6 @@ bool ModuleLinker::run() {
19401940
linkGlobalValueBody(Src);
19411941
}
19421942

1943-
// Remap all of the named MDNodes in Src into the DstM module. We do this
1944-
// after linking GlobalValues so that MDNodes that reference GlobalValues
1945-
// are properly remapped.
1946-
linkNamedMDNodes();
1947-
1948-
// Merge the module flags into the DstM module.
1949-
if (linkModuleFlagsMetadata())
1950-
return true;
1951-
19521943
// Update the initializers in the DstM module now that all globals that may
19531944
// be referenced are in DstM.
19541945
for (GlobalVariable &Src : SrcM->globals()) {
@@ -1975,6 +1966,15 @@ bool ModuleLinker::run() {
19751966
return true;
19761967
}
19771968

1969+
// Remap all of the named MDNodes in Src into the DstM module. We do this
1970+
// after linking GlobalValues so that MDNodes that reference GlobalValues
1971+
// are properly remapped.
1972+
linkNamedMDNodes();
1973+
1974+
// Merge the module flags into the DstM module.
1975+
if (linkModuleFlagsMetadata())
1976+
return true;
1977+
19781978
return false;
19791979
}
19801980

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@X = external global i32
2+
3+
declare i32 @foo()
4+
5+
define void @bar() {
6+
load i32, i32* @X
7+
call i32 @foo()
8+
ret void
9+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: llvm-as %S/only-needed-named-metadata.ll -o %t.bc
2+
; RUN: llvm-as %S/Inputs/only-needed-named-metadata.ll -o %t2.bc
3+
; RUN: llvm-link -S -only-needed %t2.bc %t.bc | FileCheck %s
4+
; RUN: llvm-link -S -internalize -only-needed %t2.bc %t.bc | FileCheck %s
5+
6+
; CHECK: @U = external global i32
7+
; CHECK: declare i32 @unused()
8+
9+
@X = global i32 5
10+
@U = global i32 6
11+
define i32 @foo() { ret i32 7 }
12+
define i32 @unused() { ret i32 8 }
13+
14+
!llvm.named = !{!0, !1}
15+
!0 = !{i32 ()* @unused}
16+
!1 = !{i32* @U}

0 commit comments

Comments
 (0)