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", "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]] [[package]]
name = "malloc_buf" name = "malloc_buf"
version = "0.0.6" version = "0.0.6"
@ -2460,6 +2476,15 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "num_threads"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "objc" name = "objc"
version = "0.2.7" version = "0.2.7"
@ -2499,6 +2524,18 @@ dependencies = [
"objc", "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]] [[package]]
name = "object" name = "object"
version = "0.28.4" version = "0.28.4"
@ -3733,10 +3770,12 @@ dependencies = [
"bumpalo", "bumpalo",
"clap 3.2.8", "clap 3.2.8",
"iced-x86", "iced-x86",
"mach_object",
"memmap2 0.5.4", "memmap2 0.5.4",
"object 0.29.0", "object 0.26.2",
"roc_build", "roc_build",
"roc_collections", "roc_collections",
"roc_error_macros",
"roc_mono", "roc_mono",
"serde", "serde",
"target-lexicon", "target-lexicon",
@ -4852,11 +4891,23 @@ dependencies = [
"libc", "libc",
"standback", "standback",
"stdweb 0.4.20", "stdweb 0.4.20",
"time-macros", "time-macros 0.1.1",
"version_check", "version_check",
"winapi", "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]] [[package]]
name = "time-macros" name = "time-macros"
version = "0.1.1" version = "0.1.1"
@ -4867,6 +4918,12 @@ dependencies = [
"time-macros-impl", "time-macros-impl",
] ]
[[package]]
name = "time-macros"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792"
[[package]] [[package]]
name = "time-macros-impl" name = "time-macros-impl"
version = "0.1.2" version = "0.1.2"
@ -5478,7 +5535,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22dc83aadbdf97388de3211cb6f105374f245a3cf2a5c65a16776e7a087a8468" checksum = "22dc83aadbdf97388de3211cb6f105374f245a3cf2a5c65a16776e7a087a8468"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"time", "time 0.2.27",
"wasmer-types", "wasmer-types",
] ]

View file

@ -287,13 +287,7 @@ pub fn build_file<'a>(
let link_start = SystemTime::now(); let link_start = SystemTime::now();
let problems = match (linking_strategy, link_type) { let problems = match (linking_strategy, link_type) {
(LinkingStrategy::Surgical, _) => { (LinkingStrategy::Surgical, _) => {
roc_linker::link_preprocessed_host(target, &host_input_path, app_o_file, &binary_path) 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
);
})?;
problems problems
} }
(LinkingStrategy::Additive, _) | (LinkingStrategy::Legacy, LinkType::None) => { (LinkingStrategy::Additive, _) | (LinkingStrategy::Legacy, LinkType::None) => {
@ -399,8 +393,7 @@ fn spawn_rebuild_thread(
exported_symbols, exported_symbols,
exported_closure_types, exported_closure_types,
target_valgrind, target_valgrind,
) );
.unwrap();
} }
LinkingStrategy::Legacy => { LinkingStrategy::Legacy => {
rebuild_host( rebuild_host(

View file

@ -488,7 +488,7 @@ pub fn build(
let linking_strategy = if wasm_dev_backend { let linking_strategy = if wasm_dev_backend {
LinkingStrategy::Additive 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") || matches.value_of(FLAG_LINKER) == Some("legacy")
{ {
LinkingStrategy::Legacy LinkingStrategy::Legacy

View file

@ -11,21 +11,17 @@ description = "A surgical linker for Roc"
name = "roc_linker" name = "roc_linker"
path = "src/lib.rs" path = "src/lib.rs"
[[bin]]
name = "link"
path = "src/main.rs"
test = false
bench = false
[dependencies] [dependencies]
roc_mono = { path = "../compiler/mono" } roc_mono = { path = "../compiler/mono" }
roc_build = { path = "../compiler/build" } roc_build = { path = "../compiler/build" }
roc_collections = { path = "../compiler/collections" } roc_collections = { path = "../compiler/collections" }
roc_error_macros = { path = "../error_macros" }
bumpalo = { version = "3.8.0", features = ["collections"] } bumpalo = { version = "3.8.0", features = ["collections"] }
clap = { version = "3.1.15", default-features = false, features = ["std", "color", "suggestions"] } 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"] } iced-x86 = { version = "1.15.0", default-features = false, features = ["std", "decoder", "op_code_info", "instr_info"] }
memmap2 = "0.5.3" 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"] } serde = { version = "1.0.130", features = ["derive"] }
bincode = "1.3.3" bincode = "1.3.3"
target-lexicon = "0.12.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). - 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. - 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 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. 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. Roc, for reference, adds 13MB (20%) when linked without garbage collection.
- Add a feature to the compiler to make this linker optional. - 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 dynamic_symbol_table_section_offset: u64,
pub symbol_table_section_offset: u64, pub symbol_table_section_offset: u64,
pub symbol_table_size: u64, pub symbol_table_size: u64,
pub macho_cmd_loc: u64,
} }