Skip to content

Commit 58a05ee

Browse files
committed
Auto merge of #46549 - alexcrichton:thinlto-weak, r=michaelwoerister
rustc: Further tweak linkage in ThinLTO In #46382 the logic around linkage preservation with ThinLTO ws tweaked but the loop that registered all otherwise exported GUID values as "don't internalize me please" was erroneously too conservative and only asking "external" linkage items to not be internalized. Instead we actually want the inversion of that condition, everything *without* "local" linkage to be internalized. This commit updates the condition there, adds a test, and... Closes #46543
2 parents 5f4b09e + 17fb43b commit 58a05ee

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/rustllvm/PassWrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules,
970970
std::set<GlobalValue::GUID> ExportedGUIDs;
971971
for (auto &List : Ret->Index) {
972972
for (auto &GVS: List.second) {
973-
if (!GlobalValue::isExternalLinkage(GVS->linkage()))
973+
if (GlobalValue::isLocalLinkage(GVS->linkage()))
974974
continue;
975975
auto GUID = GVS->getOriginalName();
976976
if (!DeadSymbols.count(GUID))
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -C codegen-units=8 -Z thinlto
12+
// ignore-windows
13+
// min-llvm-version 4.0
14+
15+
#![feature(linkage)]
16+
17+
pub mod foo {
18+
#[linkage = "weak"]
19+
#[no_mangle]
20+
pub extern "C" fn FOO() -> i32 {
21+
0
22+
}
23+
}
24+
25+
mod bar {
26+
extern "C" {
27+
fn FOO() -> i32;
28+
}
29+
30+
pub fn bar() -> i32 {
31+
unsafe { FOO() }
32+
}
33+
}
34+
35+
fn main() {
36+
bar::bar();
37+
}

0 commit comments

Comments
 (0)