From 227153193e37fc9d983b0a5ab1483438c06628f2 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Wed, 20 Dec 2023 20:28:30 -0700 Subject: [PATCH] Sanitize auto-function-split names Fixes #16 --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/util/split.rs | 8 +++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 65683e1..15de045 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -329,6 +329,7 @@ dependencies = [ "rayon", "regex", "rustc-hash", + "sanitise-file-name", "serde", "serde_json", "serde_repr", @@ -921,6 +922,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "sanitise-file-name" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d36299972b96b8ae7e8f04ecbf75fb41a27bf3781af00abcf57609774cb911" + [[package]] name = "scopeguard" version = "1.2.0" diff --git a/Cargo.toml b/Cargo.toml index f28b767..d64f598 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,6 +56,7 @@ ppc750cl = { git = "https://github.com/encounter/ppc750cl", rev = "4a2bbbc6f84dc rayon = "1.8.0" regex = "1.10.2" rustc-hash = "1.1.0" +sanitise-file-name = "1.0.0" serde = "1.0.192" serde_json = "1.0.108" serde_repr = "0.1.17" diff --git a/src/util/split.rs b/src/util/split.rs index 6e7be14..af3518b 100644 --- a/src/util/split.rs +++ b/src/util/split.rs @@ -6,6 +6,7 @@ use std::{ use anyhow::{anyhow, bail, ensure, Context, Result}; use itertools::Itertools; use petgraph::{graph::NodeIndex, Graph}; +use sanitise_file_name::sanitize_with_options; use tracing_attributes::instrument; use crate::{ @@ -69,7 +70,12 @@ fn split_ctors_dtors(obj: &mut ObjInfo, start: SectionAddress, end: SectionAddre .section .and_then(|idx| obj.sections.get(idx).map(|s| s.name.clone())) .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);