auto clippy fixes

This commit is contained in:
Folkert 2023-06-26 20:42:50 +02:00
parent 72c85efc83
commit ef39bad7c6
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
146 changed files with 750 additions and 1005 deletions

View file

@ -202,7 +202,7 @@ impl<'a> Surgeries<'a> {
println!();
println!("Text Sections");
for sec in text_sections.iter() {
println!("{:+x?}", sec);
println!("{sec:+x?}");
}
}
@ -285,8 +285,7 @@ impl<'a> Surgeries<'a> {
let offset = inst.next_ip() - op_size as u64 - sec.address() + file_offset;
if verbose {
println!(
"\tNeed to surgically replace {} bytes at file offset {:+x}",
op_size, offset,
"\tNeed to surgically replace {op_size} bytes at file offset {offset:+x}",
);
println!(
"\tIts current value is {:+x?}",
@ -373,13 +372,13 @@ pub(crate) fn preprocess_elf(
other.sort_by_key(|t| t.1);
for (name, vaddr) in other.iter() {
println!("\t{:#08x}: {}", vaddr, name);
println!("\t{vaddr:#08x}: {name}");
}
println!("Of which {} are builtins", builtins.len(),);
for (name, vaddr) in builtins.iter() {
println!("\t{:#08x}: {}", vaddr, name);
println!("\t{vaddr:#08x}: {name}");
}
}
@ -410,8 +409,8 @@ pub(crate) fn preprocess_elf(
}
};
if verbose {
println!("PLT Address: {:+x}", plt_address);
println!("PLT File Offset: {:+x}", plt_offset);
println!("PLT Address: {plt_address:+x}");
println!("PLT File Offset: {plt_offset:+x}");
}
let app_syms: Vec<_> = exec_obj
@ -467,7 +466,7 @@ pub(crate) fn preprocess_elf(
}
println!();
println!("App Function Address Map: {:+x?}", app_func_addresses);
println!("App Function Address Map: {app_func_addresses:+x?}");
}
let symbol_and_plt_processing_duration = symbol_and_plt_processing_start.elapsed();
@ -526,7 +525,7 @@ pub(crate) fn preprocess_elf(
if verbose {
println!();
println!("{:+x?}", md);
println!("{md:+x?}");
}
let saving_metadata_start = Instant::now();
@ -593,12 +592,12 @@ fn gen_elf_le(
if verbose {
println!();
println!("PH Offset: {:+x}", ph_offset);
println!("PH Entry Size: {}", ph_ent_size);
println!("PH Entry Count: {}", ph_num);
println!("SH Offset: {:+x}", sh_offset);
println!("SH Entry Size: {}", sh_ent_size);
println!("SH Entry Count: {}", sh_num);
println!("PH Offset: {ph_offset:+x}");
println!("PH Entry Size: {ph_ent_size}");
println!("PH Entry Count: {ph_num}");
println!("SH Offset: {sh_offset:+x}");
println!("SH Entry Size: {sh_ent_size}");
println!("SH Entry Count: {sh_num}");
}
// Copy header and shift everything to enable more program sections.
@ -633,10 +632,7 @@ fn gen_elf_le(
user_error!("Executable does not load any data at 0x00000000\nProbably input the wrong file as the executable");
}
if verbose {
println!(
"Shifting all data after: {:+x}({:+x})",
physical_shift_start, virtual_shift_start
);
println!("Shifting all data after: {physical_shift_start:+x}({virtual_shift_start:+x})");
}
// Shift all of the program headers.
@ -998,7 +994,7 @@ fn scan_elf_dynamic_deps(
let dynstr_data = match dynstr_sec.uncompressed_data() {
Ok(data) => data,
Err(err) => {
panic!("Failed to load dynstr section: {}", err);
panic!("Failed to load dynstr section: {err}");
}
};
@ -1028,10 +1024,7 @@ fn scan_elf_dynamic_deps(
if Path::new(c_str).file_name() == shared_lib_filename {
shared_lib_index = Some(dyn_lib_index);
if verbose {
println!(
"Found shared lib in dynamic table at index: {}",
dyn_lib_index
);
println!("Found shared lib in dynamic table at index: {dyn_lib_index}");
}
}
}
@ -1260,14 +1253,14 @@ fn surgery_elf_help(
if verbose {
println!();
println!("Is Elf64: {}", elf64);
println!("Is Little Endian: {}", litte_endian);
println!("PH Offset: {:+x}", ph_offset);
println!("PH Entry Size: {}", ph_ent_size);
println!("PH Entry Count: {}", ph_num);
println!("SH Offset: {:+x}", sh_offset);
println!("SH Entry Size: {}", sh_ent_size);
println!("SH Entry Count: {}", sh_num);
println!("Is Elf64: {elf64}");
println!("Is Little Endian: {litte_endian}");
println!("PH Offset: {ph_offset:+x}");
println!("PH Entry Size: {ph_ent_size}");
println!("PH Entry Count: {ph_num}");
println!("SH Offset: {sh_offset:+x}");
println!("SH Entry Size: {sh_ent_size}");
println!("SH Entry Count: {sh_num}");
}
// Backup section header table.
@ -1360,8 +1353,8 @@ fn surgery_elf_help(
}
}
if verbose {
println!("Data Relocation Offsets: {:+x?}", symbol_vaddr_map);
println!("Found App Function Symbols: {:+x?}", app_func_vaddr_map);
println!("Data Relocation Offsets: {symbol_vaddr_map:+x?}");
println!("Found App Function Symbols: {app_func_vaddr_map:+x?}");
}
let (new_text_section_offset, new_text_section_vaddr) = text_sections
@ -1427,22 +1420,18 @@ fn surgery_elf_help(
if verbose {
println!();
println!(
"Processing Relocations for Section: 0x{:+x?} @ {:+x} (virt: {:+x})",
sec, section_offset, section_virtual_offset
"Processing Relocations for Section: 0x{sec:+x?} @ {section_offset:+x} (virt: {section_virtual_offset:+x})"
);
}
for rel in sec.relocations() {
if verbose {
println!("\tFound Relocation: {:+x?}", rel);
println!("\tFound Relocation: {rel:+x?}");
}
match rel.1.target() {
RelocationTarget::Symbol(index) => {
let target_offset = if let Some(target_offset) = symbol_vaddr_map.get(&index) {
if verbose {
println!(
"\t\tRelocation targets symbol in app at: {:+x}",
target_offset
);
println!("\t\tRelocation targets symbol in app at: {target_offset:+x}");
}
Some(*target_offset as i64)
} else {
@ -1455,8 +1444,7 @@ fn surgery_elf_help(
let vaddr = (*address + md.added_byte_count) as i64;
if verbose {
println!(
"\t\tRelocation targets symbol in host: {} @ {:+x}",
name, vaddr
"\t\tRelocation targets symbol in host: {name} @ {vaddr:+x}"
);
}
vaddr
@ -1660,7 +1648,7 @@ fn surgery_elf_help(
for s in md.surgeries.get(func_name).unwrap_or(&vec![]) {
if verbose {
println!("\tPerforming surgery: {:+x?}", s);
println!("\tPerforming surgery: {s:+x?}");
}
let surgery_virt_offset = match s.virtual_offset {
VirtualOffset::Relative(vs) => (vs + md.added_byte_count) as i64,
@ -1670,7 +1658,7 @@ fn surgery_elf_help(
4 => {
let target = (func_virt_offset as i64 - surgery_virt_offset) as i32;
if verbose {
println!("\tTarget Jump: {:+x}", target);
println!("\tTarget Jump: {target:+x}");
}
let data = target.to_le_bytes();
exec_mmap[(s.file_offset + md.added_byte_count) as usize..][..4]
@ -1679,7 +1667,7 @@ fn surgery_elf_help(
8 => {
let target = func_virt_offset as i64 - surgery_virt_offset;
if verbose {
println!("\tTarget Jump: {:+x}", target);
println!("\tTarget Jump: {target:+x}");
}
let data = target.to_le_bytes();
exec_mmap[(s.file_offset + md.added_byte_count) as usize..][..8]
@ -1700,8 +1688,8 @@ fn surgery_elf_help(
let target =
(func_virt_offset as i64 - (plt_vaddr as i64 + jmp_inst_len as i64)) as i32;
if verbose {
println!("\tPLT: {:+x}, {:+x}", plt_off, plt_vaddr);
println!("\tTarget Jump: {:+x}", target);
println!("\tPLT: {plt_off:+x}, {plt_vaddr:+x}");
println!("\tTarget Jump: {target:+x}");
}
let data = target.to_le_bytes();
exec_mmap[plt_off] = 0xE9;

View file

@ -82,12 +82,10 @@ pub fn create_dylib_macho(
if !output.status.success() {
match std::str::from_utf8(&output.stderr) {
Ok(stderr) => panic!(
"Failed to link dummy shared library - stderr of the `ld` command was:\n{}",
stderr
"Failed to link dummy shared library - stderr of the `ld` command was:\n{stderr}"
),
Err(utf8_err) => panic!(
"Failed to link dummy shared library - stderr of the `ld` command was invalid utf8 ({:?})",
utf8_err
"Failed to link dummy shared library - stderr of the `ld` command was invalid utf8 ({utf8_err:?})"
),
}
}

View file

@ -64,7 +64,7 @@ pub fn supported(link_type: LinkType, target: &Triple) -> bool {
pub const PRECOMPILED_HOST_EXT: &str = "rh"; // Short for "roc host"
pub fn preprocessed_host_filename(target: &Triple) -> Option<String> {
roc_target::get_target_triple_str(target).map(|x| format!("{}.{}", x, PRECOMPILED_HOST_EXT))
roc_target::get_target_triple_str(target).map(|x| format!("{x}.{PRECOMPILED_HOST_EXT}"))
}
fn metadata_file_name(target: &Triple) -> String {
@ -181,9 +181,9 @@ impl ExposedSymbols {
let sym = x.as_str(interns);
custom_names.extend([
format!("roc__{}_1_exposed", sym),
format!("roc__{}_1_exposed_generic", sym),
format!("roc__{}_1_exposed_size", sym),
format!("roc__{sym}_1_exposed"),
format!("roc__{sym}_1_exposed_generic"),
format!("roc__{sym}_1_exposed_size"),
]);
let exported_closure_types = exposed_to_host
@ -193,9 +193,9 @@ impl ExposedSymbols {
for (i, _) in exported_closure_types.enumerate() {
custom_names.extend([
format!("roc__{}_{i}_caller", sym),
format!("roc__{}_{i}_size", sym),
format!("roc__{}_{i}_result_size", sym),
format!("roc__{sym}_{i}_caller"),
format!("roc__{sym}_{i}_size"),
format!("roc__{sym}_{i}_result_size"),
]);
}
}
@ -227,16 +227,16 @@ impl ExposedSymbols {
for sym in &self.top_level_values {
custom_names.extend([
format!("roc__{}_1_exposed", sym),
format!("roc__{}_1_exposed_generic", sym),
format!("roc__{}_size", sym),
format!("roc__{sym}_1_exposed"),
format!("roc__{sym}_1_exposed_generic"),
format!("roc__{sym}_size"),
]);
for closure_type in &self.exported_closure_types {
custom_names.extend([
format!("roc__{}_1_{}_caller", sym, closure_type),
format!("roc__{}_1_{}_size", sym, closure_type),
format!("roc__{}_1_{}_result_size", sym, closure_type),
format!("roc__{sym}_1_{closure_type}_caller"),
format!("roc__{sym}_1_{closure_type}_size"),
format!("roc__{sym}_1_{closure_type}_result_size"),
]);
}
}
@ -421,7 +421,7 @@ fn preprocess(
time: bool,
) {
if verbose {
println!("Targeting: {}", target);
println!("Targeting: {target}");
}
let endianness = target

View file

@ -192,7 +192,7 @@ impl<'a> Surgeries<'a> {
println!();
println!("Text Sections");
for sec in text_sections.iter() {
println!("{:+x?}", sec);
println!("{sec:+x?}");
}
}
@ -275,8 +275,7 @@ impl<'a> Surgeries<'a> {
let offset = inst.next_ip() - op_size as u64 - sec.address() + file_offset;
if verbose {
println!(
"\tNeed to surgically replace {} bytes at file offset {:+x}",
op_size, offset,
"\tNeed to surgically replace {op_size} bytes at file offset {offset:+x}",
);
println!(
"\tIts current value is {:+x?}",
@ -382,8 +381,8 @@ pub(crate) fn preprocess_macho(
}
};
if verbose {
println!("PLT Address: {:+x}", plt_address);
println!("PLT File Offset: {:+x}", plt_offset);
println!("PLT Address: {plt_address:+x}");
println!("PLT File Offset: {plt_offset:+x}");
}
let app_syms: Vec<_> = exec_obj.symbols().filter(is_roc_undefined).collect();
@ -532,7 +531,7 @@ pub(crate) fn preprocess_macho(
}
println!();
println!("App Function Address Map: {:+x?}", app_func_addresses);
println!("App Function Address Map: {app_func_addresses:+x?}");
}
let symbol_and_plt_processing_duration = symbol_and_plt_processing_start.elapsed();
@ -603,7 +602,7 @@ pub(crate) fn preprocess_macho(
if verbose {
println!();
println!("{:+x?}", md);
println!("{md:+x?}");
}
let saving_metadata_start = Instant::now();
@ -1101,8 +1100,7 @@ fn gen_macho_le(
}
cmd => {
eprintln!(
"- - - Unrecognized Mach-O command during linker preprocessing: 0x{:x?}",
cmd
"- - - Unrecognized Mach-O command during linker preprocessing: 0x{cmd:x?}"
);
// panic!(
// "Unrecognized Mach-O command during linker preprocessing: 0x{:x?}",
@ -1237,10 +1235,7 @@ fn surgery_macho_help(
let new_rodata_section_vaddr = virt_offset;
if verbose {
println!();
println!(
"New Virtual Rodata Section Address: {:+x?}",
new_rodata_section_vaddr
);
println!("New Virtual Rodata Section Address: {new_rodata_section_vaddr:+x?}");
}
// First decide on sections locations and then recode every exact symbol locations.
@ -1320,8 +1315,8 @@ fn surgery_macho_help(
}
}
if verbose {
println!("Data Relocation Offsets: {:+x?}", symbol_vaddr_map);
println!("Found App Function Symbols: {:+x?}", app_func_vaddr_map);
println!("Data Relocation Offsets: {symbol_vaddr_map:+x?}");
println!("Found App Function Symbols: {app_func_vaddr_map:+x?}");
}
// let (new_text_section_offset, new_text_section_vaddr) = text_sections
@ -1356,22 +1351,18 @@ fn surgery_macho_help(
if verbose {
println!();
println!(
"Processing Relocations for Section: 0x{:+x?} @ {:+x} (virt: {:+x})",
sec, section_offset, section_virtual_offset
"Processing Relocations for Section: 0x{sec:+x?} @ {section_offset:+x} (virt: {section_virtual_offset:+x})"
);
}
for rel in sec.relocations() {
if verbose {
println!("\tFound Relocation: {:+x?}", rel);
println!("\tFound Relocation: {rel:+x?}");
}
match rel.1.target() {
RelocationTarget::Symbol(index) => {
let target_offset = if let Some(target_offset) = symbol_vaddr_map.get(&index) {
if verbose {
println!(
"\t\tRelocation targets symbol in app at: {:+x}",
target_offset
);
println!("\t\tRelocation targets symbol in app at: {target_offset:+x}");
}
Some(*target_offset as i64)
} else {
@ -1384,8 +1375,7 @@ fn surgery_macho_help(
let vaddr = (*address + md.added_byte_count) as i64;
if verbose {
println!(
"\t\tRelocation targets symbol in host: {} @ {:+x}",
name, vaddr
"\t\tRelocation targets symbol in host: {name} @ {vaddr:+x}"
);
}
vaddr
@ -1406,10 +1396,9 @@ fn surgery_macho_help(
};
if verbose {
println!(
"\t\tRelocation base location: {:+x} (virt: {:+x})",
base, virt_base
"\t\tRelocation base location: {base:+x} (virt: {virt_base:+x})"
);
println!("\t\tFinal relocation target offset: {:+x}", target);
println!("\t\tFinal relocation target offset: {target:+x}");
}
match rel.1.size() {
32 => {
@ -1560,7 +1549,7 @@ fn surgery_macho_help(
for s in md.surgeries.get(func_name).unwrap_or(&vec![]) {
if verbose {
println!("\tPerforming surgery: {:+x?}", s);
println!("\tPerforming surgery: {s:+x?}");
}
let surgery_virt_offset = match s.virtual_offset {
VirtualOffset::Relative(vs) => (vs + md.added_byte_count) as i64,
@ -1570,7 +1559,7 @@ fn surgery_macho_help(
4 => {
let target = (func_virt_offset as i64 - surgery_virt_offset) as i32;
if verbose {
println!("\tTarget Jump: {:+x}", target);
println!("\tTarget Jump: {target:+x}");
}
let data = target.to_le_bytes();
exec_mmap[(s.file_offset + md.added_byte_count) as usize
@ -1580,7 +1569,7 @@ fn surgery_macho_help(
8 => {
let target = func_virt_offset as i64 - surgery_virt_offset;
if verbose {
println!("\tTarget Jump: {:+x}", target);
println!("\tTarget Jump: {target:+x}");
}
let data = target.to_le_bytes();
exec_mmap[(s.file_offset + md.added_byte_count) as usize
@ -1602,8 +1591,8 @@ fn surgery_macho_help(
let target =
(func_virt_offset as i64 - (plt_vaddr as i64 + jmp_inst_len as i64)) as i32;
if verbose {
println!("\tPLT: {:+x}, {:+x}", plt_off, plt_vaddr);
println!("\tTarget Jump: {:+x}", target);
println!("\tPLT: {plt_off:+x}, {plt_vaddr:+x}");
println!("\tTarget Jump: {target:+x}");
}
let data = target.to_le_bytes();
exec_mmap[plt_off] = 0xE9;

View file

@ -450,8 +450,7 @@ pub(crate) fn surgery_pe(executable_path: &Path, metadata_path: &Path, roc_app_b
.contains(&name.as_str());
if *address == 0 && !name.starts_with("roc") && !is_ingested_compiler_rt {
eprintln!(
"I don't know the address of the {} function! this may cause segfaults",
name
"I don't know the address of the {name} function! this may cause segfaults"
);
}
@ -1718,7 +1717,7 @@ mod test {
std::io::stdout().write_all(&output.stdout).unwrap();
std::io::stderr().write_all(&output.stderr).unwrap();
panic!("zig build-exe failed: {}", command_str);
panic!("zig build-exe failed: {command_str}");
}
let preprocessed_host_filename =
@ -1939,7 +1938,7 @@ mod test {
std::io::stdout().write_all(&output.stdout).unwrap();
std::io::stderr().write_all(&output.stderr).unwrap();
panic!("zig build-exe failed: {}", command_str);
panic!("zig build-exe failed: {command_str}");
}
let host_bytes = std::fs::read(dir.join("host.exe")).unwrap();