feat: impl export-executable-symbols
This commit is contained in:
parent
babff2211e
commit
6674c94d15
@ -2082,7 +2082,12 @@ fn add_order_independent_options(
|
|||||||
// sections to ensure we have all the data for PGO.
|
// sections to ensure we have all the data for PGO.
|
||||||
let keep_metadata =
|
let keep_metadata =
|
||||||
crate_type == CrateType::Dylib || sess.opts.cg.profile_generate.enabled();
|
crate_type == CrateType::Dylib || sess.opts.cg.profile_generate.enabled();
|
||||||
|
if crate_type != CrateType::Executable || !sess.opts.unstable_opts.export_executable_symbols
|
||||||
|
{
|
||||||
cmd.gc_sections(keep_metadata);
|
cmd.gc_sections(keep_metadata);
|
||||||
|
} else {
|
||||||
|
cmd.no_gc_sections();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.set_output_kind(link_output_kind, out_filename);
|
cmd.set_output_kind(link_output_kind, out_filename);
|
||||||
|
@ -640,10 +640,15 @@ fn no_default_libraries(&mut self) {
|
|||||||
|
|
||||||
fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType, symbols: &[String]) {
|
fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType, symbols: &[String]) {
|
||||||
// Symbol visibility in object files typically takes care of this.
|
// Symbol visibility in object files typically takes care of this.
|
||||||
if crate_type == CrateType::Executable && self.sess.target.override_export_symbols.is_none()
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// We manually create a list of exported symbols to ensure we don't expose any more.
|
// We manually create a list of exported symbols to ensure we don't expose any more.
|
||||||
// The object files have far more public symbols than we actually want to export,
|
// The object files have far more public symbols than we actually want to export,
|
||||||
@ -969,8 +974,12 @@ fn debuginfo(&mut self, strip: Strip, natvis_debugger_visualizers: &[PathBuf]) {
|
|||||||
fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType, symbols: &[String]) {
|
fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType, symbols: &[String]) {
|
||||||
// Symbol visibility takes care of this typically
|
// Symbol visibility takes care of this typically
|
||||||
if crate_type == CrateType::Executable {
|
if crate_type == CrateType::Executable {
|
||||||
|
let should_export_executable_symbols =
|
||||||
|
self.sess.opts.unstable_opts.export_executable_symbols;
|
||||||
|
if !should_export_executable_symbols {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let path = tmpdir.join("lib.def");
|
let path = tmpdir.join("lib.def");
|
||||||
let res: io::Result<()> = try {
|
let res: io::Result<()> = try {
|
||||||
|
@ -733,6 +733,7 @@ macro_rules! tracked {
|
|||||||
tracked!(debug_macros, true);
|
tracked!(debug_macros, true);
|
||||||
tracked!(dep_info_omit_d_target, true);
|
tracked!(dep_info_omit_d_target, true);
|
||||||
tracked!(drop_tracking, true);
|
tracked!(drop_tracking, true);
|
||||||
|
tracked!(export_executable_symbols, true);
|
||||||
tracked!(dual_proc_macros, true);
|
tracked!(dual_proc_macros, true);
|
||||||
tracked!(dwarf_version, Some(5));
|
tracked!(dwarf_version, Some(5));
|
||||||
tracked!(emit_thin_lto, false);
|
tracked!(emit_thin_lto, false);
|
||||||
|
@ -1282,6 +1282,8 @@ pub(crate) fn parse_branch_protection(
|
|||||||
"emit a section containing stack size metadata (default: no)"),
|
"emit a section containing stack size metadata (default: no)"),
|
||||||
emit_thin_lto: bool = (true, parse_bool, [TRACKED],
|
emit_thin_lto: bool = (true, parse_bool, [TRACKED],
|
||||||
"emit the bc module with thin LTO info (default: yes)"),
|
"emit the bc module with thin LTO info (default: yes)"),
|
||||||
|
export_executable_symbols: bool = (false, parse_bool, [TRACKED],
|
||||||
|
"export symbols from executables, as if they were dynamic libraries"),
|
||||||
fewer_names: Option<bool> = (None, parse_opt_bool, [TRACKED],
|
fewer_names: Option<bool> = (None, parse_opt_bool, [TRACKED],
|
||||||
"reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) \
|
"reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) \
|
||||||
(default: no)"),
|
(default: no)"),
|
||||||
|
11
src/test/run-make/export-executable-symbols/Makefile
Normal file
11
src/test/run-make/export-executable-symbols/Makefile
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
-include ../../run-make-fulldeps/tools.mk
|
||||||
|
|
||||||
|
# ignore-wasm32
|
||||||
|
# ignore-wasm64
|
||||||
|
# ignore-none no-std is not supported
|
||||||
|
# only-linux
|
||||||
|
|
||||||
|
all:
|
||||||
|
$(RUSTC) -Zexport-executable-symbols main.rs --target $(TARGET) --crate-type=bin
|
||||||
|
nm $(TMPDIR)/main | $(CGREP) exported_symbol
|
||||||
|
|
8
src/test/run-make/export-executable-symbols/main.rs
Normal file
8
src/test/run-make/export-executable-symbols/main.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// edition:2018
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub fn exported_symbol() -> i8 {
|
||||||
|
42
|
||||||
|
}
|
@ -37,6 +37,7 @@
|
|||||||
-Z dwarf-version=val -- version of DWARF debug information to emit (default: 2 or 4, depending on platform)
|
-Z dwarf-version=val -- version of DWARF debug information to emit (default: 2 or 4, depending on platform)
|
||||||
-Z emit-stack-sizes=val -- emit a section containing stack size metadata (default: no)
|
-Z emit-stack-sizes=val -- emit a section containing stack size metadata (default: no)
|
||||||
-Z emit-thin-lto=val -- emit the bc module with thin LTO info (default: yes)
|
-Z emit-thin-lto=val -- emit the bc module with thin LTO info (default: yes)
|
||||||
|
-Z export-executable-symbols=val -- export symbols from executables, as if they were dynamic libraries
|
||||||
-Z fewer-names=val -- reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) (default: no)
|
-Z fewer-names=val -- reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) (default: no)
|
||||||
-Z force-unstable-if-unmarked=val -- force all crates to be `rustc_private` unstable (default: no)
|
-Z force-unstable-if-unmarked=val -- force all crates to be `rustc_private` unstable (default: no)
|
||||||
-Z fuel=val -- set the optimization fuel quota for a crate
|
-Z fuel=val -- set the optimization fuel quota for a crate
|
||||||
|
Loading…
Reference in New Issue
Block a user