Skip to content

Commit 381b2aa

Browse files
authored
Merge pull request #12 from dpaoliello/simplify
Removed unused options (deterministic, symbol table)
2 parents 3c88e2c + a0ed9ed commit 381b2aa

File tree

4 files changed

+22
-65
lines changed

4 files changed

+22
-65
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ar_archive_writer"
3-
version = "0.1.5"
3+
version = "0.2.0"
44
edition = "2021"
55
license = "Apache-2.0 WITH LLVM-exception"
66
description = "A writer for object file ar archives"

Readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# A writer for object file ar archives
22

3-
This is based on commit [8ef3e895a](https://github.com/llvm/llvm-project/tree/3d3ef9d073e1e27ea57480b371b7f5a9f5642ed2) (15.0.0-rc3) of LLVM's archive writer.
3+
This is a Rust port of LLVM's archive writer (`ArchiveWriter.cpp`):
4+
* Based on commit [8ef3e895a](https://github.com/llvm/llvm-project/tree/3d3ef9d073e1e27ea57480b371b7f5a9f5642ed2) (15.0.0-rc3).
5+
* With the following options removed:
6+
* Deterministic: always enabled.
7+
* Symbol tables: always enabled.
48

59
## License
610

src/archive_writer.rs

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,7 @@ fn compute_string_table(names: &[u8]) -> MemberData<'_> {
217217
}
218218
}
219219

220-
fn now(deterministic: bool) -> u64 {
221-
if !deterministic {
222-
todo!("non deterministic mode is not yet supported"); // FIXME
223-
}
220+
const fn now() -> u64 {
224221
0
225222
}
226223

@@ -293,7 +290,6 @@ fn compute_symbol_table_size_and_pad(
293290
fn write_symbol_table_header<W: Write + Seek>(
294291
w: &mut W,
295292
kind: ArchiveKind,
296-
deterministic: bool,
297293
size: u64,
298294
prev_member_offset: u64,
299295
) -> io::Result<()> {
@@ -304,29 +300,18 @@ fn write_symbol_table_header<W: Write + Seek>(
304300
"__.SYMDEF"
305301
};
306302
let pos = w.stream_position()?;
307-
print_bsd_member_header(w, pos, name, now(deterministic), 0, 0, 0, size)
303+
print_bsd_member_header(w, pos, name, now(), 0, 0, 0, size)
308304
} else if is_aix_big_archive(kind) {
309-
print_big_archive_member_header(
310-
w,
311-
"",
312-
now(deterministic),
313-
0,
314-
0,
315-
0,
316-
size,
317-
prev_member_offset,
318-
0,
319-
)
305+
print_big_archive_member_header(w, "", now(), 0, 0, 0, size, prev_member_offset, 0)
320306
} else {
321307
let name = if is_64bit_kind(kind) { "/SYM64" } else { "" };
322-
print_gnu_small_member_header(w, name.to_string(), now(deterministic), 0, 0, 0, size)
308+
print_gnu_small_member_header(w, name.to_string(), now(), 0, 0, 0, size)
323309
}
324310
}
325311

326312
fn write_symbol_table<W: Write + Seek>(
327313
w: &mut W,
328314
kind: ArchiveKind,
329-
deterministic: bool,
330315
members: &[MemberData<'_>],
331316
string_table: &[u8],
332317
prev_member_offset: u64,
@@ -341,7 +326,7 @@ fn write_symbol_table<W: Write + Seek>(
341326

342327
let offset_size = if is_64bit_kind(kind) { 8 } else { 4 };
343328
let (size, pad) = compute_symbol_table_size_and_pad(kind, num_syms, offset_size, string_table);
344-
write_symbol_table_header(w, kind, deterministic, size, prev_member_offset)?;
329+
write_symbol_table_header(w, kind, size, prev_member_offset)?;
345330

346331
let mut pos = if is_aix_big_archive(kind) {
347332
u64::try_from(std::mem::size_of::<big_archive::FixLenHdr>()).unwrap()
@@ -427,8 +412,6 @@ fn compute_member_data<'a, S: Write + Seek>(
427412
sym_names: &mut Cursor<Vec<u8>>,
428413
kind: ArchiveKind,
429414
thin: bool,
430-
deterministic: bool,
431-
need_symbols: bool,
432415
new_members: &'a [NewArchiveMember<'a>],
433416
) -> io::Result<Vec<MemberData<'a>>> {
434417
const PADDING_DATA: &[u8; 8] = &[b'\n'; 8];
@@ -490,7 +473,7 @@ fn compute_member_data<'a, S: Write + Seek>(
490473
// See also the functions that handle the lookup:
491474
// in lldb: ObjectContainerBSDArchive::Archive::FindObject()
492475
// in llvm/tools/dsymutil: BinaryHolder::GetArchiveMemberBuffers().
493-
let unique_timestamps = deterministic && is_darwin(kind);
476+
let unique_timestamps = is_darwin(kind);
494477
let mut filename_count = HashMap::new();
495478
if unique_timestamps {
496479
for m in new_members {
@@ -569,11 +552,7 @@ fn compute_member_data<'a, S: Write + Seek>(
569552
)?;
570553
}
571554

572-
let symbols = if need_symbols {
573-
write_symbols(data, m.get_symbols, sym_names, &mut has_object)?
574-
} else {
575-
vec![]
576-
};
555+
let symbols = write_symbols(data, m.get_symbols, sym_names, &mut has_object)?;
577556

578557
pos += u64::try_from(header.len() + data.len() + padding.len()).unwrap();
579558
ret.push(MemberData {
@@ -597,9 +576,7 @@ fn compute_member_data<'a, S: Write + Seek>(
597576
pub fn write_archive_to_stream<W: Write + Seek>(
598577
w: &mut W,
599578
new_members: &[NewArchiveMember<'_>],
600-
write_symtab: bool,
601579
mut kind: ArchiveKind,
602-
deterministic: bool,
603580
thin: bool,
604581
) -> io::Result<()> {
605582
assert!(
@@ -610,15 +587,7 @@ pub fn write_archive_to_stream<W: Write + Seek>(
610587
let mut sym_names = Cursor::new(Vec::new());
611588
let mut string_table = Cursor::new(Vec::new());
612589

613-
let mut data = compute_member_data(
614-
&mut string_table,
615-
&mut sym_names,
616-
kind,
617-
thin,
618-
deterministic,
619-
write_symtab,
620-
new_members,
621-
)?;
590+
let mut data = compute_member_data(&mut string_table, &mut sym_names, kind, thin, new_members)?;
622591

623592
let sym_names = sym_names.into_inner();
624593

@@ -646,13 +615,13 @@ pub fn write_archive_to_stream<W: Write + Seek>(
646615

647616
// The symbol table is put at the end of the big archive file. The symbol
648617
// table is at the start of the archive file for other archive formats.
649-
if write_symtab && !is_aix_big_archive(kind) {
618+
if !is_aix_big_archive(kind) {
650619
// We assume 32-bit offsets to see if 32-bit symbols are possible or not.
651620
let (symtab_size, _pad) = compute_symbol_table_size_and_pad(kind, num_syms, 4, &sym_names);
652621
last_member_header_offset += {
653622
// FIXME avoid allocating memory here
654623
let mut tmp = Cursor::new(vec![]);
655-
write_symbol_table_header(&mut tmp, kind, deterministic, symtab_size, 0).unwrap();
624+
write_symbol_table_header(&mut tmp, kind, symtab_size, 0).unwrap();
656625
u64::try_from(tmp.into_inner().len()).unwrap()
657626
} + symtab_size;
658627

@@ -687,9 +656,7 @@ pub fn write_archive_to_stream<W: Write + Seek>(
687656
}
688657

689658
if !is_aix_big_archive(kind) {
690-
if write_symtab {
691-
write_symbol_table(w, kind, deterministic, &data, &sym_names, 0)?;
692-
}
659+
write_symbol_table(w, kind, &data, &sym_names, 0)?;
693660

694661
for m in data {
695662
w.write_all(&m.header)?;
@@ -723,7 +690,7 @@ pub fn write_archive_to_stream<W: Write + Seek>(
723690
let member_table_size =
724691
u64::try_from(20 + 20 * member_offsets.len() + member_table_name_str_tbl_size).unwrap();
725692

726-
let global_symbol_offset = if write_symtab && num_syms > 0 {
693+
let global_symbol_offset = if num_syms > 0 {
727694
last_member_end_offset
728695
+ align_to(
729696
u64::try_from(std::mem::size_of::<big_archive::BigArMemHdrType>()).unwrap()
@@ -817,15 +784,8 @@ pub fn write_archive_to_stream<W: Write + Seek>(
817784
w.write_all(&[0])?;
818785
}
819786

820-
if write_symtab && num_syms > 0 {
821-
write_symbol_table(
822-
w,
823-
kind,
824-
deterministic,
825-
&data,
826-
&sym_names,
827-
last_member_end_offset,
828-
)?;
787+
if num_syms > 0 {
788+
write_symbol_table(w, kind, &data, &sym_names, last_member_end_offset)?;
829789
}
830790
}
831791
}

tests/common.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,8 @@ pub fn create_archive_with_ar_archive_writer<'a>(
9797
})
9898
.collect::<Vec<_>>();
9999
let mut output_bytes = Cursor::new(Vec::new());
100-
ar_archive_writer::write_archive_to_stream(
101-
&mut output_bytes,
102-
&members,
103-
true,
104-
archive_kind,
105-
true,
106-
false,
107-
)
108-
.unwrap();
100+
ar_archive_writer::write_archive_to_stream(&mut output_bytes, &members, archive_kind, false)
101+
.unwrap();
109102

110103
let output_archive_bytes = output_bytes.into_inner();
111104
let ar_archive_writer_file_path = tmpdir.join("output_ar_archive_writer.a");

0 commit comments

Comments
 (0)