(
section_bytes: &mut [u8],
site: usize,
site_abs: u64,
target_abs: u64,
addend: i64,
)
| 479 | let (hi20, lo12) = crate::isa::pcrel_split(offset); |
| 480 | |
| 481 | let auipc_patched = (auipc_word & 0x0000_0FFF) | (((hi20 << 12) as u32) & 0xFFFF_F000); |
| 482 | let jalr_patched = (jalr_word & !(0xFFF << 20)) | (((lo12 as u32) & 0xFFF) << 20); |
| 483 | |
| 484 | write_u32_at(section_bytes, site, auipc_patched)?; |
| 485 | write_u32_at(section_bytes, site + 4, jalr_patched)?; |
| 486 | Ok(()) |
| 487 | } |
| 488 | |
| 489 | fn patch_jal( |
| 490 | section_bytes: &mut [u8], |
| 491 | site: usize, |
| 492 | site_abs: u64, |
| 493 | target_abs: u64, |
| 494 | addend: i64, |
| 495 | ) -> Result<(), LinkerError> { |
| 496 | let jal_word = read_u32_at(section_bytes, site)?; |
| 497 | let offset = (target_abs as i64) |
| 498 | .wrapping_add(addend) |
| 499 | .wrapping_sub(site_abs as i64); |
| 500 | |
| 501 | if (offset & 1) != 0 { |
| 502 | return Err(LinkerError::new(format!( |
| 503 | "JAL relocation offset {offset} is not 2-byte aligned" |
| 504 | ))); |
no test coverage detected