Skip to content

Commit dad074c

Browse files
committed
Fix exported symbol name
1 parent 8c81edc commit dad074c

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,9 @@ fn exported_symbols_for_non_proc_macro(tcx: TyCtxt<'_>, crate_type: CrateType) -
16991699
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
17001700
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
17011701
if info.level.is_below_threshold(export_threshold) {
1702-
symbols.push(symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum));
1702+
symbols.push(symbol_export::exporting_symbol_name_for_instance_in_crate(
1703+
tcx, symbol, cnum,
1704+
));
17031705
}
17041706
});
17051707

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+19
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,25 @@ pub fn linking_symbol_name_for_instance_in_crate<'tcx>(
608608
format!("{prefix}{undecorated}{suffix}{args_in_bytes}")
609609
}
610610

611+
pub fn exporting_symbol_name_for_instance_in_crate<'tcx>(
612+
tcx: TyCtxt<'tcx>,
613+
symbol: ExportedSymbol<'tcx>,
614+
cnum: CrateNum,
615+
) -> String {
616+
let undecorated = symbol_name_for_instance_in_crate(tcx, symbol, cnum);
617+
618+
if tcx.sess.target.force_emulated_tls
619+
&& let ExportedSymbol::NonGeneric(def_id) = symbol
620+
&& tcx.is_thread_local_static(def_id)
621+
{
622+
// When using emutls, LLVM will add the `__emutls_v.` prefix to thread local symbols,
623+
// and exported symbol name need to match this.
624+
format!("__emutls_v.{undecorated}")
625+
} else {
626+
undecorated
627+
}
628+
}
629+
611630
fn wasm_import_module_map(tcx: TyCtxt<'_>, cnum: CrateNum) -> FxHashMap<DefId, String> {
612631
// Build up a map from DefId to a `NativeLib` structure, where
613632
// `NativeLib` internally contains information about

compiler/rustc_target/src/spec/base/android.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub fn opts() -> TargetOptions {
55
base.os = "android".into();
66
base.is_like_android = true;
77
base.default_dwarf_version = 2;
8+
base.force_emulated_tls = true;
89
base.has_thread_local = true;
910
base.supported_sanitizers = SanitizerSet::ADDRESS;
1011
// This is for backward compatibility, see https://github.com/rust-lang/rust/issues/49867

0 commit comments

Comments
 (0)