-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mach/load_command: Add some missing load commands #240
Conversation
Adds support for `LC_VERSION_MIN_{TV,WATCH}OS`, as well as `LC_VERSION_EXPORTS_TRIE` and `LC_VERSION_CHAINED_FIXUPS`. Each of the above maps to a pre-existing load command structure, so no additional structure definitions were necessary. Also adds constant support for `LC_NOTE` and `LC_BUILD_VERSION`. These require new load command structures (and substructures, in the case of `LC_BUILD_VERSION`), so I left them out of this PR in the interest of brevity. I can do them in a follow-up PR, if desired.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! I would welcome followup PRs that bring goblin
back to parity with current #include <mach-o/*.h>
.
src/mach/load_command.rs
Outdated
@@ -1014,6 +1015,7 @@ pub struct VersionMinCommand { | |||
} | |||
|
|||
impl VersionMinCommand { | |||
// TODO: Needs a discriminant for TvOS, WatchOS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we ought to break this interface. Maybe add a new #[non_exhaustive] enum Platform
and add a fn platform(&self) -> Platform
while we're at it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM! I can make that part of this PR.
Uses the Platform enum to supply the appropriate load command number to `VersionMinCommand`, and implements the appropriate lossless/lossy traits for round-tripping with a `u32`.
Okay, I've added a It's technically safe to remove that |
Also, TIL that Edit: I'm going to push up a commit that bumps the MSRV, just to push the changes through the CI. Happy to drop it and make the other change, if desired. |
9638e21
to
bb766ee
Compare
bb766ee
to
bdfb336
Compare
Going to review in a bit, thanks for this! So this is a breaking change right (which is fine, might as well do this now)? |
Yep, correct -- this changes the public API for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only real question I have is whether the Platform should be repr(u32) (doesn’t have to be maybe there’s reasons to keep it away from the backing u32 consts?)
} else { | ||
LC_VERSION_MIN_MACOSX | ||
}, | ||
cmd: platform as u32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a new feature ? How is this cast working since Platform isn’t repr(u32).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this is part of the API breakage -- VersionMinCommand
can be produced from one of four different LC_*
constants, which are represented by that enum (since they might be useful elsewhere).
As for why it's working: I thought it was because I had implemented From<Platform> for u32
, but I tried removing that trait impl
and it still compiled 😟. So I'll change it to platform.into()
to make sure it's using the trait explicitly.
VersionMinTvos(comm) => comm.cmdsize, | ||
VersionMinWatchos(comm) => comm.cmdsize, | ||
DyldExportsTrie(comm) => comm.cmdsize, | ||
DyldChainedFixups(comm) => comm.cmdsize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don’t need to do this now but might be a good idea to add non exhaustive annotations to these enums as much well
/// An enumeration of platforms currently identifiable within a version_min_command. | ||
#[non_exhaustive] | ||
#[derive(Debug)] | ||
pub enum Platform { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these are tied to the LC values why not make it repr(u32) and set the values to the constants ? Maybe you can’t do that with constants in enums can’t remember
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought you couldn't either, but I just tried and it works 🤷. So I'll remove the trait usage in favour of repr(u32)
.
@@ -20,7 +20,7 @@ https://docs.rs/goblin/ | |||
|
|||
### Usage | |||
|
|||
Goblin requires `rustc` 1.36.0. | |||
Goblin requires `rustc` 1.40.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t really like this but it’s fine I guess.
Ok((DyldExportsTrie(comm), size)) | ||
} | ||
LC_DYLD_CHAINED_FIXUPS => { | ||
let comm = bytes.pread_with::<LinkeditDataCommand>(0, le)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and above are both LinkEditDataCommand? Interesting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, they both reside in __linkedit
, like a few others.
I’m ok with bumping msrv. Re The unwrapping issue, id day if it really is safe to unwrap then do it (but use expect); but if it’s the possible, e.g. with a malformed binary, etc, to have that unwrap fail, then leave it as is :) |
Sounds good! It should always be safe since the only ways to construct a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you for this PR! ❤️
@woodruffw I hope you don't mind, but I squashed and merged; i find this makes PR's cleaner generally, easier to bisect, known passing commit, etc. It's not a hard and fast rule but I prefer it more and more. People do get less "commit credit" so i do give them a heads up so they don't get sad :D |
I don’t mind at all! I usually do the same. Thanks for the quick review and merge!
Sent from mobile. Please excuse my brevity.
… On Oct 13, 2020, at 3:32 AM, m4b ***@***.***> wrote:
@woodruffw I hope you don't mind, but I squashed and merged; i find this makes PR's cleaner generally, easier to bisect, known passing commit, etc. It's not a hard and fast rule but I prefer it more and more. People do get less "commit credit" so i do give them a heads up so they don't get sad :D
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
ok this is wrapped up in upcoming 0.3 release |
First of all, thanks for this library! It's a pleasure to use.
I'm the maintainer of ruby-macho, and I noticed that these load commands were missing from your Mach-O implementation. I've taken the liberty of adding them; please let me know if there's anything else I can do.
Commit message:
Adds support for
LC_VERSION_MIN_{TV,WATCH}OS
, as well asLC_VERSION_EXPORTS_TRIE
andLC_VERSION_CHAINED_FIXUPS
.Each of the above maps to a pre-existing load command structure,
so no additional structure definitions were necessary.
Also adds constant support for
LC_NOTE
andLC_BUILD_VERSION
.These require new load command structures (and substructures, in the
case of
LC_BUILD_VERSION
), so I left them out of this PR inthe interest of brevity. I can do them in a follow-up PR,
if desired.