| 1 | #![allow (clippy::too_many_arguments)] |
| 2 | // We are writing a very specific, well defined format, so it makes it easier to |
| 3 | // see exactly what is being written if we explicitly write out `\n` instead of |
| 4 | // hoping somebody notices the `writeln!` instead of `write!`. |
| 5 | #![allow (clippy::write_with_newline)] |
| 6 | |
| 7 | mod alignment; |
| 8 | mod archive; |
| 9 | mod archive_writer; |
| 10 | mod coff; |
| 11 | mod coff_import_file; |
| 12 | mod mangler; |
| 13 | mod math_extras; |
| 14 | mod object_reader; |
| 15 | |
| 16 | pub use archive::ArchiveKind; |
| 17 | pub use archive_writer::{write_archive_to_stream, NewArchiveMember}; |
| 18 | pub use coff::MachineTypes; |
| 19 | pub use coff_import_file::{write_import_library, COFFShortExport}; |
| 20 | |
| 21 | pub type GetSymbolsFn = |
| 22 | fn(buf: &[u8], f: &mut dyn FnMut(&[u8]) -> std::io::Result<()>) -> std::io::Result<bool>; |
| 23 | pub type Is64BitObjectFileFn = fn(buf: &[u8]) -> bool; |
| 24 | pub type IsECObjectFileFn = fn(buf: &[u8]) -> bool; |
| 25 | pub type GetXCoffMemberAlignmentFn = fn(buf: &[u8]) -> u32; |
| 26 | |
| 27 | /// Helper struct to query object file information from members. |
| 28 | pub struct ObjectReader { |
| 29 | /// Iterates over the symbols in the object file. |
| 30 | pub get_symbols: GetSymbolsFn, |
| 31 | /// Returns true if the object file is 64-bit. |
| 32 | /// Note that this should match LLVM's `SymbolicFile::is64Bit`, which |
| 33 | /// considers all COFF files to be 32-bit. |
| 34 | pub is_64_bit_object_file: Is64BitObjectFileFn, |
| 35 | /// Returns true if the object file is an EC (that is, an Arm64EC or x64) |
| 36 | /// object file |
| 37 | pub is_ec_object_file: IsECObjectFileFn, |
| 38 | /// Returns the member alignment of an XCoff object file. |
| 39 | pub get_xcoff_member_alignment: GetXCoffMemberAlignmentFn, |
| 40 | } |
| 41 | |
| 42 | /// Default implementation of [ObjectReader] that uses the `object` crate. |
| 43 | pub const DEFAULT_OBJECT_READER: ObjectReader = ObjectReader { |
| 44 | get_symbols: object_reader::get_native_object_symbols, |
| 45 | is_64_bit_object_file: object_reader::is_64_bit_symbolic_file, |
| 46 | is_ec_object_file: object_reader::is_ec_object, |
| 47 | get_xcoff_member_alignment: object_reader::get_member_alignment, |
| 48 | }; |
| 49 | |