Skip to content

Commit a2af4d4

Browse files
committed
Only export the sanitizer symbols for LTO
Don't export them from cdylibs. There is no need to do so and it complicates exported_non_generic_symbols.
1 parent 43a2166 commit a2af4d4

File tree

2 files changed

+27
-48
lines changed

2 files changed

+27
-48
lines changed

compiler/rustc_codegen_ssa/src/back/lto.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::ffi::CString;
22
use std::sync::Arc;
33

44
use rustc_data_structures::memmap::Mmap;
5+
use rustc_hir::attrs::SanitizerSet;
56
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
67
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo, SymbolExportLevel};
78
use rustc_middle::ty::TyCtxt;
@@ -115,6 +116,31 @@ pub(super) fn exported_symbols_for_lto(
115116
}
116117
}
117118

119+
if tcx.sess.instrument_coverage() || tcx.sess.opts.cg.profile_generate.enabled() {
120+
// These are weak symbols that point to the profile version and the
121+
// profile name, which need to be treated as exported so LTO doesn't nix
122+
// them.
123+
const PROFILER_WEAK_SYMBOLS: [&str; 2] =
124+
["__llvm_profile_raw_version", "__llvm_profile_filename"];
125+
126+
symbols_below_threshold.extend(PROFILER_WEAK_SYMBOLS.iter().map(|&sym| sym.to_owned()));
127+
}
128+
129+
if tcx.sess.opts.unstable_opts.sanitizer.contains(SanitizerSet::MEMORY) {
130+
let mut msan_weak_symbols = Vec::new();
131+
132+
// Similar to profiling, preserve weak msan symbol during LTO.
133+
if tcx.sess.opts.unstable_opts.sanitizer_recover.contains(SanitizerSet::MEMORY) {
134+
msan_weak_symbols.push("__msan_keep_going");
135+
}
136+
137+
if tcx.sess.opts.unstable_opts.sanitizer_memory_track_origins != 0 {
138+
msan_weak_symbols.push("__msan_track_origins");
139+
}
140+
141+
symbols_below_threshold.extend(msan_weak_symbols.into_iter().map(|sym| sym.to_owned()));
142+
}
143+
118144
symbols_below_threshold
119145
}
120146

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::ty::{self, GenericArgKind, GenericArgsRef, Instance, SymbolNam
1515
use rustc_middle::util::Providers;
1616
use rustc_session::config::{CrateType, OomStrategy};
1717
use rustc_symbol_mangling::mangle_internal_symbol;
18-
use rustc_target::spec::{SanitizerSet, TlsModel};
18+
use rustc_target::spec::TlsModel;
1919
use tracing::debug;
2020

2121
use crate::base::allocator_kind_for_codegen;
@@ -242,53 +242,6 @@ fn exported_non_generic_symbols_provider_local<'tcx>(
242242
}
243243
}
244244

245-
if tcx.sess.instrument_coverage() || tcx.sess.opts.cg.profile_generate.enabled() {
246-
// These are weak symbols that point to the profile version and the
247-
// profile name, which need to be treated as exported so LTO doesn't nix
248-
// them.
249-
const PROFILER_WEAK_SYMBOLS: [&str; 2] =
250-
["__llvm_profile_raw_version", "__llvm_profile_filename"];
251-
252-
symbols.extend(PROFILER_WEAK_SYMBOLS.iter().map(|sym| {
253-
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym));
254-
(
255-
exported_symbol,
256-
SymbolExportInfo {
257-
level: SymbolExportLevel::C,
258-
kind: SymbolExportKind::Data,
259-
used: false,
260-
rustc_std_internal_symbol: false,
261-
},
262-
)
263-
}));
264-
}
265-
266-
if tcx.sess.opts.unstable_opts.sanitizer.contains(SanitizerSet::MEMORY) {
267-
let mut msan_weak_symbols = Vec::new();
268-
269-
// Similar to profiling, preserve weak msan symbol during LTO.
270-
if tcx.sess.opts.unstable_opts.sanitizer_recover.contains(SanitizerSet::MEMORY) {
271-
msan_weak_symbols.push("__msan_keep_going");
272-
}
273-
274-
if tcx.sess.opts.unstable_opts.sanitizer_memory_track_origins != 0 {
275-
msan_weak_symbols.push("__msan_track_origins");
276-
}
277-
278-
symbols.extend(msan_weak_symbols.into_iter().map(|sym| {
279-
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym));
280-
(
281-
exported_symbol,
282-
SymbolExportInfo {
283-
level: SymbolExportLevel::C,
284-
kind: SymbolExportKind::Data,
285-
used: false,
286-
rustc_std_internal_symbol: false,
287-
},
288-
)
289-
}));
290-
}
291-
292245
// Sort so we get a stable incr. comp. hash.
293246
symbols.sort_by_cached_key(|s| s.0.symbol_name_for_local_instance(tcx));
294247

0 commit comments

Comments
 (0)