mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-26 22:05:14 +00:00
Merge pull request #435 from bjorn3/write_dylib_metadata
Read and write dylib metadata
This commit is contained in:
commit
db851945ea
119
Cargo.lock
generated
119
Cargo.lock
generated
@ -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"
|
||||
@ -161,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)",
|
||||
"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)",
|
||||
@ -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"
|
||||
@ -247,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#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)",
|
||||
@ -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"
|
||||
@ -318,6 +355,16 @@ dependencies = [
|
||||
"scroll 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "goblin"
|
||||
version = "0.0.22"
|
||||
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)",
|
||||
"scroll 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.1"
|
||||
@ -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,24 @@ name = "numtoa"
|
||||
version = "0.1.0"
|
||||
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 (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)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parity-wasm"
|
||||
version = "0.38.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "plain"
|
||||
version = "0.2.3"
|
||||
@ -593,10 +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 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"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 (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)",
|
||||
]
|
||||
@ -803,6 +897,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 +944,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 +954,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,17 +970,21 @@ dependencies = [
|
||||
"checksum cranelift-module 0.30.0 (git+https://github.com/CraneStation/cranelift.git)" = "<none>"
|
||||
"checksum cranelift-native 0.30.0 (git+https://github.com/CraneStation/cranelift.git)" = "<none>"
|
||||
"checksum cranelift-simplejit 0.30.0 (git+https://github.com/CraneStation/cranelift.git)" = "<none>"
|
||||
"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"
|
||||
"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)" = "<none>"
|
||||
"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)" = "<none>"
|
||||
"checksum goblin 0.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "6a4013e9182f2345c6b7829b9ef6e670bce0dfca12c6f974457ed2160c2c7fe9"
|
||||
"checksum goblin 0.0.22 (git+https://github.com/m4b/goblin?rev=f34cf128fb4d1f3c93e5cf129cf673c9d787217b)" = "<none>"
|
||||
"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"
|
||||
@ -889,8 +994,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.12.0 (git+https://github.com/gimli-rs/object.git)" = "<none>"
|
||||
"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"
|
||||
@ -940,6 +1050,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"
|
||||
|
@ -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.12.0"
|
||||
|
||||
# Uncomment to use local checkout of cranelift
|
||||
#[patch."https://github.com/CraneStation/cranelift.git"]
|
||||
@ -39,5 +40,9 @@ indexmap = "1.0.2"
|
||||
[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" }
|
||||
object = { git = "https://github.com/gimli-rs/object.git" }
|
||||
|
||||
[profile.dev.overrides."*"]
|
||||
opt-level = 3
|
||||
|
@ -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
|
||||
|
@ -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(())
|
||||
|
@ -98,7 +98,7 @@ fn run_jit<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, log: &mut Option<File>) ->
|
||||
fn run_aot<'a, 'tcx: 'a>(
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
metadata: EncodedMetadata,
|
||||
_need_metadata_module: bool,
|
||||
need_metadata_module: bool,
|
||||
log: &mut Option<File>,
|
||||
) -> Box<CodegenResults> {
|
||||
let new_module = |name: String| {
|
||||
@ -166,6 +166,37 @@ 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 = if need_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();
|
||||
|
||||
Some(CompiledModule {
|
||||
name: metadata_cgu_name,
|
||||
kind: ModuleKind::Metadata,
|
||||
object: Some(tmp_file),
|
||||
bytecode: None,
|
||||
bytecode_compressed: None,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Box::new(CodegenResults {
|
||||
crate_name: tcx.crate_name(LOCAL_CRATE),
|
||||
modules: vec![emit_module(
|
||||
@ -184,13 +215,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,
|
||||
crate_hash: tcx.crate_hash(LOCAL_CRATE),
|
||||
metadata,
|
||||
windows_subsystem: None, // Windows is not yet supported
|
||||
|
@ -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;
|
||||
|
@ -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<owning_ref::ErasedBoxRef<[u8]>, String> {
|
||||
let mut archive = ar::Archive::new(File::open(path).map_err(|e| format!("{:?}", e))?);
|
||||
@ -31,9 +35,72 @@ impl MetadataLoader for CraneliftMetadataLoader {
|
||||
|
||||
fn get_dylib_metadata(
|
||||
&self,
|
||||
_target: &crate::rustc_target::spec::Target,
|
||||
_path: &Path,
|
||||
_target: &Target,
|
||||
path: &Path,
|
||||
) -> Result<owning_ref::ErasedBoxRef<[u8]>, 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<Vec<u8>, [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(".rustc", faerie::Decl::section(faerie::SectionKind::Data)).unwrap();
|
||||
artifact.define_with_symbols(".rustc", compressed, {
|
||||
let mut map = std::collections::BTreeMap::new();
|
||||
// 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();
|
||||
|
||||
metadata
|
||||
}
|
||||
|
2
test.sh
2
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
|
||||
|
Loading…
Reference in New Issue
Block a user