diff options
-rw-r--r-- | Cargo.lock | 47 | ||||
-rw-r--r-- | crates/proc_macro_srv/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/proc_macro_srv/src/dylib.rs | 65 |
3 files changed, 36 insertions, 78 deletions
diff --git a/Cargo.lock b/Cargo.lock index 8cb5fd7ad..ec8ad11cb 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -89,7 +89,7 @@ dependencies = [ | |||
89 | "cfg-if 1.0.0", | 89 | "cfg-if 1.0.0", |
90 | "libc", | 90 | "libc", |
91 | "miniz_oxide", | 91 | "miniz_oxide", |
92 | "object", | 92 | "object 0.22.0", |
93 | "rustc-demangle", | 93 | "rustc-demangle", |
94 | ] | 94 | ] |
95 | 95 | ||
@@ -500,17 +500,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
500 | checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce" | 500 | checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce" |
501 | 501 | ||
502 | [[package]] | 502 | [[package]] |
503 | name = "goblin" | ||
504 | version = "0.2.3" | ||
505 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
506 | checksum = "d20fd25aa456527ce4f544271ae4fea65d2eda4a6561ea56f39fb3ee4f7e3884" | ||
507 | dependencies = [ | ||
508 | "log", | ||
509 | "plain", | ||
510 | "scroll", | ||
511 | ] | ||
512 | |||
513 | [[package]] | ||
514 | name = "hashbrown" | 503 | name = "hashbrown" |
515 | version = "0.9.1" | 504 | version = "0.9.1" |
516 | source = "registry+https://github.com/rust-lang/crates.io-index" | 505 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1055,6 +1044,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1055 | checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" | 1044 | checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" |
1056 | 1045 | ||
1057 | [[package]] | 1046 | [[package]] |
1047 | name = "object" | ||
1048 | version = "0.23.0" | ||
1049 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1050 | checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" | ||
1051 | |||
1052 | [[package]] | ||
1058 | name = "once_cell" | 1053 | name = "once_cell" |
1059 | version = "1.5.2" | 1054 | version = "1.5.2" |
1060 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1055 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1159,12 +1154,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1159 | checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c" | 1154 | checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c" |
1160 | 1155 | ||
1161 | [[package]] | 1156 | [[package]] |
1162 | name = "plain" | ||
1163 | version = "0.2.3" | ||
1164 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1165 | checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" | ||
1166 | |||
1167 | [[package]] | ||
1168 | name = "proc-macro2" | 1157 | name = "proc-macro2" |
1169 | version = "1.0.24" | 1158 | version = "1.0.24" |
1170 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1159 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1192,10 +1181,10 @@ version = "0.0.0" | |||
1192 | dependencies = [ | 1181 | dependencies = [ |
1193 | "cargo_metadata", | 1182 | "cargo_metadata", |
1194 | "difference", | 1183 | "difference", |
1195 | "goblin", | ||
1196 | "libloading", | 1184 | "libloading", |
1197 | "mbe", | 1185 | "mbe", |
1198 | "memmap", | 1186 | "memmap", |
1187 | "object 0.23.0", | ||
1199 | "proc_macro_api", | 1188 | "proc_macro_api", |
1200 | "proc_macro_test", | 1189 | "proc_macro_test", |
1201 | "serde_derive", | 1190 | "serde_derive", |
@@ -1472,26 +1461,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1472 | checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" | 1461 | checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" |
1473 | 1462 | ||
1474 | [[package]] | 1463 | [[package]] |
1475 | name = "scroll" | ||
1476 | version = "0.10.2" | ||
1477 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1478 | checksum = "fda28d4b4830b807a8b43f7b0e6b5df875311b3e7621d84577188c175b6ec1ec" | ||
1479 | dependencies = [ | ||
1480 | "scroll_derive", | ||
1481 | ] | ||
1482 | |||
1483 | [[package]] | ||
1484 | name = "scroll_derive" | ||
1485 | version = "0.10.4" | ||
1486 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1487 | checksum = "b12bd20b94c7cdfda8c7ba9b92ad0d9a56e3fa018c25fca83b51aa664c9b4c0d" | ||
1488 | dependencies = [ | ||
1489 | "proc-macro2", | ||
1490 | "quote", | ||
1491 | "syn", | ||
1492 | ] | ||
1493 | |||
1494 | [[package]] | ||
1495 | name = "semver" | 1464 | name = "semver" |
1496 | version = "0.9.0" | 1465 | version = "0.9.0" |
1497 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1466 | source = "registry+https://github.com/rust-lang/crates.io-index" |
diff --git a/crates/proc_macro_srv/Cargo.toml b/crates/proc_macro_srv/Cargo.toml index 729372968..1bfa6c3fc 100644 --- a/crates/proc_macro_srv/Cargo.toml +++ b/crates/proc_macro_srv/Cargo.toml | |||
@@ -10,7 +10,7 @@ edition = "2018" | |||
10 | doctest = false | 10 | doctest = false |
11 | 11 | ||
12 | [dependencies] | 12 | [dependencies] |
13 | goblin = "0.2.1" | 13 | object = { version = "0.23", default-features = false, features = ["std", "read_core", "elf", "macho", "pe", "unaligned"] } |
14 | libloading = "0.6.0" | 14 | libloading = "0.6.0" |
15 | memmap = "0.7" | 15 | memmap = "0.7" |
16 | 16 | ||
diff --git a/crates/proc_macro_srv/src/dylib.rs b/crates/proc_macro_srv/src/dylib.rs index f8f705da8..2afb973cc 100644 --- a/crates/proc_macro_srv/src/dylib.rs +++ b/crates/proc_macro_srv/src/dylib.rs | |||
@@ -1,14 +1,17 @@ | |||
1 | //! Handles dynamic library loading for proc macro | 1 | //! Handles dynamic library loading for proc macro |
2 | 2 | ||
3 | use crate::{proc_macro::bridge, rustc_server::TokenStream}; | 3 | use std::{ |
4 | use std::fs::File; | 4 | fs::File, |
5 | use std::path::{Path, PathBuf}; | 5 | io, |
6 | path::{Path, PathBuf}, | ||
7 | }; | ||
6 | 8 | ||
7 | use goblin::{mach::Mach, Object}; | ||
8 | use libloading::Library; | 9 | use libloading::Library; |
9 | use memmap::Mmap; | 10 | use memmap::Mmap; |
11 | use object::Object; | ||
10 | use proc_macro_api::ProcMacroKind; | 12 | use proc_macro_api::ProcMacroKind; |
11 | use std::io; | 13 | |
14 | use crate::{proc_macro::bridge, rustc_server::TokenStream}; | ||
12 | 15 | ||
13 | const NEW_REGISTRAR_SYMBOL: &str = "_rustc_proc_macro_decls_"; | 16 | const NEW_REGISTRAR_SYMBOL: &str = "_rustc_proc_macro_decls_"; |
14 | 17 | ||
@@ -23,40 +26,26 @@ fn is_derive_registrar_symbol(symbol: &str) -> bool { | |||
23 | fn find_registrar_symbol(file: &Path) -> io::Result<Option<String>> { | 26 | fn find_registrar_symbol(file: &Path) -> io::Result<Option<String>> { |
24 | let file = File::open(file)?; | 27 | let file = File::open(file)?; |
25 | let buffer = unsafe { Mmap::map(&file)? }; | 28 | let buffer = unsafe { Mmap::map(&file)? }; |
26 | let object = Object::parse(&buffer).map_err(invalid_data_err)?; | ||
27 | 29 | ||
28 | let name = match object { | 30 | Ok(object::File::parse(&buffer) |
29 | Object::Elf(elf) => { | 31 | .map_err(invalid_data_err)? |
30 | let symbols = elf.dynstrtab.to_vec().map_err(invalid_data_err)?; | 32 | .exports() |
31 | symbols.into_iter().find(|s| is_derive_registrar_symbol(s)).map(&str::to_owned) | 33 | .map_err(invalid_data_err)? |
32 | } | 34 | .into_iter() |
33 | Object::PE(pe) => pe | 35 | .map(|export| export.name()) |
34 | .exports | 36 | .filter_map(|sym| String::from_utf8(sym.into()).ok()) |
35 | .iter() | 37 | .find(|sym| is_derive_registrar_symbol(sym)) |
36 | .flat_map(|s| s.name) | 38 | .map(|sym| { |
37 | .find(|s| is_derive_registrar_symbol(s)) | 39 | // From MacOS docs: |
38 | .map(&str::to_owned), | 40 | // https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/dlsym.3.html |
39 | Object::Mach(Mach::Binary(binary)) => { | 41 | // Unlike other dyld API's, the symbol name passed to dlsym() must NOT be |
40 | let exports = binary.exports().map_err(invalid_data_err)?; | 42 | // prepended with an underscore. |
41 | exports | 43 | if cfg!(target_os = "macos") && sym.starts_with('_') { |
42 | .iter() | 44 | sym[1..].to_owned() |
43 | .map(|s| { | 45 | } else { |
44 | // In macos doc: | 46 | sym |
45 | // https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/dlsym.3.html | 47 | } |
46 | // Unlike other dyld API's, the symbol name passed to dlsym() must NOT be | 48 | })) |
47 | // prepended with an underscore. | ||
48 | if s.name.starts_with('_') { | ||
49 | &s.name[1..] | ||
50 | } else { | ||
51 | &s.name | ||
52 | } | ||
53 | }) | ||
54 | .find(|s| is_derive_registrar_symbol(s)) | ||
55 | .map(&str::to_owned) | ||
56 | } | ||
57 | _ => return Ok(None), | ||
58 | }; | ||
59 | return Ok(name); | ||
60 | } | 49 | } |
61 | 50 | ||
62 | /// Loads dynamic library in platform dependent manner. | 51 | /// Loads dynamic library in platform dependent manner. |