-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #54265 - arielb1:civilize-proc-macros, r=alexcrichton
avoid leaking host details in proc macro metadata decoding proc macro crates are essentially implemented as dynamic libraries using a dlopen-based ABI. They are also Rust crates, so they have 2 worlds - the "host" world in which they are defined, and the "target" world in which they are used. For all the "target" world knows, the proc macro crate might not even be implemented in Rust, so leaks of details from the host to the target must be avoided for correctness. Because the "host" DefId space is different from the "target" DefId space, any leak involving a DefId will have a nonsensical or out-of-bounds DefKey, and will cause all sorts of crashes. This PR fixes all leaks I have found in `decoder`. In particular, #54059 was caused by host native libraries leaking into the target, which feels like it might even be a correctness issue if it doesn't cause an ICE. Fixes #54059
- Loading branch information
Showing
4 changed files
with
131 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// no-prefer-dynamic | ||
|
||
// check that having extern "C" functions in a proc macro doesn't crash. | ||
|
||
#![crate_type="proc-macro"] | ||
#![allow(non_snake_case)] | ||
|
||
extern crate proc_macro; | ||
|
||
macro_rules! proc_macro_tokenstream { | ||
() => { | ||
::proc_macro::TokenStream | ||
}; | ||
} | ||
|
||
macro_rules! proc_macro_expr_impl { | ||
($( | ||
$( #[$attr:meta] )* | ||
pub fn $func:ident($input:ident: &str) -> String $body:block | ||
)+) => { | ||
$( | ||
// Parses an input that looks like: | ||
// | ||
// ``` | ||
// #[allow(unused)] | ||
// enum ProcMacroHack { | ||
// Input = (stringify!(ARGS), 0).1, | ||
// } | ||
// ``` | ||
$( #[$attr] )* | ||
#[proc_macro_derive($func)] | ||
pub fn $func(input: proc_macro_tokenstream!()) -> proc_macro_tokenstream!() { | ||
unsafe { rust_dbg_extern_identity_u64(0); } | ||
panic!() | ||
} | ||
)+ | ||
}; | ||
} | ||
|
||
proc_macro_expr_impl! { | ||
pub fn base2_impl(input: &str) -> String { | ||
panic!() | ||
} | ||
} | ||
|
||
#[link(name="rust_test_helpers")] | ||
extern "C" { | ||
pub fn rust_dbg_extern_identity_u64(v: u64) -> u64; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// aux-build:issue_54059.rs | ||
// ignore-stage1 | ||
// ignore-wasm32-bare no libc for ffi testing | ||
// ignore-windows - dealing with weird symbols issues on dylibs isn't worth it | ||
// revisions: rpass1 | ||
|
||
extern crate issue_54059; | ||
|
||
fn main() {} |