1
Fork 0

Auto merge of #85673 - csmoe:export-exe-sym, r=bjorn3

RFC-2841: add codegen flag export symbols from executable

Closes #84161
r? `@nikomatsakis` `@Mark-Simulacrum`
This commit is contained in:
bors 2022-07-25 14:04:40 +00:00
commit dc2d232c74
7 changed files with 42 additions and 5 deletions

View file

@ -2082,7 +2082,12 @@ fn add_order_independent_options(
// sections to ensure we have all the data for PGO.
let keep_metadata =
crate_type == CrateType::Dylib || sess.opts.cg.profile_generate.enabled();
cmd.gc_sections(keep_metadata);
if crate_type != CrateType::Executable || !sess.opts.unstable_opts.export_executable_symbols
{
cmd.gc_sections(keep_metadata);
} else {
cmd.no_gc_sections();
}
}
cmd.set_output_kind(link_output_kind, out_filename);

View file

@ -640,9 +640,14 @@ impl<'a> Linker for GccLinker<'a> {
fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType, symbols: &[String]) {
// Symbol visibility in object files typically takes care of this.
if crate_type == CrateType::Executable && self.sess.target.override_export_symbols.is_none()
{
return;
if crate_type == CrateType::Executable {
let should_export_executable_symbols =
self.sess.opts.unstable_opts.export_executable_symbols;
if self.sess.target.override_export_symbols.is_none()
&& !should_export_executable_symbols
{
return;
}
}
// We manually create a list of exported symbols to ensure we don't expose any more.
@ -969,7 +974,11 @@ impl<'a> Linker for MsvcLinker<'a> {
fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType, symbols: &[String]) {
// Symbol visibility takes care of this typically
if crate_type == CrateType::Executable {
return;
let should_export_executable_symbols =
self.sess.opts.unstable_opts.export_executable_symbols;
if !should_export_executable_symbols {
return;
}
}
let path = tmpdir.join("lib.def");