Skip to content

Commit a1ca8aa

Browse files
authored
Unrolled build for #148452
Rollup merge of #148452 - Fulgen301:pdb-large-symbols-v0, r=jackh726 Mangle symbols with a mangled name close to PDB limits with v0 instead of legacy mangling to avoid linker errors This is rust-lang/compiler-team#934 As PDB debuginfo has a 64KiB limit for symbol names, we use v0 mangling instead of legacy mangling for symbol names >= 65000 bytes if PDB is used. The cutoff number was chosen to leave some room for potential errors in the empirical measurement of the limit of 65521 bytes, as well as potential symbol prefixes and suffixes that are applied later, plus some generous extra space. Tracking issue: #148429
2 parents c797096 + 21ee1cf commit a1ca8aa

File tree

2 files changed

+29
-1
lines changed
  • compiler

2 files changed

+29
-1
lines changed

compiler/rustc_symbol_mangling/src/lib.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,31 @@ fn compute_symbol_name<'tcx>(
287287
export::compute_hash_of_export_fn(tcx, instance)
288288
),
289289
false => match mangling_version {
290-
SymbolManglingVersion::Legacy => legacy::mangle(tcx, instance, instantiating_crate),
290+
SymbolManglingVersion::Legacy => {
291+
let mangled_name = legacy::mangle(tcx, instance, instantiating_crate);
292+
293+
let mangled_name_too_long = {
294+
// The PDB debug info format cannot store mangled symbol names for which its
295+
// internal record exceeds u16::MAX bytes, a limit multiple Rust projects have been
296+
// hitting due to the verbosity of legacy name mangling. Depending on the linker version
297+
// in use, such symbol names can lead to linker crashes or incomprehensible linker error
298+
// about a limit being hit.
299+
// Mangle those symbols with v0 mangling instead, which gives us more room to breathe
300+
// as v0 mangling is more compact.
301+
// Empirical testing has shown the limit for the symbol name to be 65521 bytes; use
302+
// 65000 bytes to leave some room for prefixes / suffixes as well as unknown scenarios
303+
// with a different limit.
304+
const MAX_SYMBOL_LENGTH: usize = 65000;
305+
306+
tcx.sess.target.uses_pdb_debuginfo() && mangled_name.len() > MAX_SYMBOL_LENGTH
307+
};
308+
309+
if mangled_name_too_long {
310+
v0::mangle(tcx, instance, instantiating_crate, false)
311+
} else {
312+
mangled_name
313+
}
314+
}
291315
SymbolManglingVersion::V0 => v0::mangle(tcx, instance, instantiating_crate, false),
292316
SymbolManglingVersion::Hashed => {
293317
hashed::mangle(tcx, instance, instantiating_crate, || {

compiler/rustc_target/src/spec/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2615,6 +2615,10 @@ impl TargetOptions {
26152615
// XCOFF and MachO don't support COMDAT.
26162616
!self.is_like_aix && !self.is_like_darwin
26172617
}
2618+
2619+
pub fn uses_pdb_debuginfo(&self) -> bool {
2620+
self.debuginfo_kind == DebuginfoKind::Pdb
2621+
}
26182622
}
26192623

26202624
impl TargetOptions {

0 commit comments

Comments
 (0)