From c1c4373e53f380dd778a6cdb5cb09dbcb0cb4276 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Tue, 30 Apr 2024 18:04:50 -0600 Subject: [PATCH] Prefer references to `_savegpr_14` over `__savegpr` Same for `__restore_gpr`, `__save_fpr` and `__restore_fpr`. A common issue that can be solved with a little bit of special-casing. --- src/obj/symbols.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/obj/symbols.rs b/src/obj/symbols.rs index 9f00e3d..bad062f 100644 --- a/src/obj/symbols.rs +++ b/src/obj/symbols.rs @@ -583,15 +583,24 @@ pub fn best_match_for_reloc( } symbols.sort_by_key(|&(_, symbol)| { let mut rank = match symbol.kind { - ObjSymbolKind::Function | ObjSymbolKind::Object => match reloc_kind { - ObjRelocKind::PpcAddr16Hi - | ObjRelocKind::PpcAddr16Ha - | ObjRelocKind::PpcAddr16Lo => 1, - ObjRelocKind::Absolute - | ObjRelocKind::PpcRel24 - | ObjRelocKind::PpcRel14 - | ObjRelocKind::PpcEmbSda21 => 2, - }, + ObjSymbolKind::Function | ObjSymbolKind::Object => { + // HACK: These are generally not referenced directly, so reduce their rank + if matches!( + symbol.name.as_str(), + "__save_gpr" | "__restore_gpr" | "__save_fpr" | "__restore_fpr" + ) { + return 0; + } + match reloc_kind { + ObjRelocKind::PpcAddr16Hi + | ObjRelocKind::PpcAddr16Ha + | ObjRelocKind::PpcAddr16Lo => 1, + ObjRelocKind::Absolute + | ObjRelocKind::PpcRel24 + | ObjRelocKind::PpcRel14 + | ObjRelocKind::PpcEmbSda21 => 2, + } + } // Label ObjSymbolKind::Unknown => match reloc_kind { ObjRelocKind::PpcAddr16Hi