Skip to content

Commit 0cdd7f5

Browse files
committed
Add all rustc_std_internal_symbol to symbols.o
rustc_std_internal_symbol is meant to call functions from crates where there is no direct dependency on said crate. As they either have to be added to symbols.o or rustc has to introduce an implicit dependency on them to avoid linker errors. The latter is done for some things like the panic runtime, but adding these symbols to symbols.o allows removing those implicit dependencies.
1 parent 3129d37 commit 0cdd7f5

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,7 @@ pub(crate) fn linked_symbols(
18821882
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
18831883
if info.level.is_below_threshold(export_threshold) && !tcx.is_compiler_builtins(cnum)
18841884
|| info.used
1885+
|| info.rustc_std_internal_symbol
18851886
{
18861887
symbols.push((
18871888
symbol_export::linking_symbol_name_for_instance_in_crate(

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
131131
used: codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
132132
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
133133
|| used,
134+
rustc_std_internal_symbol: codegen_attrs
135+
.flags
136+
.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL),
134137
};
135138
(def_id.to_def_id(), info)
136139
})
@@ -143,6 +146,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
143146
level: SymbolExportLevel::C,
144147
kind: SymbolExportKind::Data,
145148
used: false,
149+
rustc_std_internal_symbol: false,
146150
},
147151
);
148152
}
@@ -191,6 +195,7 @@ fn exported_symbols_provider_local<'tcx>(
191195
level: info.level,
192196
kind: SymbolExportKind::Text,
193197
used: info.used,
198+
rustc_std_internal_symbol: info.rustc_std_internal_symbol,
194199
},
195200
)
196201
})
@@ -207,6 +212,7 @@ fn exported_symbols_provider_local<'tcx>(
207212
level: SymbolExportLevel::C,
208213
kind: SymbolExportKind::Text,
209214
used: false,
215+
rustc_std_internal_symbol: false,
210216
},
211217
));
212218
}
@@ -230,6 +236,7 @@ fn exported_symbols_provider_local<'tcx>(
230236
level: SymbolExportLevel::Rust,
231237
kind: SymbolExportKind::Text,
232238
used: false,
239+
rustc_std_internal_symbol: true,
233240
},
234241
));
235242
}
@@ -250,6 +257,7 @@ fn exported_symbols_provider_local<'tcx>(
250257
level: SymbolExportLevel::C,
251258
kind: SymbolExportKind::Data,
252259
used: false,
260+
rustc_std_internal_symbol: false,
253261
},
254262
)
255263
}));
@@ -275,6 +283,7 @@ fn exported_symbols_provider_local<'tcx>(
275283
level: SymbolExportLevel::C,
276284
kind: SymbolExportKind::Data,
277285
used: false,
286+
rustc_std_internal_symbol: false,
278287
},
279288
)
280289
}));
@@ -292,6 +301,7 @@ fn exported_symbols_provider_local<'tcx>(
292301
level: SymbolExportLevel::C,
293302
kind: SymbolExportKind::Data,
294303
used: true,
304+
rustc_std_internal_symbol: false,
295305
},
296306
));
297307
}
@@ -367,6 +377,8 @@ fn exported_symbols_provider_local<'tcx>(
367377
}
368378
}
369379

380+
// Note: These all set rustc_std_internal_symbol to false as generic functions must not
381+
// be marked with this attribute and we are only handling generic functions here.
370382
match *mono_item {
371383
MonoItem::Fn(Instance { def: InstanceKind::Item(def), args }) => {
372384
let has_generics = args.non_erasable_generics().next().is_some();
@@ -382,6 +394,7 @@ fn exported_symbols_provider_local<'tcx>(
382394
level: SymbolExportLevel::Rust,
383395
kind: SymbolExportKind::Text,
384396
used: false,
397+
rustc_std_internal_symbol: false,
385398
},
386399
));
387400
}
@@ -404,6 +417,7 @@ fn exported_symbols_provider_local<'tcx>(
404417
level: SymbolExportLevel::Rust,
405418
kind: SymbolExportKind::Text,
406419
used: false,
420+
rustc_std_internal_symbol: false,
407421
},
408422
));
409423
}
@@ -420,6 +434,7 @@ fn exported_symbols_provider_local<'tcx>(
420434
level: SymbolExportLevel::Rust,
421435
kind: SymbolExportKind::Text,
422436
used: false,
437+
rustc_std_internal_symbol: false,
423438
},
424439
));
425440
}
@@ -430,6 +445,7 @@ fn exported_symbols_provider_local<'tcx>(
430445
level: SymbolExportLevel::Rust,
431446
kind: SymbolExportKind::Text,
432447
used: false,
448+
rustc_std_internal_symbol: false,
433449
},
434450
));
435451
}

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::time::{Duration, Instant};
66
use itertools::Itertools;
77
use rustc_abi::FIRST_VARIANT;
88
use rustc_ast as ast;
9-
use rustc_ast::expand::allocator::{ALLOCATOR_METHODS, AllocatorKind, global_fn_name};
9+
use rustc_ast::expand::allocator::AllocatorKind;
1010
use rustc_attr_data_structures::OptimizeAttr;
1111
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
1212
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
@@ -1056,26 +1056,6 @@ impl CrateInfo {
10561056
.collect::<Vec<_>>();
10571057
symbols.sort_unstable_by(|a, b| a.0.cmp(&b.0));
10581058
linked_symbols.extend(symbols);
1059-
if tcx.allocator_kind(()).is_some() {
1060-
// At least one crate needs a global allocator. This crate may be placed
1061-
// after the crate that defines it in the linker order, in which case some
1062-
// linkers return an error. By adding the global allocator shim methods to
1063-
// the linked_symbols list, linking the generated symbols.o will ensure that
1064-
// circular dependencies involving the global allocator don't lead to linker
1065-
// errors.
1066-
linked_symbols.extend(ALLOCATOR_METHODS.iter().map(|method| {
1067-
(
1068-
add_prefix(
1069-
mangle_internal_symbol(
1070-
tcx,
1071-
global_fn_name(method.name).as_str(),
1072-
),
1073-
SymbolExportKind::Text,
1074-
),
1075-
SymbolExportKind::Text,
1076-
)
1077-
}));
1078-
}
10791059
});
10801060
}
10811061

compiler/rustc_middle/src/middle/exported_symbols.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ pub enum SymbolExportKind {
3535
pub struct SymbolExportInfo {
3636
pub level: SymbolExportLevel,
3737
pub kind: SymbolExportKind,
38+
/// Was the symbol marked as `#[used(compiler)]` or `#[used(linker)]`?
3839
pub used: bool,
40+
/// Was the symbol marked as `#[rustc_std_internal_symbol]`?
41+
pub rustc_std_internal_symbol: bool,
3942
}
4043

4144
#[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]

src/tools/miri/src/bin/miri.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
295295
level: SymbolExportLevel::C,
296296
kind: SymbolExportKind::Text,
297297
used: false,
298+
rustc_std_internal_symbol: false,
298299
},
299300
))
300301
} else {

0 commit comments

Comments
 (0)