Encode `tail symbol` -> `auipc t1, %pcrel_hi(symbol); jalr x0, t1, %pcrel_lo(symbol)`.
(
sec: &mut SectionData,
symbol: &str,
current_addr: u64,
symbols: &super::symbol_table::SymbolTable,
section_bases: &std::collections::HashMap<SectionKind, u64>,
relocations:
| 370 | fn resolve_absolute_symbol( |
| 371 | symbol: &str, |
| 372 | symbols: &super::symbol_table::SymbolTable, |
| 373 | section_bases: &std::collections::HashMap<SectionKind, u64>, |
| 374 | ) -> Option<u64> { |
| 375 | if let Some(&addr) = symbols.all().get(symbol) { |
| 376 | for (section_kind, base) in section_bases { |
| 377 | let qualified_name = format!("{}@{}", symbol, section_kind.name()); |
| 378 | if let Some(&offset) = symbols.all().get(&qualified_name) { |
| 379 | return Some(*base + offset); |
| 380 | } |
| 381 | } |
| 382 | return Some(addr); |
| 383 | } |
| 384 | None |
| 385 | } |
| 386 | |
| 387 | // Compute PC-relative (hi20, lo12) for a target address relative to `current_addr`. |
| 388 | fn pcrel_offsets(target_addr: u64, current_addr: u64) -> (i32, i32) { |
| 389 | crate::isa::pcrel_split((target_addr as i64) - (current_addr as i64)) |
| 390 | } |
| 391 | |
| 392 | // Encode `call symbol` -> `auipc ra, %pcrel_hi(symbol); jalr ra, ra, %pcrel_lo(symbol)`. |
| 393 | fn encode_call( |
| 394 | sec: &mut SectionData, |
| 395 | symbol: &str, |
| 396 | current_addr: u64, |
| 397 | symbols: &super::symbol_table::SymbolTable, |
| 398 | section_bases: &std::collections::HashMap<SectionKind, u64>, |
| 399 | relocations: &mut Vec<RelocationRecord>, |
| 400 | section_name: &str, |
no test coverage detected