Skip to content

Commit d56dbbe

Browse files
authored
Fix exported symbol name
1 parent 860623b commit d56dbbe

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,7 @@ 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(tcx, symbol, cnum));
17031703
}
17041704
});
17051705

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,26 @@ pub fn linking_symbol_name_for_instance_in_crate<'tcx>(
608608
format!("{prefix}{undecorated}{suffix}{args_in_bytes}")
609609
}
610610

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