MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / patch_la

Function patch_la

crates/asm-to-binary/src/object_linker.rs:481–501  ·  view source on GitHub ↗
(
    section_bytes: &mut [u8],
    site: usize,
    site_abs: u64,
    target_abs: u64,
    addend: i64,
)

Source from the content-addressed store, hash-verified

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
489fn 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 )));

Callers 1

linkMethod · 0.85

Calls 3

read_u32_atFunction · 0.85
write_u32_atFunction · 0.85
pcrel_splitFunction · 0.70

Tested by

no test coverage detected