Skip to content

Commit

Permalink
Clear out timestamps in *_msvc import libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Sep 9, 2022
1 parent 61bc313 commit 2048560
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
Binary file modified crates/targets/aarch64_msvc/lib/windows.lib
Binary file not shown.
Binary file modified crates/targets/i686_msvc/lib/windows.lib
Binary file not shown.
Binary file modified crates/targets/x86_64_msvc/lib/windows.lib
Binary file not shown.
26 changes: 26 additions & 0 deletions crates/tools/msvc/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::collections::BTreeMap;
use std::io::prelude::*;
use std::io::SeekFrom;
use std::str::FromStr;

fn main() {
let platform = if let Some(platform) = option_env!("Platform") {
Expand Down Expand Up @@ -40,6 +42,30 @@ fn main() {
for library in libraries.keys() {
std::fs::remove_file(output.join(format!("{}.lib", library))).unwrap();
}

// Clear out timestamps in the resulting library.
let mut archive = std::fs::File::options().read(true).write(true).open(output.join("windows.lib")).unwrap();
let len = archive.metadata().unwrap().len();
let mut header = [0u8; 8];
archive.read_exact(&mut header).unwrap();
assert_eq!(&header, b"!<arch>\n");
for num in 1.. {
archive.seek(SeekFrom::Current(16)).unwrap(); // identifier
assert_eq!(archive.write(b"0 ").unwrap(), 12); // replace timestamp
let mut buf = [0u8; 32];
archive.read_exact(&mut buf).unwrap(); // remainder of the archive member header
let mut size = i64::from_str(std::str::from_utf8(&buf[20..][..10].split(u8::is_ascii_whitespace).next().unwrap()).unwrap()).unwrap();
if num > 3 {
archive.read_exact(&mut buf[..4]).unwrap(); // member header
let timestamp_offset = if &buf[..4] == [0, 0, 0xff, 0xff] { 4 } else { 0 };
archive.seek(SeekFrom::Current(timestamp_offset)).unwrap();
archive.write_all(&[0; 4]).unwrap();
size -= timestamp_offset + 8;
}
if archive.seek(SeekFrom::Current((size + 1) & !1)).unwrap() >= len {
break;
}
}
}

fn build_library(output: &std::path::Path, library: &str, functions: &BTreeMap<String, lib::CallingConvention>) {
Expand Down

0 comments on commit 2048560

Please sign in to comment.