Skip to content

Commit c2b7228

Browse files
Rollup merge of #163188 - dpaoliello:arm64ecsymboledit, r=lqd,bjorn3
Adjust for Arm64EC name mangling when checking for exported symbols After #160679 the Arm64EC nightly validation run internally by Microsoft started failing with: ``` === STDOUT === main.c main.obj : error LNK2019: unresolved external symbol my_add referenced in function #my_add$exit_thunk (EC Symbol) main.obj : error LNK2019: unresolved external symbol my_hash_lookup referenced in function #my_hash_lookup$exit_thunk (EC Symbol) main.obj : error LNK2019: unresolved external symbol call_internal referenced in function #call_internal$exit_thunk (EC Symbol) main.obj : error LNK2019: unresolved external symbol my_safe_div referenced in function #my_safe_div$exit_thunk (EC Symbol) main.exe : fatal error LNK1120: 4 unresolved externals ``` Root cause is that `symbol_edit` wasn't compensating for Arm64EC's name mangling, and so these symbols were missed.
2 parents 5c845c6 + 2705561 commit c2b7228

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

  • compiler/rustc_codegen_ssa/src/back
  • tests/run-make/staticlib-rename-internal-symbols-coff

‎compiler/rustc_codegen_ssa/src/back/symbol_edit.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,10 @@ fn coff_collect_impl<'data, Coff: CoffHeader>(
503503
if strip_underscore {
504504
name = name.strip_prefix('_').unwrap_or(&name).to_string();
505505
}
506-
if !exported.contains(&name) {
506+
let is_exported = exported.contains(&name)
507+
|| (header.machine() == pe::IMAGE_FILE_MACHINE_ARM64EC
508+
&& name.strip_prefix('#').is_some_and(|name| exported.contains(name)));
509+
if !is_exported {
507510
out.insert(name);
508511
}
509512
}

‎tests/run-make/staticlib-rename-internal-symbols-coff/rmake.rs‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ fn check_coff_symbols<Coff: run_make_support::object::read::coff::CoffHeader>(
153153
) {
154154
// ImageSymbol is 18 bytes; ImageSymbolEx (bigobj) is 20.
155155
let sym_size = std::mem::size_of::<Coff::ImageSymbolBytes>();
156-
// i686 decorates symbol names with a leading underscore.
157-
let strip_underscore = header.machine() == pe::IMAGE_FILE_MACHINE_I386;
158156
let Ok(symbols) = header.symbols(data) else { return };
159157
let strings = symbols.strings();
160158
let symtab_base = header.pointer_to_symbol_table() as usize;
@@ -179,8 +177,16 @@ fn check_coff_symbols<Coff: run_make_support::object::read::coff::CoffHeader>(
179177
}
180178
let Ok(name_bytes) = symbol.name(strings) else { continue };
181179
let Ok(mut name) = str::from_utf8(name_bytes).map(String::from) else { continue };
182-
if strip_underscore {
183-
name = name.strip_prefix('_').unwrap_or(&name).to_string();
180+
181+
// Adjust for various symbol decorations.
182+
match header.machine() {
183+
pe::IMAGE_FILE_MACHINE_I386 => {
184+
name = name.strip_prefix('_').unwrap_or(&name).to_string();
185+
}
186+
pe::IMAGE_FILE_MACHINE_ARM64EC => {
187+
name = name.strip_prefix('#').unwrap_or(&name).to_string();
188+
}
189+
_ => {}
184190
}
185191

186192
if EXPORTED.contains(&name.as_str()) {

0 commit comments

Comments
 (0)