Minor cleanup and update to parameters

This commit is contained in:
Brendan Hansknecht 2021-08-27 22:47:43 -07:00
parent 7e1f5c47e4
commit 7d34c88e64

View file

@ -54,11 +54,6 @@ pub fn build_app<'a>() -> App<'a> {
.help("The dynamically linked platform executable") .help("The dynamically linked platform executable")
.required(true), .required(true),
) )
.arg(
Arg::with_name(SHARED_LIB)
.help("The dummy shared library representing the Roc application")
.required(true),
)
.arg( .arg(
Arg::with_name(METADATA) Arg::with_name(METADATA)
.help("Where to save the metadata from preprocessing") .help("Where to save the metadata from preprocessing")
@ -69,6 +64,11 @@ pub fn build_app<'a>() -> App<'a> {
.help("The modified version of the dynamically linked platform executable") .help("The modified version of the dynamically linked platform executable")
.required(true), .required(true),
) )
.arg(
Arg::with_name(SHARED_LIB)
.help("The name of the shared library used in building the platform")
.default_value("libapp.so"),
)
.arg( .arg(
Arg::with_name(FLAG_VERBOSE) Arg::with_name(FLAG_VERBOSE)
.long(FLAG_VERBOSE) .long(FLAG_VERBOSE)
@ -87,17 +87,24 @@ pub fn build_app<'a>() -> App<'a> {
.subcommand( .subcommand(
App::new(CMD_SURGERY) App::new(CMD_SURGERY)
.about("Links a preprocessed platform with a Roc application.") .about("Links a preprocessed platform with a Roc application.")
.arg(
Arg::with_name(APP)
.help("The Roc application object file waiting to be linked")
.required(true),
)
.arg( .arg(
Arg::with_name(METADATA) Arg::with_name(METADATA)
.help("The metadata created by preprocessing the platform") .help("The metadata created by preprocessing the platform")
.required(true), .required(true),
) )
.arg( .arg(
Arg::with_name(APP) Arg::with_name(OUT)
.help("The Roc application object file waiting to be linked") .help(
"The modified version of the dynamically linked platform. \
It will be consumed to make linking faster.",
)
.required(true), .required(true),
) )
.arg(Arg::with_name(OUT).help("The modified version of the dynamically linked platform. It will be consumed to make linking faster.").required(true))
.arg( .arg(
Arg::with_name(FLAG_VERBOSE) Arg::with_name(FLAG_VERBOSE)
.long(FLAG_VERBOSE) .long(FLAG_VERBOSE)
@ -821,7 +828,7 @@ pub fn preprocess(matches: &ArgMatches) -> io::Result<i32> {
} }
} }
// TODO: look into shifting all of the debug info. // TODO: look into shifting all of the debug info and eh_frames.
// Delete shared library from the dynamic table. // Delete shared library from the dynamic table.
let out_ptr = out_mmap.as_mut_ptr(); let out_ptr = out_mmap.as_mut_ptr();
@ -1000,14 +1007,16 @@ pub fn surgery(matches: &ArgMatches) -> io::Result<i32> {
let name = sec.name(); let name = sec.name();
// TODO: we should really split these out and use finer permission controls. // TODO: we should really split these out and use finer permission controls.
name.is_ok() name.is_ok()
// TODO: Does Roc ever create a data section? I think no cause it would mess up fully functional guarantees.
&& (name.unwrap().starts_with(".data") && (name.unwrap().starts_with(".data")
|| name.unwrap().starts_with(".rodata") || name.unwrap().starts_with(".rodata")
// TODO: bss sections we generate should not have a real file size.
|| name.unwrap().starts_with(".bss")) || name.unwrap().starts_with(".bss"))
}) })
.collect(); .collect();
let mut symbol_offset_map: MutMap<usize, usize> = MutMap::default(); let mut symbol_offset_map: MutMap<usize, usize> = MutMap::default();
// TODO: we don't yet deal with relocations for these sections. // TODO: we don't yet deal with relocations for these sections (Do we need to?).
// We should probably first define where each section will go and resolve all symbol locations. // We should probably first define where each section will go and resolve all symbol locations.
// Then we can support all relocations correctly. // Then we can support all relocations correctly.
for sec in rodata_sections { for sec in rodata_sections {
@ -1174,6 +1183,11 @@ pub fn surgery(matches: &ArgMatches) -> io::Result<i32> {
} }
target_offset - base_offset + rel.1.addend() target_offset - base_offset + rel.1.addend()
} }
RelocationKind::Absolute => {
let target_vaddr = target_offset + new_segment_vaddr as i64;
println!("Target: 0x{:x}", target_vaddr);
target_vaddr
}
x => { x => {
println!("Relocation Kind not yet support: {:?}", x); println!("Relocation Kind not yet support: {:?}", x);
return Ok(-1); return Ok(-1);
@ -1236,6 +1250,8 @@ pub fn surgery(matches: &ArgMatches) -> io::Result<i32> {
// Flush app only data to speed up write to disk. // Flush app only data to speed up write to disk.
exec_mmap.flush_async_range(new_segment_offset, offset - new_segment_offset)?; exec_mmap.flush_async_range(new_segment_offset, offset - new_segment_offset)?;
// TODO: look into merging symbol tables, debug info, and eh frames to enable better debugger experience.
// Add 2 new sections. // Add 2 new sections.
let new_section_count = 2; let new_section_count = 2;
offset += new_section_count * sh_ent_size as usize; offset += new_section_count * sh_ent_size as usize;