Sanitize auto-function-split names

Fixes #16
This commit is contained in:
Luke Street 2023-12-20 20:28:30 -07:00
parent 2681e51443
commit 227153193e
3 changed files with 15 additions and 1 deletions

7
Cargo.lock generated
View File

@ -329,6 +329,7 @@ dependencies = [
"rayon", "rayon",
"regex", "regex",
"rustc-hash", "rustc-hash",
"sanitise-file-name",
"serde", "serde",
"serde_json", "serde_json",
"serde_repr", "serde_repr",
@ -921,6 +922,12 @@ dependencies = [
"winapi-util", "winapi-util",
] ]
[[package]]
name = "sanitise-file-name"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19d36299972b96b8ae7e8f04ecbf75fb41a27bf3781af00abcf57609774cb911"
[[package]] [[package]]
name = "scopeguard" name = "scopeguard"
version = "1.2.0" version = "1.2.0"

View File

@ -56,6 +56,7 @@ ppc750cl = { git = "https://github.com/encounter/ppc750cl", rev = "4a2bbbc6f84dc
rayon = "1.8.0" rayon = "1.8.0"
regex = "1.10.2" regex = "1.10.2"
rustc-hash = "1.1.0" rustc-hash = "1.1.0"
sanitise-file-name = "1.0.0"
serde = "1.0.192" serde = "1.0.192"
serde_json = "1.0.108" serde_json = "1.0.108"
serde_repr = "0.1.17" serde_repr = "0.1.17"

View File

@ -6,6 +6,7 @@ use std::{
use anyhow::{anyhow, bail, ensure, Context, Result}; use anyhow::{anyhow, bail, ensure, Context, Result};
use itertools::Itertools; use itertools::Itertools;
use petgraph::{graph::NodeIndex, Graph}; use petgraph::{graph::NodeIndex, Graph};
use sanitise_file_name::sanitize_with_options;
use tracing_attributes::instrument; use tracing_attributes::instrument;
use crate::{ use crate::{
@ -69,7 +70,12 @@ fn split_ctors_dtors(obj: &mut ObjInfo, start: SectionAddress, end: SectionAddre
.section .section
.and_then(|idx| obj.sections.get(idx).map(|s| s.name.clone())) .and_then(|idx| obj.sections.get(idx).map(|s| s.name.clone()))
.unwrap_or_else(|| "unknown".to_string()); .unwrap_or_else(|| "unknown".to_string());
format!("auto_{}_{}", function_symbol.name, section_name.trim_start_matches('.')) let name =
sanitize_with_options(&function_symbol.name, &sanitise_file_name::Options {
length_limit: 20,
..Default::default()
});
format!("auto_{}_{}", name, section_name.trim_start_matches('.'))
}); });
log::debug!("Adding splits to unit {}", unit); log::debug!("Adding splits to unit {}", unit);