-
Notifications
You must be signed in to change notification settings - Fork 160
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
Add Arm extensions #242
base: master
Are you sure you want to change the base?
Add Arm extensions #242
Conversation
52a5c2e
to
f276c6f
Compare
Checking I don't like the duplication and control flow inversion between I'm also toying with the idea that the NUL-terminated byte string attributes should all be separate types. The argument is that while 🤔 Maybe: Remove |
f276c6f
to
b3430b9
Compare
That feels better. The consuming code in the vendor section looks like: pub struct Vendor {
field: Option<Field>,
}
impl Vendor {
fn parse(&mut self, mut attrs: Attributes) -> Result<(), AttributeParseError> {
while let Some(attr) = attrs.next()? {
match attr.tag_number() {
1 => {
let (value, rest) = Field::parse(attr)?;
self.field = Some(value);
attrs = rest;
},
_ => return Err(attr.unrecognized()),
}
}
Ok(())
}
}
pub enum Field {
/* … */
}
impl Field {
fn parse<'a>(attr: SemiParsedAttribute<'a>) -> Result<(Self, Attributes<'a>), AttributeParseError> {
let (value, rest) = attr.parse_uleb128()?;
Ok((value.into(), rest)
}
} …which the |
66216f9
to
1a00c63
Compare
Let me know when you’d like to me to review :) |
1a00c63
to
6e7eb51
Compare
@willglynn so this is marked a WIP, is this ready for review, or what should happen here? Interested in getting this merged/in :) Let me know whenever you have the time, thanks! |
Well, I'm not happy with the test coverage but I got sidetracked before improving them and haven't returned to it yet. It seems to work though. |
There exist Arm extensions for ELF. This PR aims to add support to
goblin
.goblin::elf::arm
defines some contents and some extension traits which add Arm-specific functionality to existinggoblin
types. In particular,elf::Header::arm()
returns anOption<ArmElfHeader>
which (for Arm executables) can distinguish hard-float from soft-float, and distinguish Arm entrypoints from Thumb entrypoints.elf::Section::arm_special_section()
returns anOption<ArmSpecialSection>
which among other things can identify anArmSpecialSection::BuildAttributes
section.goblin::elf::arm::build_attributes
is the largest single part of this PR. It adds a bunch of types for parsing through the Arm build attributes hierarchy, mostly in (data type, fallible iterator, iterator error) sets. It also defines a particularly gory macro for use bybuild_attributes
submodules. You see, Arm build attributes are organized into vendor-specific sections, and each vendor is free to define attributes as they see fit. Modeling this in Rust in a way that preservesgoblin
API stability is challenging.The most interesting build attribute vendor is the Arm embedded ABI (
aeabi
) vendor, captured here ingoblin::elf::arm::build_attributes::aeabi
. Every Arm tool produces and consumesaeabi
build attributes. The original spec describes attributes like:That macro lets me write this as:
The macro expands to:
…along with all the boring, duplicative mapping and conversion code.
This all needs considerably better test coverage before it's ready to merge. I'm opening this as a draft PR for feedback and discussion.