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

Function parse_sections

tests/integration/linker.rs:92–122  ·  view source on GitHub ↗
(elf: &[u8])

Source from the content-addressed store, hash-verified

90}
91
92fn parse_sections(elf: &[u8]) -> Vec<SectionHeader> {
93 let shoff = read_u64(elf, 40) as usize;
94 let shentsize = read_u16(elf, 58) as usize;
95 let shnum = read_u16(elf, 60) as usize;
96 let shstrndx = read_u16(elf, 62) as usize;
97
98 let mut raw = Vec::with_capacity(shnum);
99 for index in 0..shnum {
100 let base = shoff + index * shentsize;
101 raw.push((
102 index,
103 read_u32(elf, base),
104 read_u64(elf, base + 16),
105 read_u64(elf, base + 24),
106 read_u64(elf, base + 32),
107 read_u64(elf, base + 56),
108 ));
109 }
110
111 let shstrtab = &elf[raw[shstrndx].3 as usize..(raw[shstrndx].3 + raw[shstrndx].4) as usize];
112
113 raw.into_iter()
114 .map(|(_index, name_off, sh_addr, sh_offset, sh_size, sh_entsize)| SectionHeader {
115 name: read_c_string(shstrtab, name_off),
116 sh_addr,
117 sh_offset,
118 sh_size,
119 sh_entsize,
120 })
121 .collect()
122}
123
124fn parse_symbols(elf: &[u8], sections: &[SectionHeader]) -> Vec<SymbolEntry> {
125 let symtab = sections

Calls 6

read_c_stringFunction · 0.85
pushMethod · 0.80
collectMethod · 0.80
read_u64Function · 0.70
read_u16Function · 0.70
read_u32Function · 0.70