|
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}; |
2 | 2 |
|
3 | 3 | use anyhow::{anyhow, bail, ensure, Context, Result};
|
4 | 4 | use filetime::FileTime;
|
@@ -627,6 +627,27 @@ pub fn parse(data: &[u8], config: &DiffObjConfig) -> Result<ObjInfo> {
|
627 | 627 | section.relocations =
|
628 | 628 | relocations_by_section(arch.as_ref(), &obj_file, section, split_meta.as_ref())?;
|
629 | 629 | }
|
| 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 | + } |
630 | 651 | if config.combine_data_sections {
|
631 | 652 | combine_data_sections(&mut sections)?;
|
632 | 653 | }
|
|
0 commit comments