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

Method to_object

crates/asm-to-binary/src/assembler/output.rs:516–885  ·  view source on GitHub ↗

Produce a relocatable ELF-64 object (`ET_REL`) suitable for external linking.

(&self, object_name: &str)

Source from the content-addressed store, hash-verified

514 // ---- Emit section headers ----
515 debug_assert_eq!(buf.len() as u64, shdrs_offset);
516
517 // SHT_NULL
518 buf.extend_from_slice(&[0u8; 64]);
519
520 // One header per program section
521 for (i, es) in elf_secs.iter().enumerate() {
522 let filesz = if matches!(es.sec.kind, Some(SectionKind::Bss)) {
523 0u64
524 } else {
525 es.sec.bytes.len() as u64
526 };
527 push_u32_le(&mut buf, shstrtab_indices[i]); // sh_name
528 push_u32_le(&mut buf, es.sh_type); // sh_type
529 push_u64_le(&mut buf, es.sh_flags); // sh_flags
530 push_u64_le(&mut buf, es.load_addr); // sh_addr
531 push_u64_le(&mut buf, sec_file_offsets[i]); // sh_offset
532 push_u64_le(&mut buf, filesz); // sh_size
533 push_u32_le(&mut buf, 0); // sh_link
534 push_u32_le(&mut buf, 0); // sh_info
535 push_u64_le(&mut buf, 4); // sh_addralign
536 push_u64_le(&mut buf, 0); // sh_entsize
537 }
538
539 // .shstrtab header
540 push_u32_le(&mut buf, shstrtab_name_idx);
541 push_u32_le(&mut buf, SHT_STRTAB);
542 push_u64_le(&mut buf, 0);
543 push_u64_le(&mut buf, 0);
544 push_u64_le(&mut buf, shstrtab_offset);
545 push_u64_le(&mut buf, shstrtab.len() as u64);
546 push_u32_le(&mut buf, 0);
547 push_u32_le(&mut buf, 0);
548 push_u64_le(&mut buf, 1);
549 push_u64_le(&mut buf, 0);
550
551 // .strtab header
552 push_u32_le(&mut buf, strtab_name_idx);
553 push_u32_le(&mut buf, SHT_STRTAB);
554 push_u64_le(&mut buf, 0);
555 push_u64_le(&mut buf, 0);
556 push_u64_le(&mut buf, strtab_offset);
557 push_u64_le(&mut buf, strtab.len() as u64);
558 push_u32_le(&mut buf, 0);
559 push_u32_le(&mut buf, 0);
560 push_u64_le(&mut buf, 1);
561 push_u64_le(&mut buf, 0);
562
563 // .symtab header
564 let strtab_shndx = 1 + n_prog_secs + 1; // index of .strtab
565 let n_local_syms = sorted_syms
566 .iter()
567 .filter(|(n, _)| !self.global_symbols.contains(n))
568 .count()
569 + 1; // +1 for STN_UNDEF
570 push_u32_le(&mut buf, symtab_name_idx);
571 push_u32_le(&mut buf, SHT_SYMTAB);
572 push_u64_le(&mut buf, 0);
573 push_u64_le(&mut buf, 0);

Callers 4

assemble_namedMethod · 0.80
cmd_hll_to_asmFunction · 0.80
write_object_fileMethod · 0.80

Calls 12

push_u32_leFunction · 0.85
push_u16_leFunction · 0.85
push_u64_leFunction · 0.85
align_up_toFunction · 0.85
is_executableMethod · 0.80
pushMethod · 0.80
collectMethod · 0.80
getMethod · 0.80
cloneMethod · 0.45
nameMethod · 0.45
insertMethod · 0.45
containsMethod · 0.45