MCPcopy Index your code
hub / github.com/encounter/objdiff / map_sections

Function map_sections

objdiff-core/src/obj/read.rs:365–416  ·  view source on GitHub ↗
(
    _arch: &dyn Arch,
    obj_file: &object::File,
    split_meta: Option<&SplitMeta>,
)

Source from the content-addressed store, hash-verified

363}
364
365fn map_sections(
366 _arch: &dyn Arch,
367 obj_file: &object::File,
368 split_meta: Option<&SplitMeta>,
369) -> Result<(Vec<Section>, Vec<usize>)> {
370 let mut section_names = BTreeMap::<String, usize>::new();
371 let mut max_index = 0;
372 let section_count =
373 obj_file.sections().inspect(|s| max_index = max_index.max(s.index().0)).count();
374 let mut result = Vec::<Section>::with_capacity(section_count);
375 let mut section_indices = vec![usize::MAX; max_index + 1];
376 for section in obj_file.sections() {
377 let name = section.name().context("Failed to process section name")?;
378 let kind = map_section_kind(&section);
379 let data = if kind == SectionKind::Unknown {
380 // Don't need to read data for unknown sections
381 Vec::new()
382 } else {
383 section.uncompressed_data().context("Failed to read section data")?.into_owned()
384 };
385
386 // Find the virtual address for the section symbol if available
387 let section_symbol = obj_file.symbols().find(|s| {
388 s.kind() == object::SymbolKind::Section && s.section_index() == Some(section.index())
389 });
390 let virtual_address = section_symbol.and_then(|s| {
391 split_meta
392 .and_then(|m| m.virtual_addresses.as_ref())
393 .and_then(|v| v.get(s.index().0).cloned())
394 });
395
396 let unique_id = section_names.entry(name.to_string()).or_insert(0);
397 let id = format!("{name}-{unique_id}");
398 *unique_id += 1;
399
400 section_indices[section.index().0] = result.len();
401 result.push(Section {
402 id,
403 name: name.to_string(),
404 address: section.address(),
405 size: section.size(),
406 kind,
407 data: SectionData(data),
408 flags: Default::default(),
409 align: NonZeroU64::new(section.align()),
410 relocations: Default::default(),
411 virtual_address,
412 line_info: Default::default(),
413 });
414 }
415 Ok((result, section_indices))
416}
417
418const LOW_PRIORITY_SYMBOLS: &[&str] =
419 &["__gnu_compiled_c", "__gnu_compiled_cplusplus", "gcc2_compiled."];

Callers 1

parseFunction · 0.85

Calls 6

map_section_kindFunction · 0.85
SectionDataClass · 0.85
indexMethod · 0.80
nameMethod · 0.80
getMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected