From e8c50cf2c2d1716fad0397ded02ac58f42ec9172 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 27 Mar 2019 19:24:42 +0100 Subject: [PATCH 01/10] Read and write dylib metadata --- Cargo.lock | 113 ++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/driver.rs | 37 +++++++++++++--- src/lib.rs | 1 + src/metadata.rs | 71 +++++++++++++++++++++++++++--- test.sh | 2 +- 6 files changed, 210 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 58d253edc..939741d72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,10 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "adler32" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "aho-corasick" version = "0.7.3" @@ -73,6 +78,11 @@ name = "bitflags" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "build_const" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "byteorder" version = "1.3.2" @@ -213,6 +223,22 @@ dependencies = [ "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crc" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crc32fast" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "env_logger" version = "0.6.1" @@ -286,6 +312,17 @@ name = "fallible-iterator" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "flate2" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -308,6 +345,16 @@ dependencies = [ "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "goblin" +version = "0.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "scroll 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "goblin" version = "0.0.21" @@ -375,6 +422,34 @@ name = "memchr" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "miniz-sys" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "miniz_oxide" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "miniz_oxide_c_api" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "nodrop" version = "0.1.13" @@ -385,6 +460,26 @@ name = "numtoa" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "object" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "goblin 0.0.19 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-wasm 0.35.7 (registry+https://github.com/rust-lang/crates.io-index)", + "scroll 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "parity-wasm" +version = "0.35.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "plain" version = "0.2.3" @@ -597,6 +692,7 @@ dependencies = [ "gimli 0.18.0 (git+https://github.com/gimli-rs/gimli.git)", "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "object 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -803,6 +899,11 @@ name = "utf8-ranges" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "uuid" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "vec_map" version = "0.8.1" @@ -845,6 +946,7 @@ dependencies = [ ] [metadata] +"checksum adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c" "checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum ar 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6c1afd66a96a235fa8eeec0ee757ec0d2c0db7cb89b4e04ae159f37952b97bd5" @@ -854,6 +956,7 @@ dependencies = [ "checksum backtrace 0.3.30 (registry+https://github.com/rust-lang/crates.io-index)" = "ada4c783bb7e7443c14e0480f429ae2cc99da95065aeab7ee1b81ada0419404f" "checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" "checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" +"checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" "checksum cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)" = "39f75544d7bbaf57560d2168f28fd649ff9c76153874db88bdbdfd839b1a7e7d" "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" @@ -869,6 +972,8 @@ dependencies = [ "checksum cranelift-module 0.30.0 (git+https://github.com/CraneStation/cranelift.git)" = "" "checksum cranelift-native 0.30.0 (git+https://github.com/CraneStation/cranelift.git)" = "" "checksum cranelift-simplejit 0.30.0 (git+https://github.com/CraneStation/cranelift.git)" = "" +"checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" +"checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" "checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a" "checksum errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2a071601ed01b988f896ab14b95e67335d1eeb50190932a1320f7fe3cadc84e" "checksum errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" @@ -876,9 +981,11 @@ dependencies = [ "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum fallible-iterator 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" +"checksum flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f87e68aa82b2de08a6e037f1385455759df6e445a8df5e005b4297191dbf18aa" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum gimli 0.18.0 (git+https://github.com/gimli-rs/gimli.git)" = "" +"checksum goblin 0.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "c65cd533b33e3d04c6e393225fa8919ddfcf5862ca8919c7f9a167c312ef41c2" "checksum goblin 0.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "6a4013e9182f2345c6b7829b9ef6e670bce0dfca12c6f974457ed2160c2c7fe9" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" @@ -889,8 +996,13 @@ dependencies = [ "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum mach 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "86dd2487cdfea56def77b88438a2c915fb45113c5319bfe7e14306ca4cd0b0e1" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" +"checksum miniz-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0300eafb20369952951699b68243ab4334f4b10a88f411c221d444b36c40e649" +"checksum miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c468f2369f07d651a5d0bb2c9079f8488a66d5466efe42d0c5c6466edcb7f71e" +"checksum miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b7fe927a42e3807ef71defb191dc87d4e24479b221e67015fe38ae2b7b447bab" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" +"checksum object 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e7934267669d9b8637926ed243df1b917b40e43dd070aea2a178296e6ed1b72" +"checksum parity-wasm 0.35.7 (registry+https://github.com/rust-lang/crates.io-index)" = "3e1e076c4e01399b6cd0793a8df42f90bba3ae424671ef421d1608a943155d93" "checksum plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" @@ -940,6 +1052,7 @@ dependencies = [ "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum utf8-ranges 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9d50aa7650df78abf942826607c62468ce18d9019673d4a2ebe1865dbb96ffde" +"checksum uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "90dbc611eb48397705a6b0f6e917da23ae517e4d127123d2cf7674206627d32a" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" diff --git a/Cargo.toml b/Cargo.toml index b60411311..31897eaea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ libc = "0.2.53" tempfile = "3.0.7" gimli = { git = "https://github.com/gimli-rs/gimli.git" } indexmap = "1.0.2" +object = "0.11.0" # Uncomment to use local checkout of cranelift #[patch."https://github.com/CraneStation/cranelift.git"] diff --git a/src/driver.rs b/src/driver.rs index c975f7755..a9cf054e0 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -166,6 +166,35 @@ fn run_aot<'a, 'tcx: 'a>( rustc_incremental::save_dep_graph(tcx); rustc_incremental::finalize_session_directory(tcx.sess, tcx.crate_hash(LOCAL_CRATE)); + let metadata_module = { + use rustc::mir::mono::CodegenUnitNameBuilder; + + let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx); + let metadata_cgu_name = cgu_name_builder + .build_cgu_name(LOCAL_CRATE, &["crate"], Some("metadata")) + .as_str() + .to_string(); + + let mut metadata_artifact = + faerie::Artifact::new(crate::build_isa(tcx.sess).triple().clone(), metadata_cgu_name.clone()); + crate::metadata::write_metadata(tcx, &mut metadata_artifact); + + let tmp_file = tcx + .output_filenames(LOCAL_CRATE) + .temp_path(OutputType::Metadata, Some(&metadata_cgu_name)); + + let obj = metadata_artifact.emit().unwrap(); + std::fs::write(&tmp_file, obj).unwrap(); + + CompiledModule { + name: metadata_cgu_name, + kind: ModuleKind::Metadata, + object: Some(tmp_file), + bytecode: None, + bytecode_compressed: None, + } + }; + Box::new(CodegenResults { crate_name: tcx.crate_name(LOCAL_CRATE), modules: vec![emit_module( @@ -184,13 +213,7 @@ fn run_aot<'a, 'tcx: 'a>( } else { None }, - metadata_module: Some(CompiledModule { - name: "dummy_metadata".to_string(), - kind: ModuleKind::Metadata, - object: None, - bytecode: None, - bytecode_compressed: None, - }), + metadata_module: Some(metadata_module), crate_hash: tcx.crate_hash(LOCAL_CRATE), metadata, windows_subsystem: None, // Windows is not yet supported diff --git a/src/lib.rs b/src/lib.rs index a2435312f..be46d638b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ #![feature(rustc_private, never_type, decl_macro)] #![allow(intra_doc_link_resolution_failure)] +extern crate flate2; extern crate rustc; extern crate rustc_allocator; extern crate rustc_codegen_ssa; diff --git a/src/metadata.rs b/src/metadata.rs index d7fd026df..1cc33df9e 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -1,16 +1,20 @@ -use rustc::middle::cstore::MetadataLoader; +use std::fs::File; +use std::path::Path; + +use rustc::session::config; +use rustc::ty::TyCtxt; +use rustc::middle::cstore::{EncodedMetadata, MetadataLoader}; use rustc_codegen_ssa::METADATA_FILENAME; use rustc_data_structures::owning_ref::{self, OwningRef}; use rustc_data_structures::rustc_erase_owner; -use std::fs::File; -use std::path::Path; +use rustc_target::spec::Target; pub struct CraneliftMetadataLoader; impl MetadataLoader for CraneliftMetadataLoader { fn get_rlib_metadata( &self, - _target: &crate::rustc_target::spec::Target, + _target: &Target, path: &Path, ) -> Result, String> { let mut archive = ar::Archive::new(File::open(path).map_err(|e| format!("{:?}", e))?); @@ -31,9 +35,62 @@ impl MetadataLoader for CraneliftMetadataLoader { fn get_dylib_metadata( &self, - _target: &crate::rustc_target::spec::Target, - _path: &Path, + _target: &Target, + path: &Path, ) -> Result, String> { - Err("dylib metadata loading is not yet supported".to_string()) + use object::Object; + let file = std::fs::read(path).map_err(|e| format!("read:{:?}", e))?; + let file = object::File::parse(&file).map_err(|e| format!("parse: {:?}", e))?; + let buf = file.section_data_by_name(".rustc").ok_or("no .rustc section")?.into_owned(); + let buf: OwningRef, [u8]> = OwningRef::new(buf).into(); + Ok(rustc_erase_owner!(buf.map_owner_box())) } } + +// Adapted from https://github.com/rust-lang/rust/blob/da573206f87b5510de4b0ee1a9c044127e409bd3/src/librustc_codegen_llvm/base.rs#L47-L112 +pub fn write_metadata<'a, 'gcx>( + tcx: TyCtxt<'a, 'gcx, 'gcx>, + artifact: &mut faerie::Artifact +) -> EncodedMetadata { + use std::io::Write; + use flate2::Compression; + use flate2::write::DeflateEncoder; + + #[derive(PartialEq, Eq, PartialOrd, Ord)] + enum MetadataKind { + None, + Uncompressed, + Compressed + } + + let kind = tcx.sess.crate_types.borrow().iter().map(|ty| { + match *ty { + config::CrateType::Executable | + config::CrateType::Staticlib | + config::CrateType::Cdylib => MetadataKind::None, + + config::CrateType::Rlib => MetadataKind::Uncompressed, + + config::CrateType::Dylib | + config::CrateType::ProcMacro => MetadataKind::Compressed, + } + }).max().unwrap_or(MetadataKind::None); + + if kind == MetadataKind::None { + return EncodedMetadata::new(); + } + + let metadata = tcx.encode_metadata(); + if kind == MetadataKind::Uncompressed { + return metadata; + } + + assert!(kind == MetadataKind::Compressed); + let mut compressed = tcx.metadata_encoding_version(); + DeflateEncoder::new(&mut compressed, Compression::fast()) + .write_all(&metadata.raw_data).unwrap(); + + artifact.declare_with(".rustc", faerie::Decl::debug_section(), compressed).unwrap(); + + metadata +} diff --git a/test.sh b/test.sh index 6be002a9c..1dfbf9247 100755 --- a/test.sh +++ b/test.sh @@ -5,7 +5,7 @@ rm -r target/out || true mkdir -p target/out/clif echo "[BUILD] mini_core" -$RUSTC example/mini_core.rs --crate-name mini_core --crate-type lib +$RUSTC example/mini_core.rs --crate-name mini_core --crate-type dylib echo "[BUILD] example" $RUSTC example/example.rs --crate-type lib From 8dae241368caa365df4321d0af6c3f1d760a4a5a Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 28 Mar 2019 20:54:44 +0100 Subject: [PATCH 02/10] [WIP] Use correct segment for metadata section --- Cargo.lock | 8 ++++---- Cargo.toml | 3 +++ src/debuginfo.rs | 2 +- src/metadata.rs | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 939741d72..613f5a73a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -171,7 +171,7 @@ source = "git+https://github.com/CraneStation/cranelift.git#f3f7cadd0157d06089c9 dependencies = [ "cranelift-codegen 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", "cranelift-module 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", - "faerie 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "faerie 0.10.0 (git+https://github.com/m4b/faerie.git?rev=dcb671a99faa32b72fac88d2406e952a41844636)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "goblin 0.0.21 (registry+https://github.com/rust-lang/crates.io-index)", "target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -273,7 +273,7 @@ dependencies = [ [[package]] name = "faerie" version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/m4b/faerie.git?rev=dcb671a99faa32b72fac88d2406e952a41844636#dcb671a99faa32b72fac88d2406e952a41844636" dependencies = [ "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -688,7 +688,7 @@ dependencies = [ "cranelift-faerie 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", "cranelift-module 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", "cranelift-simplejit 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", - "faerie 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "faerie 0.10.0 (git+https://github.com/m4b/faerie.git?rev=dcb671a99faa32b72fac88d2406e952a41844636)", "gimli 0.18.0 (git+https://github.com/gimli-rs/gimli.git)", "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", @@ -977,7 +977,7 @@ dependencies = [ "checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a" "checksum errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2a071601ed01b988f896ab14b95e67335d1eeb50190932a1320f7fe3cadc84e" "checksum errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" -"checksum faerie 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c6d75e6376216d6228fbab8025087523666623d9302ff17dd023d024bf98302" +"checksum faerie 0.10.0 (git+https://github.com/m4b/faerie.git?rev=dcb671a99faa32b72fac88d2406e952a41844636)" = "" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum fallible-iterator 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" diff --git a/Cargo.toml b/Cargo.toml index 31897eaea..164e6503a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,5 +40,8 @@ object = "0.11.0" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] cranelift-simplejit = { git = "https://github.com/CraneStation/cranelift.git" } +[patch.crates-io] +faerie = { git = "https://github.com/m4b/faerie.git", rev = "dcb671a99faa32b72fac88d2406e952a41844636" } + [profile.dev.overrides."*"] opt-level = 3 diff --git a/src/debuginfo.rs b/src/debuginfo.rs index 3afdaf8d9..0e9846807 100644 --- a/src/debuginfo.rs +++ b/src/debuginfo.rs @@ -191,7 +191,7 @@ impl<'a, 'tcx: 'a> DebugContext<'tcx> { let _: Result<()> = sections.for_each_mut(|id, section| { if !section.writer.slice().is_empty() { artifact - .declare_with(id.name(), Decl::debug_section(), section.writer.take()) + .declare_with(id.name(), Decl::section(SectionKind::Debug), section.writer.take()) .unwrap(); } Ok(()) diff --git a/src/metadata.rs b/src/metadata.rs index 1cc33df9e..23cf7a692 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -90,7 +90,7 @@ pub fn write_metadata<'a, 'gcx>( DeflateEncoder::new(&mut compressed, Compression::fast()) .write_all(&metadata.raw_data).unwrap(); - artifact.declare_with(".rustc", faerie::Decl::debug_section(), compressed).unwrap(); + artifact.declare_with(".rustc", faerie::Decl::section(faerie::SectionKind::Data), compressed).unwrap(); metadata } From 1bea823069d5a56e560500e25f2f2d0a0cd23ece Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 29 Mar 2019 19:25:14 +0100 Subject: [PATCH 03/10] [DEBUG] Add objdump invocation --- test.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test.sh b/test.sh index 1dfbf9247..602cdc50b 100755 --- a/test.sh +++ b/test.sh @@ -7,6 +7,8 @@ mkdir -p target/out/clif echo "[BUILD] mini_core" $RUSTC example/mini_core.rs --crate-name mini_core --crate-type dylib +objdump -section-headers target/out/libmini_core.dylib + echo "[BUILD] example" $RUSTC example/example.rs --crate-type lib From 805e270910f892780b06f36f6c4a8bfd29474876 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 4 Apr 2019 20:42:50 +0200 Subject: [PATCH 04/10] [WIP] --- ar_test.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 ar_test.rs diff --git a/ar_test.rs b/ar_test.rs new file mode 100644 index 000000000..567b2f04d --- /dev/null +++ b/ar_test.rs @@ -0,0 +1,45 @@ +//! ```cargo +//! [dependencies] +//! ar = "0.6.2" +//! ``` + +use std::io::Read; + +// 64 gives Invalid file size field in entry header +// 32 gives unexpected EOF in the middle of archive entry header +const METADATA_LEN: usize = 64; + +fn main() { + let mut builder = ar::Builder::new(std::fs::File::create("test.a").expect("create")); + + // Remove this append and there is no problem. + let header = ar::Header::new(b"core-fc675.rcgu.o".to_vec(), 0); + // Remove any of the characters in the filename and ! from will show up in the error message. + // Making it shorter than 17 chars will fix the problem though. + + builder.append(&header, &mut (&[] as &[u8])).expect("add rcgu"); + + let mut buf: Vec = vec!['!' as u8; 28]; + buf.extend(b"hello worl"); + buf.extend(&['*' as u8; 26] as &[u8]); + assert!(buf.len() >= METADATA_LEN); + + let header = ar::Header::new(b"rust.metadata.bin".to_vec(), METADATA_LEN as u64); + builder.append(&header, &mut (&buf[0..METADATA_LEN])).expect("add meta"); + + std::mem::drop(builder); + + // Remove this ranlib invocation and there is no problem. + /*assert!( + std::process::Command::new("ranlib") + .arg("test.a") + .status() + .expect("Couldn't run ranlib") + .success() + );*/ + + let mut archive = ar::Archive::new(std::fs::File::open("test.a").expect("open")); + while let Some(entry) = archive.next_entry() { + entry.unwrap(); + } +} From 847a37fedc5463bdae4e5bcc2eb2bbcf08c196a6 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 4 May 2019 15:26:26 +0200 Subject: [PATCH 05/10] Only write metadata module when necessary --- src/driver.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index a9cf054e0..391154f80 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -98,7 +98,7 @@ fn run_jit<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, log: &mut Option) -> fn run_aot<'a, 'tcx: 'a>( tcx: TyCtxt<'a, 'tcx, 'tcx>, metadata: EncodedMetadata, - _need_metadata_module: bool, + need_metadata_module: bool, log: &mut Option, ) -> Box { let new_module = |name: String| { @@ -166,7 +166,7 @@ fn run_aot<'a, 'tcx: 'a>( rustc_incremental::save_dep_graph(tcx); rustc_incremental::finalize_session_directory(tcx.sess, tcx.crate_hash(LOCAL_CRATE)); - let metadata_module = { + let metadata_module = if need_metadata_module { use rustc::mir::mono::CodegenUnitNameBuilder; let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx); @@ -186,13 +186,15 @@ fn run_aot<'a, 'tcx: 'a>( let obj = metadata_artifact.emit().unwrap(); std::fs::write(&tmp_file, obj).unwrap(); - CompiledModule { + Some(CompiledModule { name: metadata_cgu_name, kind: ModuleKind::Metadata, object: Some(tmp_file), bytecode: None, bytecode_compressed: None, - } + }) + } else { + None }; Box::new(CodegenResults { @@ -213,7 +215,7 @@ fn run_aot<'a, 'tcx: 'a>( } else { None }, - metadata_module: Some(metadata_module), + metadata_module, crate_hash: tcx.crate_hash(LOCAL_CRATE), metadata, windows_subsystem: None, // Windows is not yet supported From 4ade7463332ddd5b30872cb824d738112f197b61 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 26 May 2019 10:02:32 +0200 Subject: [PATCH 06/10] [WIP] Add section symbol for mach-O --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 613f5a73a..2e105bb2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -171,7 +171,7 @@ source = "git+https://github.com/CraneStation/cranelift.git#f3f7cadd0157d06089c9 dependencies = [ "cranelift-codegen 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", "cranelift-module 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", - "faerie 0.10.0 (git+https://github.com/m4b/faerie.git?rev=dcb671a99faa32b72fac88d2406e952a41844636)", + "faerie 0.10.0 (git+https://github.com/bjorn3/faerie.git?branch=macho_section_symbols)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "goblin 0.0.21 (registry+https://github.com/rust-lang/crates.io-index)", "target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -273,7 +273,7 @@ dependencies = [ [[package]] name = "faerie" version = "0.10.0" -source = "git+https://github.com/m4b/faerie.git?rev=dcb671a99faa32b72fac88d2406e952a41844636#dcb671a99faa32b72fac88d2406e952a41844636" +source = "git+https://github.com/bjorn3/faerie.git?branch=macho_section_symbols#c08282ee1296abda4f815d5ef8582fc7785b0b3b" dependencies = [ "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -688,7 +688,7 @@ dependencies = [ "cranelift-faerie 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", "cranelift-module 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", "cranelift-simplejit 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", - "faerie 0.10.0 (git+https://github.com/m4b/faerie.git?rev=dcb671a99faa32b72fac88d2406e952a41844636)", + "faerie 0.10.0 (git+https://github.com/bjorn3/faerie.git?branch=macho_section_symbols)", "gimli 0.18.0 (git+https://github.com/gimli-rs/gimli.git)", "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", @@ -977,7 +977,7 @@ dependencies = [ "checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a" "checksum errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2a071601ed01b988f896ab14b95e67335d1eeb50190932a1320f7fe3cadc84e" "checksum errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" -"checksum faerie 0.10.0 (git+https://github.com/m4b/faerie.git?rev=dcb671a99faa32b72fac88d2406e952a41844636)" = "" +"checksum faerie 0.10.0 (git+https://github.com/bjorn3/faerie.git?branch=macho_section_symbols)" = "" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum fallible-iterator 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" diff --git a/Cargo.toml b/Cargo.toml index 164e6503a..9f8e302c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ object = "0.11.0" cranelift-simplejit = { git = "https://github.com/CraneStation/cranelift.git" } [patch.crates-io] -faerie = { git = "https://github.com/m4b/faerie.git", rev = "dcb671a99faa32b72fac88d2406e952a41844636" } +faerie = { git = "https://github.com/bjorn3/faerie.git", branch = "macho_section_symbols" } [profile.dev.overrides."*"] opt-level = 3 From 893945bd717659bdd3ad2de601b87c49851d80e2 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 31 May 2019 12:35:04 +0200 Subject: [PATCH 07/10] Update for faerie section symbols --- config.sh | 2 +- src/metadata.rs | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/config.sh b/config.sh index 5dca77855..7fbd41128 100644 --- a/config.sh +++ b/config.sh @@ -20,4 +20,4 @@ fi export RUSTFLAGS='-Zalways-encode-mir -Cpanic=abort -Cdebuginfo=2 -Zcodegen-backend='$(pwd)'/target/'$channel'/librustc_codegen_cranelift.'$dylib_ext' --sysroot '$(pwd)'/build_sysroot/sysroot' RUSTC="rustc $RUSTFLAGS -L crate=target/out --out-dir target/out" -export RUST_LOG=warn # display metadata load errors +export RUSTC_LOG=warn # display metadata load errors diff --git a/src/metadata.rs b/src/metadata.rs index 23cf7a692..8abf0dcc1 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -90,7 +90,12 @@ pub fn write_metadata<'a, 'gcx>( DeflateEncoder::new(&mut compressed, Compression::fast()) .write_all(&metadata.raw_data).unwrap(); - artifact.declare_with(".rustc", faerie::Decl::section(faerie::SectionKind::Data), compressed).unwrap(); + artifact.declare(".rustc", faerie::Decl::section(faerie::SectionKind::Data)).unwrap(); + artifact.define_with_symbols(".rustc", compressed, { + let mut map = std::collections::BTreeMap::new(); + map.insert(rustc::middle::exported_symbols::metadata_symbol_name(tcx), 0); + map + }).unwrap(); metadata } From aa48c1482a75b12d25d156d732d8333312a6801f Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 2 Jun 2019 11:42:31 +0200 Subject: [PATCH 08/10] [WIP] --- Cargo.lock | 26 +++++++++++--------------- Cargo.toml | 5 +++-- test.sh | 2 +- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e105bb2f..dd3ef80c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -171,7 +171,7 @@ source = "git+https://github.com/CraneStation/cranelift.git#f3f7cadd0157d06089c9 dependencies = [ "cranelift-codegen 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", "cranelift-module 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", - "faerie 0.10.0 (git+https://github.com/bjorn3/faerie.git?branch=macho_section_symbols)", + "faerie 0.10.0", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "goblin 0.0.21 (registry+https://github.com/rust-lang/crates.io-index)", "target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -273,7 +273,6 @@ dependencies = [ [[package]] name = "faerie" version = "0.10.0" -source = "git+https://github.com/bjorn3/faerie.git?branch=macho_section_symbols#c08282ee1296abda4f815d5ef8582fc7785b0b3b" dependencies = [ "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -347,7 +346,7 @@ dependencies = [ [[package]] name = "goblin" -version = "0.0.19" +version = "0.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -357,7 +356,7 @@ dependencies = [ [[package]] name = "goblin" -version = "0.0.21" +version = "0.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -462,19 +461,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "object" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +version = "0.12.0" dependencies = [ "flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "goblin 0.0.19 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-wasm 0.35.7 (registry+https://github.com/rust-lang/crates.io-index)", + "goblin 0.0.22 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-wasm 0.38.0 (registry+https://github.com/rust-lang/crates.io-index)", "scroll 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "parity-wasm" -version = "0.35.7" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -688,11 +686,11 @@ dependencies = [ "cranelift-faerie 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", "cranelift-module 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", "cranelift-simplejit 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", - "faerie 0.10.0 (git+https://github.com/bjorn3/faerie.git?branch=macho_section_symbols)", + "faerie 0.10.0", "gimli 0.18.0 (git+https://github.com/gimli-rs/gimli.git)", "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "object 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "object 0.12.0", "target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -977,7 +975,6 @@ dependencies = [ "checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a" "checksum errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2a071601ed01b988f896ab14b95e67335d1eeb50190932a1320f7fe3cadc84e" "checksum errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" -"checksum faerie 0.10.0 (git+https://github.com/bjorn3/faerie.git?branch=macho_section_symbols)" = "" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum fallible-iterator 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" @@ -985,8 +982,8 @@ dependencies = [ "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum gimli 0.18.0 (git+https://github.com/gimli-rs/gimli.git)" = "" -"checksum goblin 0.0.19 (registry+https://github.com/rust-lang/crates.io-index)" = "c65cd533b33e3d04c6e393225fa8919ddfcf5862ca8919c7f9a167c312ef41c2" "checksum goblin 0.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "6a4013e9182f2345c6b7829b9ef6e670bce0dfca12c6f974457ed2160c2c7fe9" +"checksum goblin 0.0.22 (registry+https://github.com/rust-lang/crates.io-index)" = "7f55d53401eb2fd30afd025c570b1946b6966344acf21b42e31286f3bf89e6a8" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" "checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" @@ -1001,8 +998,7 @@ dependencies = [ "checksum miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b7fe927a42e3807ef71defb191dc87d4e24479b221e67015fe38ae2b7b447bab" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" -"checksum object 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2e7934267669d9b8637926ed243df1b917b40e43dd070aea2a178296e6ed1b72" -"checksum parity-wasm 0.35.7 (registry+https://github.com/rust-lang/crates.io-index)" = "3e1e076c4e01399b6cd0793a8df42f90bba3ae424671ef421d1608a943155d93" +"checksum parity-wasm 0.38.0 (registry+https://github.com/rust-lang/crates.io-index)" = "20d7e522a7f994cc4ae32970b1ce0d99ecf91b8e1df080517a26faa6d2e2ee62" "checksum plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" diff --git a/Cargo.toml b/Cargo.toml index 9f8e302c7..1b505f7e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ libc = "0.2.53" tempfile = "3.0.7" gimli = { git = "https://github.com/gimli-rs/gimli.git" } indexmap = "1.0.2" -object = "0.11.0" +object = "0.12.0" # Uncomment to use local checkout of cranelift #[patch."https://github.com/CraneStation/cranelift.git"] @@ -41,7 +41,8 @@ object = "0.11.0" cranelift-simplejit = { git = "https://github.com/CraneStation/cranelift.git" } [patch.crates-io] -faerie = { git = "https://github.com/bjorn3/faerie.git", branch = "macho_section_symbols" } +faerie = { path = "../faerie" } +object = { path = "../object" } [profile.dev.overrides."*"] opt-level = 3 diff --git a/test.sh b/test.sh index 602cdc50b..6573bdda6 100755 --- a/test.sh +++ b/test.sh @@ -5,7 +5,7 @@ rm -r target/out || true mkdir -p target/out/clif echo "[BUILD] mini_core" -$RUSTC example/mini_core.rs --crate-name mini_core --crate-type dylib +$RUSTC example/mini_core.rs --crate-name mini_core --crate-type dylib -Csave-temps objdump -section-headers target/out/libmini_core.dylib From 07bb89a02d37e2158023ebf4e23799e54c7c4f31 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 11 Jun 2019 16:57:59 +0200 Subject: [PATCH 09/10] Fix it --- Cargo.lock | 20 +++++++++++--------- Cargo.toml | 4 ++-- src/metadata.rs | 7 ++++++- test.sh | 2 -- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dd3ef80c1..ecd803172 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -171,7 +171,7 @@ source = "git+https://github.com/CraneStation/cranelift.git#f3f7cadd0157d06089c9 dependencies = [ "cranelift-codegen 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", "cranelift-module 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", - "faerie 0.10.0", + "faerie 0.10.0 (git+https://github.com/m4b/faerie.git)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "goblin 0.0.21 (registry+https://github.com/rust-lang/crates.io-index)", "target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -273,6 +273,7 @@ dependencies = [ [[package]] name = "faerie" version = "0.10.0" +source = "git+https://github.com/m4b/faerie.git#f6ce890950950d9ee85b7cb5de5fff9c9291f194" dependencies = [ "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -357,7 +358,7 @@ dependencies = [ [[package]] name = "goblin" version = "0.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/m4b/goblin?rev=f34cf128fb4d1f3c93e5cf129cf673c9d787217b#f34cf128fb4d1f3c93e5cf129cf673c9d787217b" dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -462,11 +463,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "object" version = "0.12.0" +source = "git+https://github.com/gimli-rs/object.git#aced06a20eb59867c88e23c03e15613ffd582618" dependencies = [ "flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", - "goblin 0.0.22 (registry+https://github.com/rust-lang/crates.io-index)", + "goblin 0.0.22 (git+https://github.com/m4b/goblin?rev=f34cf128fb4d1f3c93e5cf129cf673c9d787217b)", "parity-wasm 0.38.0 (registry+https://github.com/rust-lang/crates.io-index)", "scroll 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -474,9 +477,6 @@ dependencies = [ name = "parity-wasm" version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "plain" @@ -686,11 +686,11 @@ dependencies = [ "cranelift-faerie 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", "cranelift-module 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", "cranelift-simplejit 0.30.0 (git+https://github.com/CraneStation/cranelift.git)", - "faerie 0.10.0", + "faerie 0.10.0 (git+https://github.com/m4b/faerie.git)", "gimli 0.18.0 (git+https://github.com/gimli-rs/gimli.git)", "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", - "object 0.12.0", + "object 0.12.0 (git+https://github.com/gimli-rs/object.git)", "target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -975,6 +975,7 @@ dependencies = [ "checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a" "checksum errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2a071601ed01b988f896ab14b95e67335d1eeb50190932a1320f7fe3cadc84e" "checksum errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" +"checksum faerie 0.10.0 (git+https://github.com/m4b/faerie.git)" = "" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum fallible-iterator 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" @@ -983,7 +984,7 @@ dependencies = [ "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum gimli 0.18.0 (git+https://github.com/gimli-rs/gimli.git)" = "" "checksum goblin 0.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "6a4013e9182f2345c6b7829b9ef6e670bce0dfca12c6f974457ed2160c2c7fe9" -"checksum goblin 0.0.22 (registry+https://github.com/rust-lang/crates.io-index)" = "7f55d53401eb2fd30afd025c570b1946b6966344acf21b42e31286f3bf89e6a8" +"checksum goblin 0.0.22 (git+https://github.com/m4b/goblin?rev=f34cf128fb4d1f3c93e5cf129cf673c9d787217b)" = "" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" "checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" @@ -998,6 +999,7 @@ dependencies = [ "checksum miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b7fe927a42e3807ef71defb191dc87d4e24479b221e67015fe38ae2b7b447bab" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" +"checksum object 0.12.0 (git+https://github.com/gimli-rs/object.git)" = "" "checksum parity-wasm 0.38.0 (registry+https://github.com/rust-lang/crates.io-index)" = "20d7e522a7f994cc4ae32970b1ce0d99ecf91b8e1df080517a26faa6d2e2ee62" "checksum plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" diff --git a/Cargo.toml b/Cargo.toml index 1b505f7e6..59d66d07f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,8 +41,8 @@ object = "0.12.0" cranelift-simplejit = { git = "https://github.com/CraneStation/cranelift.git" } [patch.crates-io] -faerie = { path = "../faerie" } -object = { path = "../object" } +faerie = { git = "https://github.com/m4b/faerie.git" } +object = { git = "https://github.com/gimli-rs/object.git" } [profile.dev.overrides."*"] opt-level = 3 diff --git a/src/metadata.rs b/src/metadata.rs index 8abf0dcc1..56ce208a7 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -93,7 +93,12 @@ pub fn write_metadata<'a, 'gcx>( artifact.declare(".rustc", faerie::Decl::section(faerie::SectionKind::Data)).unwrap(); artifact.define_with_symbols(".rustc", compressed, { let mut map = std::collections::BTreeMap::new(); - map.insert(rustc::middle::exported_symbols::metadata_symbol_name(tcx), 0); + // FIXME implement faerie elf backend section custom symbols + // For MachO this is necessary to prevent the linker from throwing away the .rustc section, + // but for ELF it isn't. + if tcx.sess.target.target.options.is_like_osx { + map.insert(rustc::middle::exported_symbols::metadata_symbol_name(tcx), 0); + } map }).unwrap(); diff --git a/test.sh b/test.sh index 6573bdda6..20f4a6bd1 100755 --- a/test.sh +++ b/test.sh @@ -7,8 +7,6 @@ mkdir -p target/out/clif echo "[BUILD] mini_core" $RUSTC example/mini_core.rs --crate-name mini_core --crate-type dylib -Csave-temps -objdump -section-headers target/out/libmini_core.dylib - echo "[BUILD] example" $RUSTC example/example.rs --crate-type lib From 44a35507995b94751a4eaa58607b4a04a1310098 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 11 Jun 2019 16:59:42 +0200 Subject: [PATCH 10/10] Cleanup --- ar_test.rs | 45 --------------------------------------------- test.sh | 2 +- 2 files changed, 1 insertion(+), 46 deletions(-) delete mode 100644 ar_test.rs diff --git a/ar_test.rs b/ar_test.rs deleted file mode 100644 index 567b2f04d..000000000 --- a/ar_test.rs +++ /dev/null @@ -1,45 +0,0 @@ -//! ```cargo -//! [dependencies] -//! ar = "0.6.2" -//! ``` - -use std::io::Read; - -// 64 gives Invalid file size field in entry header -// 32 gives unexpected EOF in the middle of archive entry header -const METADATA_LEN: usize = 64; - -fn main() { - let mut builder = ar::Builder::new(std::fs::File::create("test.a").expect("create")); - - // Remove this append and there is no problem. - let header = ar::Header::new(b"core-fc675.rcgu.o".to_vec(), 0); - // Remove any of the characters in the filename and ! from will show up in the error message. - // Making it shorter than 17 chars will fix the problem though. - - builder.append(&header, &mut (&[] as &[u8])).expect("add rcgu"); - - let mut buf: Vec = vec!['!' as u8; 28]; - buf.extend(b"hello worl"); - buf.extend(&['*' as u8; 26] as &[u8]); - assert!(buf.len() >= METADATA_LEN); - - let header = ar::Header::new(b"rust.metadata.bin".to_vec(), METADATA_LEN as u64); - builder.append(&header, &mut (&buf[0..METADATA_LEN])).expect("add meta"); - - std::mem::drop(builder); - - // Remove this ranlib invocation and there is no problem. - /*assert!( - std::process::Command::new("ranlib") - .arg("test.a") - .status() - .expect("Couldn't run ranlib") - .success() - );*/ - - let mut archive = ar::Archive::new(std::fs::File::open("test.a").expect("open")); - while let Some(entry) = archive.next_entry() { - entry.unwrap(); - } -} diff --git a/test.sh b/test.sh index 20f4a6bd1..1dfbf9247 100755 --- a/test.sh +++ b/test.sh @@ -5,7 +5,7 @@ rm -r target/out || true mkdir -p target/out/clif echo "[BUILD] mini_core" -$RUSTC example/mini_core.rs --crate-name mini_core --crate-type dylib -Csave-temps +$RUSTC example/mini_core.rs --crate-name mini_core --crate-type dylib echo "[BUILD] example" $RUSTC example/example.rs --crate-type lib