Skip to content

Commit f4b84d2

Browse files
committed
Fix exported symbol name
1 parent ebd915e commit f4b84d2

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,9 @@ fn exported_symbols_for_non_proc_macro(tcx: TyCtxt<'_>, crate_type: CrateType) -
17481748
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
17491749
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
17501750
if info.level.is_below_threshold(export_threshold) {
1751-
symbols.push(symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum));
1751+
symbols.push(symbol_export::exporting_symbol_name_for_instance_in_crate(
1752+
tcx, symbol, cnum,
1753+
));
17521754
}
17531755
});
17541756

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 19 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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)