mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
implement implicit addends (used for .rdata relocations by rust)
This commit is contained in:
parent
ccc69c2f16
commit
761891a5a1
1 changed files with 18 additions and 4 deletions
|
@ -364,16 +364,24 @@ pub(crate) fn surgery_pe(executable_path: &Path, metadata_path: &Path, roc_app_b
|
|||
} = app_relocation;
|
||||
|
||||
if let Some(destination) = md.exports.get(name) {
|
||||
dbg!(&name);
|
||||
match relocation.kind() {
|
||||
object::RelocationKind::Relative => {
|
||||
// we implicitly only do 32-bit relocations
|
||||
debug_assert_eq!(relocation.size(), 32);
|
||||
|
||||
let implicit = if relocation.has_implicit_addend() {
|
||||
let slice =
|
||||
&executable[offset + *offset_in_section as usize..][..4];
|
||||
u32::from_le_bytes(slice.try_into().unwrap())
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
let delta = destination
|
||||
- section_virtual_address as i64
|
||||
- *offset_in_section as i64
|
||||
+ relocation.addend();
|
||||
+ relocation.addend()
|
||||
+ implicit as i64;
|
||||
|
||||
executable[offset + *offset_in_section as usize..][..4]
|
||||
.copy_from_slice(&(delta as i32).to_le_bytes());
|
||||
|
@ -384,11 +392,17 @@ pub(crate) fn surgery_pe(executable_path: &Path, metadata_path: &Path, roc_app_b
|
|||
// we implicitly only do 32-bit relocations
|
||||
debug_assert_eq!(relocation.size(), 32);
|
||||
|
||||
dbg!(&name);
|
||||
let implicit = if relocation.has_implicit_addend() {
|
||||
let slice = &executable[offset + *offset_in_section as usize..][..4];
|
||||
u32::from_le_bytes(slice.try_into().unwrap())
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
let delta =
|
||||
destination - section_virtual_address as i64 - *offset_in_section as i64
|
||||
+ relocation.addend();
|
||||
+ relocation.addend()
|
||||
+ implicit as i64;
|
||||
|
||||
executable[offset + *offset_in_section as usize..][..4]
|
||||
.copy_from_slice(&(delta as i32).to_le_bytes());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue