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

Function parse_symbols

tests/integration/linker.rs:124–147  ·  view source on GitHub ↗
(elf: &[u8], sections: &[SectionHeader])

Source from the content-addressed store, hash-verified

122}
123
124fn parse_symbols(elf: &[u8], sections: &[SectionHeader]) -> Vec<SymbolEntry> {
125 let symtab = sections
126 .iter()
127 .find(|section| section.name == ".symtab")
128 .unwrap_or_else(|| panic!("missing .symtab in exported ELF"));
129 let strtab = sections
130 .iter()
131 .find(|section| section.name == ".strtab")
132 .unwrap_or_else(|| panic!("missing .strtab in exported ELF"));
133
134 let symtab_bytes = &elf[symtab.sh_offset as usize..(symtab.sh_offset + symtab.sh_size) as usize];
135 let strtab_bytes = &elf[strtab.sh_offset as usize..(strtab.sh_offset + strtab.sh_size) as usize];
136 let entsize = symtab.sh_entsize as usize;
137
138 symtab_bytes
139 .chunks_exact(entsize)
140 .map(|entry| SymbolEntry {
141 name: read_c_string(strtab_bytes, read_u32(entry, 0)),
142 bind: entry[4] >> 4,
143 section_index: read_u16(entry, 6),
144 value: read_u64(entry, 8),
145 })
146 .collect()
147}
148
149fn section_index_for_addr(sections: &[SectionHeader], addr: u64) -> usize {
150 sections

Calls 5

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