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

Function encode_la

crates/asm-to-binary/src/assembler/encode.rs:401–424  ·  view source on GitHub ↗

Encode `la rd, symbol` -> `auipc rd, %pcrel_hi(symbol); addi rd, rd, %pcrel_lo(symbol)`. Always emits a relocation since section merging may change cross-section distances.

(
    sec: &mut SectionData,
    rd: u8,
    symbol: &str,
    current_addr: u64,
    symbols: &super::symbol_table::SymbolTable,
    section_bases: &std::collections::HashMap<SectionKind, u64>,
    r

Source from the content-addressed store, hash-verified

399 relocations: &mut Vec<RelocationRecord>,
400 section_name: &str,
401) {
402 if let Some(target_addr) = resolve_absolute_symbol(symbol, symbols, section_bases) {
403 let (hi20, lo12) = pcrel_offsets(target_addr, current_addr);
404 sec.push_u32_le(Auipc::new(1, hi20 << 12).encode());
405 sec.push_u32_le(Jalr::new(1, 1, lo12).encode());
406 return;
407 }
408 // Emit relocation when the target is in a different object.
409 let reloc_offset = sec.current_offset();
410 sec.push_u32_le(Auipc::new(1, 0).encode());
411 sec.push_u32_le(Jalr::new(1, 1, 0).encode());
412 relocations.push(RelocationRecord {
413 section: section_name.to_owned(),
414 offset: reloc_offset,
415 symbol: symbol.to_owned(),
416 kind: RelocationKind::CallPlt,
417 addend: 0,
418 });
419}
420
421// Encode `tail symbol` -> `auipc t1, %pcrel_hi(symbol); jalr x0, t1, %pcrel_lo(symbol)`.
422fn encode_tail(
423 sec: &mut SectionData,
424 symbol: &str,
425 current_addr: u64,
426 symbols: &super::symbol_table::SymbolTable,
427 section_bases: &std::collections::HashMap<SectionKind, u64>,

Callers 1

encodeFunction · 0.85

Calls 6

resolve_absolute_symbolFunction · 0.85
pcrel_offsetsFunction · 0.85
current_offsetMethod · 0.80
push_u32_leMethod · 0.80
pushMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected