| 1 | #![allow(clippy::write_with_newline)] |
| 2 | |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::{HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#, HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#}; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#; |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#, ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#, Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#, Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#, Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}; |
| 6 | |
| 7 | use superrust-analyzer cargo implib 0.3.3 ar/::*; |
| 8 | use craterust-analyzer cargo implib 0.3.3 crate/::{bailrust-analyzer cargo implib 0.3.3 ar/error/bail!, ensurerust-analyzer cargo implib 0.3.3 ar/error/ensure!, errrust-analyzer cargo implib 0.3.3 ar/error/err!}; |
| 9 | |
| 10 | // ========================================================================= // |
| 11 | |
| 12 | impl Headerrust-analyzer cargo implib 0.3.3 ar/Header# { |
| 13 | fn write_gnurust-analyzer cargo implib 0.3.3 ar/write/impl#[Header]write_gnu().<W>( |
| 14 | &self, |
| 15 | deterministic: bool, |
| 16 | writer: &mut W, |
| 17 | names: &HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, usize>, |
| 18 | ) -> Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> |
| 19 | where |
| 20 | W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#, |
| 21 | { |
| 22 | self.validaterust-analyzer cargo implib 0.3.3 ar/impl#[Header]validate().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 23 | if self.identifierrust-analyzer cargo implib 0.3.3 ar/Header#identifier..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().15 { |
| 24 | let offset = names[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().&self.identifierrust-analyzer cargo implib 0.3.3 ar/Header#identifier.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 25 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(writer, "/{:<15}", offset)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 26 | } else { |
| 27 | writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&self.identifierrust-analyzer cargo implib 0.3.3 ar/Header#identifier.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 28 | writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(b"/")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 29 | writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![b' '; 15 -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). self.identifierrust-analyzer cargo implib 0.3.3 ar/Header#identifier..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()])?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 30 | } |
| 31 | |
| 32 | if deterministic { |
| 33 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!( |
| 34 | writer, |
| 35 | "{:<12}{:<6}{:<6}{:<8o}{:<10}`\n", |
| 36 | 0, 0, 0, 0o644, self.sizerust-analyzer cargo implib 0.3.3 ar/Header#size. |
| 37 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 38 | } else { |
| 39 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!( |
| 40 | writer, |
| 41 | "{:<12}{:<6}{:<6}{:<8o}{:<10}`\n", |
| 42 | self.mtimerust-analyzer cargo implib 0.3.3 ar/Header#mtime., self.uidrust-analyzer cargo implib 0.3.3 ar/Header#uid., self.gidrust-analyzer cargo implib 0.3.3 ar/Header#gid., self.moderust-analyzer cargo implib 0.3.3 ar/Header#mode., self.sizerust-analyzer cargo implib 0.3.3 ar/Header#size. |
| 43 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 44 | } |
| 45 | |
| 46 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 47 | } |
| 48 | } |
| 49 | // ========================================================================= // |
| 50 | |
| 51 | /// Builder for GNU archive format |
| 52 | /// |
| 53 | /// # TL;DR |
| 54 | /// The GNU format is a backwards incompatible archive format that diverges from the legacy Unix |
| 55 | /// archive format in the following significant ways: |
| 56 | /// |
| 57 | /// 1) It can contain a binary symbol table that needs to be the first member of the archive. |
| 58 | /// This table can contain either 32bit or 64bit offsets pointing to the entities that symbols |
| 59 | /// relate to. |
| 60 | /// |
| 61 | /// Unlike the BSD tables the GNU tables are _somewhat_ more formally defined and are simpler in |
| 62 | /// construction. |
| 63 | /// |
| 64 | /// 2) The handling of extended strings is done with a string lookup table (either as the first of |
| 65 | /// second member) which is little more than a large string array. |
| 66 | /// |
| 67 | /// 3) Extensions exist to create a rare format known as a thin-archive. |
| 68 | /// |
| 69 | /// 4) GNU archives have a formal [deterministic mode](#deterministic-archives) that is important |
| 70 | /// for build systems and toolchains. |
| 71 | /// |
| 72 | /// Most tools outside of BSD targets tend to use GNU format as the defacto standard, and it is |
| 73 | /// well-supported by LLVM and GNU toolchains. More subtle variants of this format exist such as |
| 74 | /// the unimplemented Microsoft extended ECOFF archive. |
| 75 | /// |
| 76 | /// # Layout |
| 77 | /// Except where indicated, the metadata for the archive is typically encoded as ascii strings. All |
| 78 | /// ascii strings in an archive are padded to the length of the given field with ascii space `0x20` |
| 79 | /// as the fill value. This gives an archive a general fixed format look if opened in a text |
| 80 | /// editor. |
| 81 | /// |
| 82 | /// Data is emplaced inline directly after a header record, no manipulations are done on data |
| 83 | /// stored in an archive, and there are no restrictions on what data can be stored in an archive. |
| 84 | /// Data might have a padding character (`\n`) added if the entity would be on an odd byte |
| 85 | /// boundary, but this is purely an internal detail of the format and not visible in any metadata. |
| 86 | /// |
| 87 | /// **Header** |
| 88 | /// |
| 89 | /// | Section | Type | |
| 90 | /// |-----------------|---------------------| |
| 91 | /// | Magic signature | Literal `!<arch>\n` | |
| 92 | /// |
| 93 | /// **Entity Header** |
| 94 | /// |
| 95 | /// | Section | Type | Notes | |
| 96 | /// |---------|----------------|--------------------------------------------------------------------------------------------------| |
| 97 | /// | Name | `[u8; 16]` | Gnu handles strings in a manner that _effectively_ reduces this to 15 bytes | |
| 98 | /// | MTime | `[u8; 12]` | Seconds since the Unix epoch. Often `0` as per [deterministic archives](#deterministic-archives) | |
| 99 | /// | Uid | `[u8; 6]` | Unix plain user id. Often `0` as per [deterministic archives](#deterministic-archives) | |
| 100 | /// | Gid | `[u8; 6]` | Unix plain group id. Often `0` as per [deterministic archives](#deterministic-archives) | |
| 101 | /// | Mode | `[u8; 8]` | Unix file mode in Octal. Often `0` as per [deterministic archives](#deterministic-archives) | |
| 102 | /// | Size | `[u8; 10]` | Entity data size in bytes, the size _does not reflect_ any padding | |
| 103 | /// | End | Literal `\`\n` | Marks the end of the entity header | |
| 104 | /// |
| 105 | /// **Symbol table (if present)** |
| 106 | /// |
| 107 | /// Symbol tables are prepended with an entity header, although most implementations choose to make |
| 108 | /// the header all spaces in contrast to general header format for [deterministic |
| 109 | /// archives](#Deterministic Archives) but with the same general effect. |
| 110 | /// |
| 111 | /// The name for the entity for the symbol table is either `//` or `/SYM64/` dependent on if the |
| 112 | /// overall size of the archive crosses the maximum addressable size allowed by 32 bits. |
| 113 | /// |
| 114 | /// | Section | Type | Notes | |
| 115 | /// |----------|-------------------|---------------------------------------------------------| |
| 116 | /// | Num syms | `u32` / `u64` | _Generally_ `u32` but can be `u64` for > 4Gb archives | |
| 117 | /// | Offsets | `[u32]` / `[u64]` | Pointer from a symbol to the relevant archive entity | |
| 118 | /// | Names | `[c_str]` | The name of each symbol as a plain C style string array | |
| 119 | /// |
| 120 | /// **Extended strings (if present)** |
| 121 | /// |
| 122 | /// GNU archives generally encode names inline in the format `/some_name.o/`. |
| 123 | /// |
| 124 | /// The bracketed `/` pairing allows GNU archives to contain embedded spaces and other metachars |
| 125 | /// (excluding `/` itself). |
| 126 | /// |
| 127 | /// If the name is _greater than_ 15 bytes it is encoded as offset number into a string table. The |
| 128 | /// string table is one of the first few members in the archive and is given as strings separated |
| 129 | /// by the byte sequence `[0x2F, 0x0A]` (or `\\/n` in ascii). |
| 130 | /// No padding is done in the string table itself and the offset written to the entity header is zero |
| 131 | /// based from the start of the string table. |
| 132 | /// |
| 133 | /// The entity name for the string table is formatted as `/#offset`, for example, for an extended |
| 134 | /// name starting at offset `4853` the value written to the entity header becomes `/#4853` |
| 135 | /// |
| 136 | /// ## Deterministic Archives |
| 137 | /// The existence of several variables in entity headers make the format poorly suited to |
| 138 | /// consistent generation of archives. This confuses toolchains which may interpret frequently |
| 139 | /// changing headers as a change to the overall archive and force needless recomputations. |
| 140 | /// |
| 141 | /// As such, a backwards compatible extension exists for GNU archives where all variable fields not |
| 142 | /// directly related to an entities data are set to ascii `0`. This is known as deterministic mode |
| 143 | /// and is common for most modern in use unix archives (the format has long since lost its original |
| 144 | /// duty as a general archive format and is now mostly used for toolchain operations). |
| 145 | pub struct GnuBuilderrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#> { |
| 146 | writerrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#writer.: W, |
| 147 | deterministicrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#deterministic.: bool, |
| 148 | short_namesrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#short_names.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>, |
| 149 | long_namesrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#long_names.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, usize>, |
| 150 | symbol_table_relocationsrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#symbol_table_relocations.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u64>>, |
| 151 | symbol_indexrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#symbol_index.: usize, |
| 152 | } |
| 153 | |
| 154 | impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#> GnuBuilderrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#<W> { |
| 155 | /// The third argument is a map from file identifier to the name of all symbols in the file. |
| 156 | /// Create a new archive builder with the underlying writer object as the |
| 157 | /// destination of all data written. The `identifiers` parameter must give |
| 158 | /// the complete list of entry identifiers that will be included in this |
| 159 | /// archive. The last argument is a map from file identifier to the name of |
| 160 | /// all symbols in the file. |
| 161 | pub fn new_with_symbol_tablerust-analyzer cargo implib 0.3.3 ar/write/impl#[`GnuBuilder<W>`]new_with_symbol_table().( |
| 162 | mut writer: W, |
| 163 | deterministic: bool, |
| 164 | identifiers: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>, |
| 165 | symbol_table: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>>, |
| 166 | ) -> Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<GnuBuilderrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#<W>> { |
| 167 | let mut short_names = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`]new().(); |
| 168 | let mut long_names = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, usize>::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().(); |
| 169 | let mut name_table_size: usize = 0; |
| 170 | for identifier in identifiers.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().() { |
| 171 | let length = identifier.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 172 | if length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().15 { |
| 173 | long_names.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(identifier, name_table_size); |
| 174 | name_table_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().2; |
| 175 | } else { |
| 176 | short_names.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(identifier); |
| 177 | } |
| 178 | } |
| 179 | let name_table_needs_padding = name_table_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0; |
| 180 | if name_table_needs_padding { |
| 181 | name_table_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().3; // ` /\n` |
| 182 | } |
| 183 | |
| 184 | writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(GLOBAL_HEADERrust-analyzer cargo implib 0.3.3 ar/GLOBAL_HEADER.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 185 | |
| 186 | let mut symbol_table_relocations: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u64>> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(symbol_table.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 187 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().symbol_table.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 188 | let wordsize = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<u32>(); |
| 189 | let symbol_count: usize = symbol_table.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|symbols| symbols.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()).sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().(); |
| 190 | let symbols = symbol_table.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().(); |
| 191 | let mut symbol_table_size: usize = wordsize |
| 192 | +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().wordsize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().symbol_count |
| 193 | +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().symbols.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|symbol| symbol.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1).sumrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#sum().::<usize>(); |
| 194 | let symbol_table_needs_padding = symbol_table_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0; |
| 195 | if symbol_table_needs_padding { |
| 196 | symbol_table_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().3; // ` /\n` |
| 197 | } |
| 198 | |
| 199 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!( |
| 200 | writer, |
| 201 | "{:<16}{:<12}{:<6}{:<6}{:<8o}{:<10}`\n", |
| 202 | GNU_SYMBOL_LOOKUP_TABLE_IDrust-analyzer cargo implib 0.3.3 ar/GNU_SYMBOL_LOOKUP_TABLE_ID., 0, 0, 0, 0, symbol_table_size |
| 203 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 204 | |
| 205 | writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&u32::to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]to_be_bytes().(u32::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u32][`TryFrom<usize>`]try_from().(symbol_count).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().( |
| 206 | |_| errrust-analyzer cargo implib 0.3.3 ar/error/err!!("Too many symbols for 32bit table `{}`", symbol_count), |
| 207 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 208 | |
| 209 | for symbols in &symbol_table { |
| 210 | let mut sym_rels = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 211 | for _symbol in symbols { |
| 212 | sym_rels.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(writer.stream_positionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#stream_position().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().); |
| 213 | writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&u32::to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]to_be_bytes().(0xcafebabe))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 214 | } |
| 215 | symbol_table_relocations.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(sym_rels); |
| 216 | } |
| 217 | |
| 218 | for symbol in symbol_table.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().() { |
| 219 | writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(symbol)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 220 | writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(b"\0")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 221 | } |
| 222 | if symbol_table_needs_padding { |
| 223 | writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(b" /\n")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().long_names.is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]is_empty().() { |
| 228 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!( |
| 229 | writer, |
| 230 | "{:<48}{:<10}`\n", |
| 231 | GNU_NAME_TABLE_IDrust-analyzer cargo implib 0.3.3 ar/GNU_NAME_TABLE_ID., name_table_size |
| 232 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 233 | let mut entries: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(usize, &[u8])> = long_names |
| 234 | .iterrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]iter().() |
| 235 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(id, &start)| (start, id.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().())) |
| 236 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 237 | entries.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().(); |
| 238 | for (_, id) in entries { |
| 239 | writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(id)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 240 | writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(b"/\n")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 241 | } |
| 242 | if name_table_needs_padding { |
| 243 | writer.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(b" /\n")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(GnuBuilderrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder# { |
| 248 | writerrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#writer., |
| 249 | deterministicrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#deterministic., |
| 250 | short_namesrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#short_names., |
| 251 | long_namesrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#long_names., |
| 252 | symbol_table_relocationsrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#symbol_table_relocations., |
| 253 | symbol_indexrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#symbol_index.: 0, |
| 254 | }) |
| 255 | } |
| 256 | |
| 257 | /// Adds a new entry to this archive. |
| 258 | pub fn appendrust-analyzer cargo implib 0.3.3 ar/write/impl#[`GnuBuilder<W>`]append().<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#>(&mut self, header: &Headerrust-analyzer cargo implib 0.3.3 ar/Header#, mut data: R) -> Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 259 | let is_long_name = header.identifierrust-analyzer cargo implib 0.3.3 ar/impl#[Header]identifier().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().15; |
| 260 | let has_name = if is_long_name { |
| 261 | self.long_namesrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#long_names..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(header.identifierrust-analyzer cargo implib 0.3.3 ar/impl#[Header]identifier().()) |
| 262 | } else { |
| 263 | self.short_namesrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#short_names..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(header.identifierrust-analyzer cargo implib 0.3.3 ar/impl#[Header]identifier().()) |
| 264 | }; |
| 265 | |
| 266 | ensurerust-analyzer cargo implib 0.3.3 ar/error/ensure!!( |
| 267 | has_name, |
| 268 | "Identifier `{:?}` was not in the list of identifiers passed to GnuBuilder::new()", |
| 269 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(header.identifierrust-analyzer cargo implib 0.3.3 ar/impl#[Header]identifier().()) |
| 270 | ); |
| 271 | |
| 272 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(relocs) = self.symbol_table_relocationsrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#symbol_table_relocations..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(self.symbol_indexrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#symbol_index.) { |
| 273 | let entry_offset = self.writerrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#writer..stream_positionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#stream_position().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 274 | let entry_offset_bytes = u32::to_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]to_be_bytes().( |
| 275 | u32::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u32][`TryFrom<u64>`]try_from().(entry_offset).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| errrust-analyzer cargo implib 0.3.3 ar/error/err!!("Archive larger than 4GB"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 276 | ); |
| 277 | for &reloc_offset in relocs { |
| 278 | self.writerrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#writer..seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#seek().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Startrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#Start#(reloc_offset))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 279 | self.writerrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#writer..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&entry_offset_bytes)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 280 | } |
| 281 | self.writerrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#writer..seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#seek().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Startrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#Start#(entry_offset))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 282 | self.symbol_indexrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#symbol_index. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 283 | } |
| 284 | |
| 285 | header.write_gnurust-analyzer cargo implib 0.3.3 ar/write/impl#[Header]write_gnu().(self.deterministicrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#deterministic., &mut self.writerrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#writer., &self.long_namesrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#long_names.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 286 | let actual_size = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::copyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/copy/copy().(&mut data, &mut self.writerrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#writer.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 287 | if actual_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().header.sizerust-analyzer cargo implib 0.3.3 ar/impl#[Header]size().() { |
| 288 | bailrust-analyzer cargo implib 0.3.3 ar/error/bail!!( |
| 289 | "Wrong file size (header.size() = `{}`, actual = `{}`)", |
| 290 | header.sizerust-analyzer cargo implib 0.3.3 ar/impl#[Header]size().(), |
| 291 | actual_size |
| 292 | ); |
| 293 | } |
| 294 | if actual_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem().2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().0 { |
| 295 | self.writerrust-analyzer cargo implib 0.3.3 ar/write/GnuBuilder#writer..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&[b'\n'])?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 296 | } |
| 297 | |
| 298 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 299 | } |
| 300 | } |