Skip to content

Commit da34864

Browse files
authored
Fix deny(unused) of an unused import with SGX + Miri (#581)
The `deny(unused)` use that used to be here is incompatible with building this crate with Miri. The import in question is only used in a module that is only declared when we are not `cfg(miri)`. I tried to fix this by grouping items into modules so that I could apply `cfg(not(miri))` to all the SGX code. One could also make the build work by deleting the `#[deny(unused)]`, but that felt hacky.
1 parent 45bdb72 commit da34864

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

src/backtrace/libunwind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl Frame {
4949
// the address here, which could be later mapped to correct function.
5050
#[cfg(all(target_env = "sgx", target_vendor = "fortanix"))]
5151
{
52-
let image_base = super::get_image_base();
52+
let image_base = super::sgx_image_base::get_image_base();
5353
ip = usize::wrapping_sub(ip as usize, image_base as _) as _;
5454
}
5555
ip

src/backtrace/mod.rs

+37-27
Original file line numberDiff line numberDiff line change
@@ -125,39 +125,49 @@ impl fmt::Debug for Frame {
125125
}
126126
}
127127

128-
#[cfg(all(target_env = "sgx", target_vendor = "fortanix", not(feature = "std")))]
129-
mod sgx_no_std_image_base {
130-
use core::ffi::c_void;
131-
use core::sync::atomic::{AtomicUsize, Ordering::SeqCst};
132-
133-
static IMAGE_BASE: AtomicUsize = AtomicUsize::new(0);
134-
135-
/// Set the image base address. This is only available for Fortanix SGX
136-
/// target when the `std` feature is not enabled. This can be used in the
137-
/// standard library to set the correct base address.
138-
#[doc(hidden)]
139-
pub fn set_image_base(base_addr: *mut c_void) {
140-
IMAGE_BASE.store(base_addr as _, SeqCst);
128+
#[cfg(all(target_env = "sgx", target_vendor = "fortanix", not(miri)))]
129+
mod sgx_image_base {
130+
131+
#[cfg(not(feature = "std"))]
132+
pub(crate) mod imp {
133+
use core::ffi::c_void;
134+
use core::sync::atomic::{AtomicUsize, Ordering::SeqCst};
135+
136+
static IMAGE_BASE: AtomicUsize = AtomicUsize::new(0);
137+
138+
/// Set the image base address. This is only available for Fortanix SGX
139+
/// target when the `std` feature is not enabled. This can be used in the
140+
/// standard library to set the correct base address.
141+
#[doc(hidden)]
142+
pub fn set_image_base(base_addr: *mut c_void) {
143+
IMAGE_BASE.store(base_addr as _, SeqCst);
144+
}
145+
146+
pub(crate) fn get_image_base() -> *mut c_void {
147+
IMAGE_BASE.load(SeqCst) as _
148+
}
141149
}
142150

143-
pub(crate) fn get_image_base() -> *mut c_void {
144-
IMAGE_BASE.load(SeqCst) as _
145-
}
146-
}
147-
148-
#[cfg(all(target_env = "sgx", target_vendor = "fortanix", not(feature = "std")))]
149-
pub use self::sgx_no_std_image_base::set_image_base;
151+
#[cfg(feature = "std")]
152+
mod imp {
153+
use core::ffi::c_void;
150154

151-
#[cfg(all(target_env = "sgx", target_vendor = "fortanix", not(feature = "std")))]
152-
#[deny(unused)]
153-
pub(crate) use self::sgx_no_std_image_base::get_image_base;
155+
pub(crate) fn get_image_base() -> *mut c_void {
156+
std::os::fortanix_sgx::mem::image_base() as _
157+
}
158+
}
154159

155-
#[cfg(all(target_env = "sgx", target_vendor = "fortanix", feature = "std"))]
156-
#[deny(unused)]
157-
pub(crate) fn get_image_base() -> *mut c_void {
158-
std::os::fortanix_sgx::mem::image_base() as _
160+
pub(crate) use imp::get_image_base;
159161
}
160162

163+
#[cfg(all(
164+
target_env = "sgx",
165+
target_vendor = "fortanix",
166+
not(feature = "std"),
167+
not(miri)
168+
))]
169+
pub use sgx_image_base::imp::set_image_base;
170+
161171
cfg_if::cfg_if! {
162172
// This needs to come first, to ensure that
163173
// Miri takes priority over the host platform

0 commit comments

Comments
 (0)