Skip to content

Commit a44e446

Browse files
author
Jethro Beekman
committed
Add override_export_symbols option to Rust target specification
1 parent 7e82eda commit a44e446

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/librustc_codegen_ssa/back/linker.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,10 @@ impl<'a> Linker for WasmLd<'a> {
10501050
}
10511051

10521052
fn exported_symbols(tcx: TyCtxt, crate_type: CrateType) -> Vec<String> {
1053+
if let Some(ref exports) = tcx.sess.target.target.options.override_export_symbols {
1054+
return exports.clone()
1055+
}
1056+
10531057
let mut symbols = Vec::new();
10541058

10551059
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);

src/librustc_target/spec/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,10 @@ pub struct TargetOptions {
683683
/// target features. This is `true` by default, and `false` for targets like
684684
/// wasm32 where the whole program either has simd or not.
685685
pub simd_types_indirect: bool,
686+
687+
/// If set, have the linker export exactly these symbols, instead of using
688+
/// the usual logic to figure this out from the crate itself.
689+
pub override_export_symbols: Option<Vec<String>>
686690
}
687691

688692
impl Default for TargetOptions {
@@ -763,6 +767,7 @@ impl Default for TargetOptions {
763767
emit_debug_gdb_scripts: true,
764768
requires_uwtable: false,
765769
simd_types_indirect: true,
770+
override_export_symbols: None,
766771
}
767772
}
768773
}
@@ -898,6 +903,14 @@ impl Target {
898903
)
899904
);
900905
} );
906+
($key_name:ident, opt_list) => ( {
907+
let name = (stringify!($key_name)).replace("_", "-");
908+
obj.find(&name[..]).map(|o| o.as_array()
909+
.map(|v| base.options.$key_name = Some(v.iter()
910+
.map(|a| a.as_string().unwrap().to_string()).collect())
911+
)
912+
);
913+
} );
901914
($key_name:ident, optional) => ( {
902915
let name = (stringify!($key_name)).replace("_", "-");
903916
if let Some(o) = obj.find(&name[..]) {
@@ -1044,6 +1057,7 @@ impl Target {
10441057
key!(emit_debug_gdb_scripts, bool);
10451058
key!(requires_uwtable, bool);
10461059
key!(simd_types_indirect, bool);
1060+
key!(override_export_symbols, opt_list);
10471061

10481062
if let Some(array) = obj.find("abi-blacklist").and_then(Json::as_array) {
10491063
for name in array.iter().filter_map(|abi| abi.as_string()) {
@@ -1253,6 +1267,7 @@ impl ToJson for Target {
12531267
target_option_val!(emit_debug_gdb_scripts);
12541268
target_option_val!(requires_uwtable);
12551269
target_option_val!(simd_types_indirect);
1270+
target_option_val!(override_export_symbols);
12561271

12571272
if default.abi_blacklist != self.options.abi_blacklist {
12581273
d.insert("abi-blacklist".to_string(), self.options.abi_blacklist.iter()

0 commit comments

Comments
 (0)