|
1 |
| -use std::{collections::HashSet, fs, io::Cursor, mem::size_of, path::Path}; |
| 1 | +use std::{ |
| 2 | + collections::{HashMap, HashSet}, |
| 3 | + fs, |
| 4 | + io::Cursor, |
| 5 | + mem::size_of, |
| 6 | + path::Path, |
| 7 | +}; |
2 | 8 |
|
3 | 9 | use anyhow::{anyhow, bail, ensure, Context, Result};
|
4 | 10 | use filetime::FileTime;
|
@@ -147,6 +153,7 @@ fn symbols_by_section(
|
147 | 153 | obj_file: &File<'_>,
|
148 | 154 | section: &ObjSection,
|
149 | 155 | split_meta: Option<&SplitMeta>,
|
| 156 | + name_counts: &mut HashMap<String, u32>, |
150 | 157 | ) -> Result<Vec<ObjSymbol>> {
|
151 | 158 | let mut result = Vec::<ObjSymbol>::new();
|
152 | 159 | for symbol in obj_file.symbols() {
|
@@ -179,8 +186,14 @@ fn symbols_by_section(
|
179 | 186 | }
|
180 | 187 | if result.is_empty() {
|
181 | 188 | // Dummy symbol for empty sections
|
| 189 | + *name_counts.entry(section.name.clone()).or_insert(0) += 1; |
| 190 | + let current_count: u32 = *name_counts.get(§ion.name).unwrap(); |
182 | 191 | result.push(ObjSymbol {
|
183 |
| - name: format!("[{}]", section.name), |
| 192 | + name: if current_count > 1 { |
| 193 | + format!("[{} ({})]", section.name, current_count) |
| 194 | + } else { |
| 195 | + format!("[{}]", section.name) |
| 196 | + }, |
184 | 197 | demangled_name: None,
|
185 | 198 | address: 0,
|
186 | 199 | section_address: 0,
|
@@ -635,9 +648,15 @@ pub fn parse(data: &[u8], config: &DiffObjConfig) -> Result<ObjInfo> {
|
635 | 648 | let arch = new_arch(&obj_file)?;
|
636 | 649 | let split_meta = split_meta(&obj_file)?;
|
637 | 650 | let mut sections = filter_sections(&obj_file, split_meta.as_ref())?;
|
| 651 | + let mut name_counts: HashMap<String, u32> = HashMap::new(); |
638 | 652 | for section in &mut sections {
|
639 |
| - section.symbols = |
640 |
| - symbols_by_section(arch.as_ref(), &obj_file, section, split_meta.as_ref())?; |
| 653 | + section.symbols = symbols_by_section( |
| 654 | + arch.as_ref(), |
| 655 | + &obj_file, |
| 656 | + section, |
| 657 | + split_meta.as_ref(), |
| 658 | + &mut name_counts, |
| 659 | + )?; |
641 | 660 | section.relocations =
|
642 | 661 | relocations_by_section(arch.as_ref(), &obj_file, section, split_meta.as_ref())?;
|
643 | 662 | }
|
|
0 commit comments