Skip to content
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

k256 does not compile without allocator #1057

Closed
StackOverflowExcept1on opened this issue Jun 21, 2024 · 5 comments
Closed

k256 does not compile without allocator #1057

StackOverflowExcept1on opened this issue Jun 21, 2024 · 5 comments

Comments

@StackOverflowExcept1on
Copy link

error: no global memory allocator found but one is required; link to std or add `#[global_allocator]` to a static item that implements the GlobalAlloc trait

error: could not compile `app` (bin "app") due to 1 previous error
[package]
name = "app"
version = "0.1.0"
edition = "2021"

[dependencies]
k256 = { version = "0.14.0-pre.0", default-features = false, features = ["arithmetic"] }
libc = { version = "0.2.155", default-features = false }
rand_core = { version = "0.6.4", default-features = false, features = ["getrandom"] }

[profile.dev]
panic = "abort"

[profile.release]
opt-level = "z"
lto = true
codegen-units = 1
panic = "abort"
strip = true
#![no_std]
#![no_main]

extern crate libc;

use k256::SecretKey;
use rand_core::OsRng;

#[no_mangle]
extern "C" fn main() -> i32 {
    if f().to_bytes()[0] == 0xff {
        1
    } else {
        0
    }
}

#[no_mangle]
#[inline(never)]
pub fn f() -> SecretKey {
    SecretKey::random(&mut OsRng)
}

#[panic_handler]
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
    loop {}
}
@tarcieri
Copy link
Member

You didn't mention what target you're using and are pulling in superfluous dependencies. Can you pull in just k256 and its transitive dependencies? (e.g. no rand_core)

Which crate are you speculating is actually linking liballoc?

@tarcieri
Copy link
Member

I reproduced this without the superfluous dependencies. Wonder if it's related to precomputation /cc @fjarri

@StackOverflowExcept1on
Copy link
Author

You didn't mention what target you're using

rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7

@StackOverflowExcept1on
Copy link
Author

This is might be related to zeroize feature "alloc"

├── hybrid-array feature "default"
│   └── hybrid-array v0.2.0-rc.8
│       ├── typenum feature "const-generics"
│       │   └── typenum v1.17.0
│       ├── typenum feature "default"
│       │   └── typenum v1.17.0
│       └── zeroize feature "default"
│           ├── zeroize v1.8.1
│           └── zeroize feature "alloc"
│               └── zeroize v1.8.1

@tarcieri
Copy link
Member

tarcieri commented Jun 21, 2024

Aah, good catch

Edit: opened RustCrypto/hybrid-array#76

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants