Skip to content

Commit 6bb4ffd

Browse files
committed
Disambiguate dummy symbols
1 parent 2379853 commit 6bb4ffd

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

objdiff-core/src/obj/read.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashSet, fs, io::Cursor, mem::size_of, path::Path};
1+
use std::{collections::{HashMap, HashSet}, fs, io::Cursor, mem::size_of, path::Path};
22

33
use anyhow::{anyhow, bail, ensure, Context, Result};
44
use filetime::FileTime;
@@ -627,6 +627,27 @@ pub fn parse(data: &[u8], config: &DiffObjConfig) -> Result<ObjInfo> {
627627
section.relocations =
628628
relocations_by_section(arch.as_ref(), &obj_file, section, split_meta.as_ref())?;
629629
}
630+
// The dummy symbols all have the same name, which means that only the first one can be
631+
// compared
632+
let all_names = sections
633+
.iter()
634+
.flat_map(|section| section.symbols.iter().map(|symbol| symbol.name.clone()));
635+
let mut name_counts: HashMap<String, usize> = HashMap::new();
636+
for name in all_names {
637+
name_counts.entry(name).and_modify(|i| *i += 1).or_insert(1);
638+
}
639+
// Reversing the iterator here means the symbol sections will be given in the expected order
640+
// since they're assigned from the count down to prevent
641+
// having to use another hashmap which counts up
642+
// TODO what about reverse_fn_order?
643+
for section in sections.iter_mut().rev() {
644+
for symbol in section.symbols.iter_mut().rev() {
645+
if name_counts[&symbol.name] > 1 {
646+
name_counts.entry(symbol.name.clone()).and_modify(|i| *i -= 1);
647+
symbol.name = format!("{} {}", &symbol.name, name_counts[&symbol.name]);
648+
}
649+
}
650+
}
630651
if config.combine_data_sections {
631652
combine_data_sections(&mut sections)?;
632653
}

0 commit comments

Comments
 (0)