Skip to content

Commit 4053e25

Browse files
committed
librustc_trans: Mark some profiler symbols as exported to avoid LTO removing them.
1 parent 8a4cebd commit 4053e25

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/librustc_trans/back/symbol_export.rs

+14
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,20 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
223223
}
224224
}
225225

226+
if tcx.sess.opts.debugging_opts.pgo_gen.is_some() {
227+
// These are weak symbols that point to the profile version and the
228+
// profile name, which need to be treated as exported so LTO doesn't nix
229+
// them.
230+
const PROFILER_WEAK_SYMBOLS: [&'static str; 2] = [
231+
"__llvm_profile_raw_version",
232+
"__llvm_profile_filename",
233+
];
234+
for sym in &PROFILER_WEAK_SYMBOLS {
235+
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(sym));
236+
symbols.push((exported_symbol, SymbolExportLevel::C));
237+
}
238+
}
239+
226240
if tcx.sess.crate_types.borrow().contains(&config::CrateTypeDylib) {
227241
let symbol_name = metadata_symbol_name(tcx);
228242
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(&symbol_name));
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-include ../tools.mk
2+
3+
all:
4+
ifeq ($(PROFILER_SUPPORT),1)
5+
$(RUSTC) -Copt-level=3 -Clto=fat -Z pgo-gen=test.profraw test.rs
6+
$(call RUN,test) || exit 1
7+
[ -e "$(TMPDIR)/test.profraw" ] || (echo "No .profraw file"; exit 1)
8+
endif

src/test/run-make/pgo-gen-lto/test.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2018 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+
fn main() {}

0 commit comments

Comments
 (0)