Skip to content

Commit 3f7e297

Browse files
bors[bot]MabezDev
andauthored
Merge #91
91: Don't use a random hash ident, instead use the crate prefixed symbol r=almindor a=MabezDev This is what cortex-m land is doing. This was initially discovered to be an issue when implementing unwinding in riscv probe-rs, the dwarf info shows the hashed symbol name which is a bit weird, this makes it more clear what the symbol actually is. Co-authored-by: Scott Mabin <[email protected]>
2 parents 8bae02e + 5c8b061 commit 3f7e297

File tree

3 files changed

+3
-48
lines changed

3 files changed

+3
-48
lines changed

riscv-rt/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- Update `riscv` to version 0.8
1313
- Update Minimum Supported Rust Version to 1.59
14+
- The main symbol is no longer randomly generated in the `#[entry]` macro, instead it uses `__risc_v_rt__main`.
1415

1516
### Removed
1617

riscv-rt/macros/Cargo.toml

-5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,3 @@ proc-macro2 = "1.0"
2222
[dependencies.syn]
2323
version = "1.0"
2424
features = ["extra-traits", "full"]
25-
26-
[dependencies.rand]
27-
version = "0.7.3"
28-
default-features = false
29-
features = ["small_rng"]

riscv-rt/macros/src/lib.rs

+2-43
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![deny(warnings)]
22

33
extern crate proc_macro;
4-
extern crate rand;
54
#[macro_use]
65
extern crate quote;
76
extern crate core;
@@ -10,13 +9,7 @@ extern crate proc_macro2;
109
extern crate syn;
1110

1211
use proc_macro2::Span;
13-
use rand::Rng;
14-
use rand::SeedableRng;
15-
use std::sync::atomic::{AtomicUsize, Ordering};
16-
use std::time::{SystemTime, UNIX_EPOCH};
17-
use syn::{parse, spanned::Spanned, Ident, ItemFn, ReturnType, Type, Visibility};
18-
19-
static CALL_COUNT: AtomicUsize = AtomicUsize::new(0);
12+
use syn::{parse, spanned::Spanned, ItemFn, ReturnType, Type, Visibility};
2013

2114
use proc_macro::TokenStream;
2215

@@ -90,13 +83,12 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
9083
// XXX should we blacklist other attributes?
9184
let attrs = f.attrs;
9285
let unsafety = f.sig.unsafety;
93-
let hash = random_ident();
9486
let stmts = f.block.stmts;
9587

9688
quote!(
9789
#[export_name = "main"]
9890
#(#attrs)*
99-
pub #unsafety fn #hash() -> ! {
91+
pub #unsafety fn __risc_v_rt__main() -> ! {
10092
#(#stmts)*
10193
}
10294
)
@@ -176,36 +168,3 @@ pub fn pre_init(args: TokenStream, input: TokenStream) -> TokenStream {
176168
)
177169
.into()
178170
}
179-
180-
// Creates a random identifier
181-
fn random_ident() -> Ident {
182-
let secs = SystemTime::now()
183-
.duration_since(UNIX_EPOCH)
184-
.unwrap()
185-
.as_secs();
186-
187-
let count: u64 = CALL_COUNT.fetch_add(1, Ordering::SeqCst) as u64;
188-
let mut seed: [u8; 16] = [0; 16];
189-
190-
for (i, v) in seed.iter_mut().take(8).enumerate() {
191-
*v = ((secs >> (i * 8)) & 0xFF) as u8
192-
}
193-
194-
for (i, v) in seed.iter_mut().skip(8).enumerate() {
195-
*v = ((count >> (i * 8)) & 0xFF) as u8
196-
}
197-
198-
let mut rng = rand::rngs::SmallRng::from_seed(seed);
199-
Ident::new(
200-
&(0..16)
201-
.map(|i| {
202-
if i == 0 || rng.gen() {
203-
('a' as u8 + rng.gen::<u8>() % 25) as char
204-
} else {
205-
('0' as u8 + rng.gen::<u8>() % 10) as char
206-
}
207-
})
208-
.collect::<String>(),
209-
Span::call_site(),
210-
)
211-
}

0 commit comments

Comments
 (0)