mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
switch from assignment to using the set method for numbers
This commit is contained in:
parent
e88d759331
commit
dbbc621892
2 changed files with 33 additions and 26 deletions
|
@ -578,17 +578,18 @@ fn gen_elf_le(
|
||||||
let p_offset = ph.p_offset.get(LE);
|
let p_offset = ph.p_offset.get(LE);
|
||||||
if (p_type == elf::PT_LOAD && p_offset == 0) || p_type == elf::PT_PHDR {
|
if (p_type == elf::PT_LOAD && p_offset == 0) || p_type == elf::PT_PHDR {
|
||||||
// Extend length for the first segment and the program header.
|
// Extend length for the first segment and the program header.
|
||||||
ph.p_filesz = endian::U64::new(LE, ph.p_filesz.get(LE) + md.added_byte_count);
|
ph.p_filesz
|
||||||
ph.p_memsz = endian::U64::new(LE, ph.p_memsz.get(LE) + md.added_byte_count);
|
.set(LE, ph.p_filesz.get(LE) + md.added_byte_count);
|
||||||
|
ph.p_memsz.set(LE, ph.p_memsz.get(LE) + md.added_byte_count);
|
||||||
} else {
|
} else {
|
||||||
// Shift if needed.
|
// Shift if needed.
|
||||||
if physical_shift_start <= p_offset {
|
if physical_shift_start <= p_offset {
|
||||||
ph.p_offset = endian::U64::new(LE, p_offset + md.added_byte_count);
|
ph.p_offset.set(LE, p_offset + md.added_byte_count);
|
||||||
}
|
}
|
||||||
let p_vaddr = ph.p_vaddr.get(LE);
|
let p_vaddr = ph.p_vaddr.get(LE);
|
||||||
if virtual_shift_start <= p_vaddr {
|
if virtual_shift_start <= p_vaddr {
|
||||||
ph.p_vaddr = endian::U64::new(LE, p_vaddr + md.added_byte_count);
|
ph.p_vaddr.set(LE, p_vaddr + md.added_byte_count);
|
||||||
ph.p_paddr = endian::U64::new(LE, p_vaddr + md.added_byte_count);
|
ph.p_paddr.set(LE, p_vaddr + md.added_byte_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -623,10 +624,10 @@ fn gen_elf_le(
|
||||||
let sh_offset = sh.sh_offset.get(LE);
|
let sh_offset = sh.sh_offset.get(LE);
|
||||||
let sh_addr = sh.sh_addr.get(LE);
|
let sh_addr = sh.sh_addr.get(LE);
|
||||||
if physical_shift_start <= sh_offset {
|
if physical_shift_start <= sh_offset {
|
||||||
sh.sh_offset = endian::U64::new(LE, sh_offset + md.added_byte_count);
|
sh.sh_offset.set(LE, sh_offset + md.added_byte_count);
|
||||||
}
|
}
|
||||||
if virtual_shift_start <= sh_addr {
|
if virtual_shift_start <= sh_addr {
|
||||||
sh.sh_addr = endian::U64::new(LE, sh_addr + md.added_byte_count);
|
sh.sh_addr.set(LE, sh_addr + md.added_byte_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record every relocation section.
|
// Record every relocation section.
|
||||||
|
@ -660,7 +661,7 @@ fn gen_elf_le(
|
||||||
for rel in relocations.iter_mut() {
|
for rel in relocations.iter_mut() {
|
||||||
let r_offset = rel.r_offset.get(LE);
|
let r_offset = rel.r_offset.get(LE);
|
||||||
if virtual_shift_start <= r_offset {
|
if virtual_shift_start <= r_offset {
|
||||||
rel.r_offset = endian::U64::new(LE, r_offset + md.added_byte_count);
|
rel.r_offset.set(LE, r_offset + md.added_byte_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -675,7 +676,7 @@ fn gen_elf_le(
|
||||||
for (i, rel) in relocations.iter_mut().enumerate() {
|
for (i, rel) in relocations.iter_mut().enumerate() {
|
||||||
let r_offset = rel.r_offset.get(LE);
|
let r_offset = rel.r_offset.get(LE);
|
||||||
if virtual_shift_start <= r_offset {
|
if virtual_shift_start <= r_offset {
|
||||||
rel.r_offset = endian::U64::new(LE, r_offset + md.added_byte_count);
|
rel.r_offset.set(LE, r_offset + md.added_byte_count);
|
||||||
// Deal with potential adjusts to absolute jumps.
|
// Deal with potential adjusts to absolute jumps.
|
||||||
// TODO: Verify other relocation types.
|
// TODO: Verify other relocation types.
|
||||||
if rel.r_type(LE, false) == elf::R_X86_64_RELATIVE {
|
if rel.r_type(LE, false) == elf::R_X86_64_RELATIVE {
|
||||||
|
@ -796,7 +797,7 @@ fn gen_elf_le(
|
||||||
dyn_offset as usize,
|
dyn_offset as usize,
|
||||||
dynamic_lib_count,
|
dynamic_lib_count,
|
||||||
);
|
);
|
||||||
for mut d in dyns {
|
for d in dyns {
|
||||||
match d.d_tag.get(LE) as u32 {
|
match d.d_tag.get(LE) as u32 {
|
||||||
// I believe this is the list of symbols that need to be update if addresses change.
|
// I believe this is the list of symbols that need to be update if addresses change.
|
||||||
// I am less sure about the symbols from GNU_HASH down.
|
// I am less sure about the symbols from GNU_HASH down.
|
||||||
|
@ -830,7 +831,7 @@ fn gen_elf_le(
|
||||||
| elf::DT_VERNEED => {
|
| elf::DT_VERNEED => {
|
||||||
let d_addr = d.d_val.get(LE);
|
let d_addr = d.d_val.get(LE);
|
||||||
if virtual_shift_start <= d_addr {
|
if virtual_shift_start <= d_addr {
|
||||||
d.d_val = endian::U64::new(LE, d_addr + md.added_byte_count);
|
d.d_val.set(LE, d_addr + md.added_byte_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -850,7 +851,7 @@ fn gen_elf_le(
|
||||||
for sym in symbols {
|
for sym in symbols {
|
||||||
let addr = sym.st_value.get(LE);
|
let addr = sym.st_value.get(LE);
|
||||||
if virtual_shift_start <= addr {
|
if virtual_shift_start <= addr {
|
||||||
sym.st_value = endian::U64::new(LE, addr + md.added_byte_count);
|
sym.st_value.set(LE, addr + md.added_byte_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -882,13 +883,17 @@ fn gen_elf_le(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update main elf header for extra data.
|
// Update main elf header for extra data.
|
||||||
let mut file_header = load_struct_inplace_mut::<elf::FileHeader64<LE>>(&mut out_mmap, 0);
|
let file_header = load_struct_inplace_mut::<elf::FileHeader64<LE>>(&mut out_mmap, 0);
|
||||||
file_header.e_shoff = endian::U64::new(LE, file_header.e_shoff.get(LE) + md.added_byte_count);
|
file_header
|
||||||
|
.e_shoff
|
||||||
|
.set(LE, file_header.e_shoff.get(LE) + md.added_byte_count);
|
||||||
let e_entry = file_header.e_entry.get(LE);
|
let e_entry = file_header.e_entry.get(LE);
|
||||||
if virtual_shift_start <= e_entry {
|
if virtual_shift_start <= e_entry {
|
||||||
file_header.e_entry = endian::U64::new(LE, e_entry + md.added_byte_count);
|
file_header.e_entry.set(LE, e_entry + md.added_byte_count);
|
||||||
}
|
}
|
||||||
file_header.e_phnum = endian::U16::new(LE, ph_num + added_header_count as u16);
|
file_header
|
||||||
|
.e_phnum
|
||||||
|
.set(LE, ph_num + added_header_count as u16);
|
||||||
|
|
||||||
out_mmap
|
out_mmap
|
||||||
}
|
}
|
||||||
|
@ -1486,8 +1491,10 @@ fn surgery_elf_help(
|
||||||
|
|
||||||
// Reload and update file header and size.
|
// Reload and update file header and size.
|
||||||
let file_header = load_struct_inplace_mut::<elf::FileHeader64<LE>>(exec_mmap, 0);
|
let file_header = load_struct_inplace_mut::<elf::FileHeader64<LE>>(exec_mmap, 0);
|
||||||
file_header.e_shoff = endian::U64::new(LE, new_sh_offset as u64);
|
file_header.e_shoff.set(LE, new_sh_offset as u64);
|
||||||
file_header.e_shnum = endian::U16::new(LE, sh_num + new_section_count as u16);
|
file_header
|
||||||
|
.e_shnum
|
||||||
|
.set(LE, sh_num + new_section_count as u16);
|
||||||
|
|
||||||
// Add 2 new segments that match the new sections.
|
// Add 2 new segments that match the new sections.
|
||||||
let program_headers = load_structs_inplace_mut::<elf::ProgramHeader64<LE>>(
|
let program_headers = load_structs_inplace_mut::<elf::ProgramHeader64<LE>>(
|
||||||
|
@ -1606,9 +1613,9 @@ fn surgery_elf_help(
|
||||||
exec_mmap,
|
exec_mmap,
|
||||||
dynsym_offset as usize + *i as usize * mem::size_of::<elf::Sym64<LE>>(),
|
dynsym_offset as usize + *i as usize * mem::size_of::<elf::Sym64<LE>>(),
|
||||||
);
|
);
|
||||||
sym.st_shndx = endian::U16::new(LE, new_text_section_index as u16);
|
sym.st_shndx.set(LE, new_text_section_index as u16);
|
||||||
sym.st_value = endian::U64::new(LE, func_virt_offset);
|
sym.st_value.set(LE, func_virt_offset);
|
||||||
sym.st_size = endian::U64::new(
|
sym.st_size.set(
|
||||||
LE,
|
LE,
|
||||||
match app_func_size_map.get(func_name) {
|
match app_func_size_map.get(func_name) {
|
||||||
Some(size) => *size,
|
Some(size) => *size,
|
||||||
|
@ -1623,9 +1630,9 @@ fn surgery_elf_help(
|
||||||
exec_mmap,
|
exec_mmap,
|
||||||
symtab_offset as usize + *i as usize * mem::size_of::<elf::Sym64<LE>>(),
|
symtab_offset as usize + *i as usize * mem::size_of::<elf::Sym64<LE>>(),
|
||||||
);
|
);
|
||||||
sym.st_shndx = endian::U16::new(LE, new_text_section_index as u16);
|
sym.st_shndx.set(LE, new_text_section_index as u16);
|
||||||
sym.st_value = endian::U64::new(LE, func_virt_offset);
|
sym.st_value.set(LE, func_virt_offset);
|
||||||
sym.st_size = endian::U64::new(
|
sym.st_size.set(
|
||||||
LE,
|
LE,
|
||||||
match app_func_size_map.get(func_name) {
|
match app_func_size_map.get(func_name) {
|
||||||
Some(size) => *size,
|
Some(size) => *size,
|
||||||
|
|
|
@ -1550,8 +1550,8 @@ fn surgery_macho_help(
|
||||||
// exec_mmap,
|
// exec_mmap,
|
||||||
// dynsym_offset as usize + *i as usize * mem::size_of::<elf::Sym64<LE >>(),
|
// dynsym_offset as usize + *i as usize * mem::size_of::<elf::Sym64<LE >>(),
|
||||||
// );
|
// );
|
||||||
// sym.st_value = endian::U64::new(LE , func_virt_offset as u64);
|
// sym.st_value.set(LE , func_virt_offset as u64);
|
||||||
// sym.st_size = endian::U64::new(
|
// sym.st_size.set(
|
||||||
// LE ,
|
// LE ,
|
||||||
// match app_func_size_map.get(func_name) {
|
// match app_func_size_map.get(func_name) {
|
||||||
// Some(size) => *size,
|
// Some(size) => *size,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue