aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock47
-rw-r--r--crates/proc_macro_srv/Cargo.toml2
-rw-r--r--crates/proc_macro_srv/src/dylib.rs65
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"
500checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce" 500checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce"
501 501
502[[package]] 502[[package]]
503name = "goblin"
504version = "0.2.3"
505source = "registry+https://github.com/rust-lang/crates.io-index"
506checksum = "d20fd25aa456527ce4f544271ae4fea65d2eda4a6561ea56f39fb3ee4f7e3884"
507dependencies = [
508 "log",
509 "plain",
510 "scroll",
511]
512
513[[package]]
514name = "hashbrown" 503name = "hashbrown"
515version = "0.9.1" 504version = "0.9.1"
516source = "registry+https://github.com/rust-lang/crates.io-index" 505source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1055,6 +1044,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1055checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" 1044checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397"
1056 1045
1057[[package]] 1046[[package]]
1047name = "object"
1048version = "0.23.0"
1049source = "registry+https://github.com/rust-lang/crates.io-index"
1050checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4"
1051
1052[[package]]
1058name = "once_cell" 1053name = "once_cell"
1059version = "1.5.2" 1054version = "1.5.2"
1060source = "registry+https://github.com/rust-lang/crates.io-index" 1055source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1159,12 +1154,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1159checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c" 1154checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c"
1160 1155
1161[[package]] 1156[[package]]
1162name = "plain"
1163version = "0.2.3"
1164source = "registry+https://github.com/rust-lang/crates.io-index"
1165checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
1166
1167[[package]]
1168name = "proc-macro2" 1157name = "proc-macro2"
1169version = "1.0.24" 1158version = "1.0.24"
1170source = "registry+https://github.com/rust-lang/crates.io-index" 1159source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1192,10 +1181,10 @@ version = "0.0.0"
1192dependencies = [ 1181dependencies = [
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"
1472checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" 1461checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
1473 1462
1474[[package]] 1463[[package]]
1475name = "scroll"
1476version = "0.10.2"
1477source = "registry+https://github.com/rust-lang/crates.io-index"
1478checksum = "fda28d4b4830b807a8b43f7b0e6b5df875311b3e7621d84577188c175b6ec1ec"
1479dependencies = [
1480 "scroll_derive",
1481]
1482
1483[[package]]
1484name = "scroll_derive"
1485version = "0.10.4"
1486source = "registry+https://github.com/rust-lang/crates.io-index"
1487checksum = "b12bd20b94c7cdfda8c7ba9b92ad0d9a56e3fa018c25fca83b51aa664c9b4c0d"
1488dependencies = [
1489 "proc-macro2",
1490 "quote",
1491 "syn",
1492]
1493
1494[[package]]
1495name = "semver" 1464name = "semver"
1496version = "0.9.0" 1465version = "0.9.0"
1497source = "registry+https://github.com/rust-lang/crates.io-index" 1466source = "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"
10doctest = false 10doctest = false
11 11
12[dependencies] 12[dependencies]
13goblin = "0.2.1" 13object = { version = "0.23", default-features = false, features = ["std", "read_core", "elf", "macho", "pe", "unaligned"] }
14libloading = "0.6.0" 14libloading = "0.6.0"
15memmap = "0.7" 15memmap = "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
3use crate::{proc_macro::bridge, rustc_server::TokenStream}; 3use std::{
4use std::fs::File; 4 fs::File,
5use std::path::{Path, PathBuf}; 5 io,
6 path::{Path, PathBuf},
7};
6 8
7use goblin::{mach::Mach, Object};
8use libloading::Library; 9use libloading::Library;
9use memmap::Mmap; 10use memmap::Mmap;
11use object::Object;
10use proc_macro_api::ProcMacroKind; 12use proc_macro_api::ProcMacroKind;
11use std::io; 13
14use crate::{proc_macro::bridge, rustc_server::TokenStream};
12 15
13const NEW_REGISTRAR_SYMBOL: &str = "_rustc_proc_macro_decls_"; 16const NEW_REGISTRAR_SYMBOL: &str = "_rustc_proc_macro_decls_";
14 17
@@ -23,40 +26,26 @@ fn is_derive_registrar_symbol(symbol: &str) -> bool {
23fn find_registrar_symbol(file: &Path) -> io::Result<Option<String>> { 26fn 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.