-
Notifications
You must be signed in to change notification settings - Fork 26
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 Reloc::Data, which supports an addend #75
base: master
Are you sure you want to change the base?
Conversation
Fixes m4b#71 This commit creates a new variant 'Data' of the 'Reloc' enum. This can be used to define a relocation to a data section entry with a custom addend. With this change, it's now possible to create a relocation representing an index into an array or some other structure, where the addebd represents the offset from the base. I've only implemented this for ELF. Unfortunately, I'm completely unfamiliar with Mach-O, and don't have an OS X instance available to test with. Additionally, I've moved the magic '-4' into a constant, and added some documentation explaining where it comes from (though I may have a few details wrong). I've also tweaked the binary created by src/bin/main.rs to demonstrate using Reloc::Data
@@ -37,6 +37,29 @@ type Relocation = goblin::elf::reloc::Reloc; | |||
type Symbol = goblin::elf::sym::Sym; | |||
type Section = SectionHeader; | |||
|
|||
/// When we have a link from a function on X86, | |||
/// we create a relocation entry that modifies | |||
/// the PC-relative 32-bit immedaite value of an instruction. (e.g.'call') |
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.
*immediate
This looks like it should work for ELF x86-64. However, I think we need to figure out how this is going to work for ELF x86 and Mach-O. The difference being that unlike ELF x86-64, these do not store the addend in the relocation. Note that this is a problem for the Also, I don't think it makes sense for |
Which relocation types are you referring to? From what I can see, |
I mean that x86-32 uses .rel instead of .rela, and faerie currently has no support for writing addends except in the relocation entry. |
// Having a user-supplied addend doesn't make sense here, | ||
// as it would cause us to move within the GOT itself - | ||
// not relative to the address stored in the GOT entry. | ||
assert!(addend == 0, "Addend must be 0 for reloc {:?}", l); |
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.
so the way we've been doing this, or at least I thought, perhaps things have changed:
- artifact is the only real "entry" to the various backends.
- consequently most user level errors are attempted to be caught during artifact construction, and a Result is returned.
- asserts in the backends are to ensure that contracts between the artifact front end and the backend are enforced at the artifact front end via result. I.e., they're programmer invariants, not user input invariants. So if there is some kind of user introduced error that is backend specific, but not enforced by artifact (because it can't, for example), then we should return a result, instead of asserting.
So I bring this all up because this assert looks like its enforcing user inputs to have certain properties, which means it should be a returning a Result.
That being said, I can't see on this git review if this function returns a Result, so maybe you didn't feel like changing the return type, etc., which is reasonable, but then we should revisit (at some other PR perhaps) this functions return type if user errors are being asserted against.
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.
It doesn't return a Result (FYI github lets you expand the review code to see this).
cc @sunfishcode @pchickey |
What happened here? Seems there were some unresolved questions? How mergeable/close is this? |
Ping all concerned parties; same comment as above, this PR is getting stale :) |
You could just go ahead and merge this. It's no worse than the existing |
I myself don't feel I have a clear view of how faerie's "automatic" approach to relocations should work, so I'm stepping back as reviewer here. |
Fixes #71
This commit creates a new variant 'Data' of the 'Reloc' enum.
This can be used to define a relocation to a data section entry
with a custom addend.
With this change, it's now possible to create a relocation representing
an index into an array or some other structure, where the addebd
represents the offset from the base.
I've only implemented this for ELF. Unfortunately, I'm completely
unfamiliar with Mach-O, and don't have an OS X instance available to
test with.
Additionally, I've moved the magic '-4' into a constant, and added some
documentation explaining where it comes from (though I may have a few
details wrong).
I've also tweaked the binary created by src/bin/main.rs to demonstrate
using Reloc::Data