Commit Graph

550 Commits

Author SHA1 Message Date
Philip Craig d65bc756e4 read: add ObjectSection::relocation_map (#654)
This is intended to handle relocations for DWARF.
2024-03-28 11:58:07 +10:00
Philip Craig ff176cc59e read: allow use of ReadCache without std (#653) 2024-03-27 11:33:43 +10:00
Philip Craig 2e5b48eeca build/elf: handle parsing dynamic relocations with invalid link
If there are no symbol references in the relocations, then
it doesn't matter that the link is invalid.
2024-03-25 16:02:26 +10:00
Philip Craig c3f1f949c5 build/elf: support more section types 2024-03-25 16:02:26 +10:00
Philip Craig d6094add33 build/elf: fix sh_info for SHT_DYNSYM section
It's possible to have local symbols in the dynamic symbol table,
and sh_info should count these, the same as it already does
for SHT_SYMTAB.

Also be sure to exclude these from the GNU hash table.
2024-03-25 16:02:26 +10:00
Philip Craig bafb1c3d3e build/elf: fix sh_size for attribute sections 2024-03-25 16:02:26 +10:00
Philip Craig 6b60450e0c write/elf: fix sh_entsize for 32-bit hash sections 2024-03-25 16:02:26 +10:00
Philip Craig 9f11ebd731 read/archive: add thin archive support (#651) 2024-03-25 15:40:28 +10:00
Philip Craig 6b4adc8b20 read/wasm: handle tag sections 2024-03-20 14:22:11 +10:00
Philip Craig 25fdef30a2 read/wasm: don't try to parse components
The current code is only designed to support a single module.
2024-03-20 14:21:07 +10:00
Philip Craig 9adf74a95a read/wasm: validate function indices 2024-03-20 14:19:46 +10:00
Philip Craig f3432e9807 elf: allow for absence of dynstr (#646)
.dynstr doesn't need to be present if there are no dynamic strings.

- handle section index 0 in read::elf::SectionTable::strings
- don't require .dynstr when writing if there are no strings
- don't print name of symbol index 0 in readobj example
2024-03-19 14:56:51 +10:00
Philip Craig 67d53c27f7 build/elf: improve handling of sh_offset for SHT_NOBITS when writing (#645) 2024-03-19 13:40:38 +10:00
Markus Stange 791adb0a1e Correctly handle dyld caches on macOS 13 and above (#642)
This allows successful parsing of dyld caches on
macOS 13 and above on Intel Macs.

The main dyld cache file on macOS contains an array of
subcache info structs, each of which specifies the UUID
(and some other information) of each subcache.
`DyldCache::parse` checks that the subcache UUIDs match
these expected UUIDs.

In macOS 13, the format of the subcache info struct
changed: it gained an additional field after the UUID
field. This means that as soon as you had more than
one subcache, our UUID check would fail, because the
second subcache UUID would be read from the wrong offset.

I didn't notice this on my Apple Silicon Mac, because
the arm64e dyld cache only has one subcache:
`dyld_shared_cache_arm64e.01`.
But on Intel Macs, there are currently four subcaches:
`dyld_shared_cache_x86_64.01`, `.02`, `.03`, and `.04`.

In practice this means that my software hasn't been able to
symbolicate macOS system libraries on Intel Macs since
the release of macOS 13.

This commit adds the new struct definition and makes
the UUID check work correctly.

This is a breaking change to the public API. I added
a `DyldSubCacheSlice` enum, but I'm not particularly
fond of it.

dyldcachedump was working correctly on macOS 13+ because it was trying
the "leading zero" suffix format as well as the "no leading zero" suffix
format. This commit changes it to read the suffix from the main cache
header.

objdump was not able to parse dyld shared cache files on macOS 13+ because
it was only using the "no leading zero" suffix format, and thus not finding
the subcaches.
2024-03-11 15:01:56 +10:00
Philip Craig 1119a2a1fe build/elf: add Builder (#618)
The Builder can be created from an existing ELF file, modified,
and then written out again.

Also add the `object-rewrite` crate which provides higher
level operations for modification. Use this to replace
the elfcopy example.
2024-03-01 18:52:56 +10:00
Philip Craig 7b61896648 Fix unused items when building with feature combinations (#637) 2024-02-26 11:23:04 +10:00
Philip Craig fb0d876a0b Fix clippy warnings (#636) 2024-02-23 17:43:09 +10:00
Philip Craig 09d8d571f7 read: more ReadRef and ReadCache documentation (#633) 2024-02-15 17:51:54 +10:00
Philip Craig 1c618a2194 read: use Vec::try_reserve_exact for large allocations (#632) 2024-02-13 12:32:30 +10:00
Guillaume Girol f1a0ec96a1 read: check that sizes are smaller than the file length in ReadCache (#630)
This avoids large allocations due to invalid sizes in corrupted files.
2024-02-11 21:30:06 +10:00
Philip Craig 027dd4d6c5 read: add Relocation::set_addend (#627)
This was removed in eb58357f for consistency (nowhere else in
the read API allows mutation), but there are existing users
so add it back in for convenience.
2024-01-30 17:47:28 +10:00
Philip Craig 443f7ec777 read: add MachOFatFile (#623)
My primary motivation is to avoid the impl for a type in another
module, but I think this is also closer to the API for other files.
2024-01-30 17:47:10 +10:00
Adam Gastineau 2125bfeb0e Add xrOS platform (#626) 2024-01-30 10:48:31 +10:00
David Lattimore 8a7a9b6841 read: Allow comdat names to be borrowed for 'data (#622) 2024-01-08 13:00:45 +10:00
Philip Craig 28f2bc63a2 Avoid using reexports within the crate (#621)
The exception is reusing common definitions that are reexported
in the read module (preexisting) and write module (newly added).

This is for consistency, and makes it easier to experiment with a
restructure.
2024-01-07 15:04:39 +10:00