Borrow display filenames when the mapped path permits it

This commit is contained in:
Rui Ueyama committed 2026-09-14 22:54:33 +09:00
1 parent e21540ed26
commit a1d0c8a6a3
3 files changed
+11 -8

No files matched your search

+1 -1
View File
@@ -152,7 +152,7 @@ impl<E: Arch> BackgroundMerge<E> {
}
let (filename, archive_name) = names.get_or_insert_with(|| {
(
std::sync::Arc::<str>::from(file.base.filename.as_str()),
std::sync::Arc::<str>::from(file.base.filename.as_ref()),
std::sync::Arc::<std::path::Path>::from(file.archive_name.as_path()),
)
});
+9 -6
View File
@@ -436,7 +436,7 @@ impl From<DsoId> for FileId {
#[derive(Debug)]
pub struct InputFile<E: Layout> {
pub mf: Option<&'static MappedFile>,
pub filename: String,
pub filename: Cow<'static, str>,
/// Position in the command line; lower is earlier. Symbol resolution
/// breaks ties in favor of earlier files.
@@ -480,10 +480,10 @@ pub struct InputFile<E: Layout> {
}
impl<E: Layout> InputFile<E> {
fn empty(filename: &str) -> InputFile<E> {
fn empty(filename: Cow<'static, str>) -> InputFile<E> {
InputFile {
mf: None,
filename: filename.to_string(),
filename,
priority: 0,
file_index: u32::MAX,
is_reachable: AtomicBool::new(false),
@@ -547,7 +547,7 @@ impl<E: Layout> InputFile<E> {
is_little_endian: E::Endian::IS_LITTLE,
e_flags: ehdr.e_flags.get(),
shdrs,
..InputFile::empty(&mf.name.to_string_lossy())
..InputFile::empty(mf.name.to_string_lossy())
};
// e_shstrndx is a 16-bit field. If .shstrtab's section index is
@@ -1150,7 +1150,10 @@ impl<E: Arch> ObjectFile<E> {
/// Creates the internal object file that holds linker-synthesized
/// symbols.
pub fn internal() -> ObjectFile<E> {
let mut file = ObjectFile::with_base(InputFile::<E>::empty("<internal>"), PathBuf::new());
let mut file = ObjectFile::with_base(
InputFile::<E>::empty(Cow::Borrowed("<internal>")),
PathBuf::new(),
);
file.sections_parsed = true;
file.base.set_reachable(true);
file
@@ -1220,7 +1223,7 @@ impl<E: Arch> ObjectFile<E> {
strtab: &'static [u8],
comdat_keys: Vec<Option<&'static [u8]>>,
) -> ObjectFile<E> {
let mut base = InputFile::<E>::empty(&mf.name.to_string_lossy());
let mut base = InputFile::<E>::empty(mf.name.to_string_lossy());
base.mf = Some(mf);
base.elf_syms = Cow::Owned(elf_syms);
base.symbol_strtab = strtab;
+1 -1
View File
@@ -921,7 +921,7 @@ fn merged_resolve_members<E: Arch>(
let mut members: Vec<Vec<crate::chunks::merged::ResolveMember<'_>>> =
(0..count).map(|_| Vec::new()).collect();
for file in objs {
let filename = file.base.filename.as_str();
let filename = file.base.filename.as_ref();
let archive_name = file.archive_name.as_path();
let shstrtab = file.base.shstrtab;
let num_elf_sections = file.num_elf_sections;