Merge pull request #3410 from rtfeldman/merge-macho-progress

port all macho linker work to trunk and make it mergable
This commit is contained in:
Richard Feldman 2022-07-16 16:04:42 -04:00 committed by GitHub
commit 6389dba5b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 1921 additions and 627 deletions

63
Cargo.lock generated
View File

@ -2105,6 +2105,22 @@ dependencies = [
"libc",
]
[[package]]
name = "mach_object"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b6f2d7176b94027af58085a2c9d27c4e416586caba409c314569213901d6068"
dependencies = [
"bitflags",
"byteorder",
"lazy_static",
"libc",
"log",
"thiserror",
"time 0.3.11",
"uuid",
]
[[package]]
name = "malloc_buf"
version = "0.0.6"
@ -2460,6 +2476,15 @@ dependencies = [
"syn",
]
[[package]]
name = "num_threads"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
dependencies = [
"libc",
]
[[package]]
name = "objc"
version = "0.2.7"
@ -2499,6 +2524,18 @@ dependencies = [
"objc",
]
[[package]]
name = "object"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2"
dependencies = [
"crc32fast",
"flate2",
"indexmap",
"memchr",
]
[[package]]
name = "object"
version = "0.28.4"
@ -3733,10 +3770,12 @@ dependencies = [
"bumpalo",
"clap 3.2.8",
"iced-x86",
"mach_object",
"memmap2 0.5.4",
"object 0.29.0",
"object 0.26.2",
"roc_build",
"roc_collections",
"roc_error_macros",
"roc_mono",
"serde",
"target-lexicon",
@ -4852,11 +4891,23 @@ dependencies = [
"libc",
"standback",
"stdweb 0.4.20",
"time-macros",
"time-macros 0.1.1",
"version_check",
"winapi",
]
[[package]]
name = "time"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72c91f41dcb2f096c05f0873d667dceec1087ce5bcf984ec8ffb19acddbb3217"
dependencies = [
"itoa 1.0.2",
"libc",
"num_threads",
"time-macros 0.2.4",
]
[[package]]
name = "time-macros"
version = "0.1.1"
@ -4867,6 +4918,12 @@ dependencies = [
"time-macros-impl",
]
[[package]]
name = "time-macros"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792"
[[package]]
name = "time-macros-impl"
version = "0.1.2"
@ -5478,7 +5535,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22dc83aadbdf97388de3211cb6f105374f245a3cf2a5c65a16776e7a087a8468"
dependencies = [
"byteorder",
"time",
"time 0.2.27",
"wasmer-types",
]

View File

@ -287,13 +287,7 @@ pub fn build_file<'a>(
let link_start = SystemTime::now();
let problems = match (linking_strategy, link_type) {
(LinkingStrategy::Surgical, _) => {
roc_linker::link_preprocessed_host(target, &host_input_path, app_o_file, &binary_path)
.map_err(|err| {
todo!(
"gracefully handle failing to surgically link with error: {:?}",
err
);
})?;
roc_linker::link_preprocessed_host(target, &host_input_path, app_o_file, &binary_path);
problems
}
(LinkingStrategy::Additive, _) | (LinkingStrategy::Legacy, LinkType::None) => {
@ -399,8 +393,7 @@ fn spawn_rebuild_thread(
exported_symbols,
exported_closure_types,
target_valgrind,
)
.unwrap();
);
}
LinkingStrategy::Legacy => {
rebuild_host(

View File

@ -488,7 +488,7 @@ pub fn build(
let linking_strategy = if wasm_dev_backend {
LinkingStrategy::Additive
} else if !roc_linker::supported(&link_type, &triple)
} else if !roc_linker::supported(link_type, &triple)
|| matches.value_of(FLAG_LINKER) == Some("legacy")
{
LinkingStrategy::Legacy

View File

@ -11,21 +11,17 @@ description = "A surgical linker for Roc"
name = "roc_linker"
path = "src/lib.rs"
[[bin]]
name = "link"
path = "src/main.rs"
test = false
bench = false
[dependencies]
roc_mono = { path = "../compiler/mono" }
roc_build = { path = "../compiler/build" }
roc_collections = { path = "../compiler/collections" }
roc_error_macros = { path = "../error_macros" }
bumpalo = { version = "3.8.0", features = ["collections"] }
clap = { version = "3.1.15", default-features = false, features = ["std", "color", "suggestions"] }
iced-x86 = { version = "1.15.0", default-features = false, features = ["std", "decoder", "op_code_info", "instr_info"] }
memmap2 = "0.5.3"
object = { version = "0.29.0", features = ["read", "write"] }
object = { version = "0.26.2", features = ["read", "write"] }
mach_object = "0.1"
serde = { version = "1.0.130", features = ["derive"] }
bincode = "1.3.3"
target-lexicon = "0.12.3"

View File

@ -39,7 +39,7 @@ This linker is run in 2 phases: preprocessing and surigical linking.
- As a prereq, we need roc building on Windows (I'm not sure it does currently).
- Definitely a solid bit different than elf, but hopefully after refactoring for Macho, won't be that crazy to add.
- Look at enabling completely in memory linking that could be used with `roc run` and/or `roc repl`
- Look more into roc hosts and keeping certain functions. Currently I just disabled linker garbage collection.
- Look more into rust hosts and keeping certain functions. Currently I just disabled linker garbage collection.
This works but adds 1.2MB (40%) to even a tiny app. It may be a size issue for large rust hosts.
Roc, for reference, adds 13MB (20%) when linked without garbage collection.
- Add a feature to the compiler to make this linker optional.

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +0,0 @@
use roc_linker::{build_app, preprocess, surgery, CMD_PREPROCESS, CMD_SURGERY};
use std::io;
fn main() -> io::Result<()> {
let matches = build_app().get_matches();
let exit_code = match matches.subcommand() {
None => Ok::<i32, io::Error>(-1),
Some((CMD_PREPROCESS, sub_matches)) => preprocess(sub_matches),
Some((CMD_SURGERY, sub_matches)) => surgery(sub_matches),
_ => unreachable!(),
}?;
std::process::exit(exit_code);
}

View File

@ -34,4 +34,5 @@ pub struct Metadata {
pub dynamic_symbol_table_section_offset: u64,
pub symbol_table_section_offset: u64,
pub symbol_table_size: u64,
pub macho_cmd_loc: u64,
}