Skip to content

fix: Fix proc macro ABI version checks #10799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions crates/proc_macro_srv/src/abis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,26 @@ impl Abi {
symbol_name: String,
info: RustCInfo,
) -> Result<Abi, LoadProcMacroDylibError> {
if info.version.0 != 1 {
Err(LoadProcMacroDylibError::UnsupportedABI)
} else if info.version.1 < 47 {
Err(LoadProcMacroDylibError::UnsupportedABI)
} else if info.version.1 < 54 {
let inner = unsafe { Abi_1_47::from_lib(lib, symbol_name) }?;
Ok(Abi::Abi1_47(inner))
} else if info.version.1 < 56 {
let inner = unsafe { Abi_1_55::from_lib(lib, symbol_name) }?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Say the minor version is 55, then < 54 is false but < 56 is true, so it ends up at this line, using the 1.55 abi.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, let's say the minor is 54.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, then it still ends up using 1.55, so the old code is wrong. In any case your code is much clearer.

Ok(Abi::Abi1_55(inner))
} else if info.version.1 < 57 {
let inner = unsafe { Abi_1_56::from_lib(lib, symbol_name) }?;
Ok(Abi::Abi1_56(inner))
} else {
let inner = unsafe { Abi_1_58::from_lib(lib, symbol_name) }?;
Ok(Abi::Abi1_58(inner))
// FIXME: this should use exclusive ranges when they're stable
// https://github.com/rust-lang/rust/issues/37854
match (info.version.0, info.version.1) {
(1, 47..=54) => {
let inner = unsafe { Abi_1_47::from_lib(lib, symbol_name) }?;
Ok(Abi::Abi1_47(inner))
}
(1, 55..=55) => {
let inner = unsafe { Abi_1_55::from_lib(lib, symbol_name) }?;
Ok(Abi::Abi1_55(inner))
}
(1, 56..=57) => {
let inner = unsafe { Abi_1_56::from_lib(lib, symbol_name) }?;
Ok(Abi::Abi1_56(inner))
}
(1, 58..) => {
let inner = unsafe { Abi_1_58::from_lib(lib, symbol_name) }?;
Ok(Abi::Abi1_58(inner))
}
_ => Err(LoadProcMacroDylibError::UnsupportedABI),
}
}

Expand Down