From e8db15f662af7fe646a75fbbb3c507037dc55753 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 21 Apr 2019 15:25:39 +0200 Subject: [PATCH] Fix filename length for ar files --- src/archive.rs | 20 ++++++++++++++++++-- src/lib.rs | 6 +++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/archive.rs b/src/archive.rs index 02b8c4fd14e..44ca68c2127 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -36,7 +36,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { dst: output.to_path_buf(), src: input.map(|p| p.to_path_buf()), lib_search_paths: archive_search_paths(sess), - is_like_osx: sess.target.target.options.is_like_osx, + is_like_osx: true, //sess.target.target.options.is_like_osx, }; let (src_archives, entries) = if let Some(src) = &config.src { @@ -146,8 +146,24 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { ArchiveEntry::FromArchive { archive_index, entry_index } => { let entry = self.src_archives[archive_index].jump_to_entry(entry_index).unwrap(); let orig_header = entry.header(); + + let orig_filename = orig_header.identifier().to_vec(); + + use std::collections::hash_map::DefaultHasher; + use std::hash::{Hash, Hasher}; + let mut hasher = DefaultHasher::new(); + orig_filename.hash(&mut hasher); + let mut filename = hasher.finish().to_le_bytes()[0..6].to_vec(); + filename.extend(&orig_filename[orig_filename.len() - 9..]); + + assert!( + filename.len() <= 16, + "Filenames bigger than 16 bytes are not yet supported. Filename was: \"{}\"", + String::from_utf8(filename).unwrap_or_else(|e| e.to_string()), + ); + let mut header = - ar::Header::new(orig_header.identifier().to_vec(), orig_header.size()); + ar::Header::new(filename, orig_header.size()); header.set_mtime(orig_header.mtime()); header.set_uid(orig_header.uid()); header.set_gid(orig_header.gid()); diff --git a/src/lib.rs b/src/lib.rs index 53dc644ddc4..f1bceb648e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -325,14 +325,14 @@ impl CodegenBackend for CraneliftCodegenBackend { return Box::new(CodegenResults { crate_name: tcx.crate_name(LOCAL_CRATE), modules: vec![emit_module( - "dummy_name", + "u", ModuleKind::Regular, faerie_module, debug, )], allocator_module: if created_alloc_shim { Some(emit_module( - "allocator_shim", + "a", ModuleKind::Allocator, allocator_module, None, @@ -341,7 +341,7 @@ impl CodegenBackend for CraneliftCodegenBackend { None }, metadata_module: CompiledModule { - name: "dummy_metadata".to_string(), + name: "m".to_string(), kind: ModuleKind::Metadata, object: None, bytecode: None,