-
Notifications
You must be signed in to change notification settings - Fork 281
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
missing symbols for no_std
target
#119
Comments
nostd implies no malloc/free, which we don't yet support. I believe there's some work upstream that will enable this eventually.
… On Jun 10, 2019, at 11:35, Wladimir J. van der Laan ***@***.***> wrote:
(looks like there's some overlap with #114)
I'm trying to build rust-secp256k1 for a bare-metal RISC-V platform, I've built and installed a compatible toolchain using crosstool-ng and do
CC="${HOME}/x-tools/riscv64-unknown-elf/bin/riscv64-unknown-elf-gcc" cargo build --release
However, I get the following missing symbol errors:
Compiling secp256k1-test v0.1.0 (/home/user/maixgo/k210-sdk-istuff/rust/secp256k1-test)
error: linking with `rust-lld` failed: exit code: 1
|
...
= note: rust-lld: error: undefined symbol: _impure_ptr
>>> referenced by reent.h:814 (/home/user/x-tools/riscv64-unknown-elf/riscv64-unknown-elf/sys-include/sys/reent.h:814)
>>> secp256k1.o:(default_error_callback_fn) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: fprintf
>>> referenced by secp256k1.c
>>> secp256k1.o:(default_error_callback_fn) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: _impure_ptr
>>> referenced by reent.h:814 (/home/user/x-tools/riscv64-unknown-elf/riscv64-unknown-elf/sys-include/sys/reent.h:814)
>>> secp256k1.o:(default_illegal_callback_fn) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: fprintf
>>> referenced by secp256k1.c
>>> secp256k1.o:(default_illegal_callback_fn) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: malloc
>>> referenced by secp256k1.c
>>> secp256k1.o:(secp256k1_ecmult_odd_multiples_table_storage_var.constprop.31) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: malloc
>>> referenced by secp256k1.c
>>> secp256k1.o:(secp256k1_ecmult_odd_multiples_table_storage_var.constprop.31) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: malloc
>>> referenced by secp256k1.c
>>> secp256k1.o:(secp256k1_ecmult_odd_multiples_table_storage_var.constprop.31) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: free
>>> referenced by secp256k1.c
>>> secp256k1.o:(secp256k1_ecmult_odd_multiples_table_storage_var.constprop.31) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: free
>>> referenced by secp256k1.c
>>> secp256k1.o:(secp256k1_ecmult_odd_multiples_table_storage_var.constprop.31) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: free
>>> referenced by secp256k1.c
>>> secp256k1.o:(secp256k1_ecmult_odd_multiples_table_storage_var.constprop.31) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: malloc
>>> referenced by secp256k1.c
>>> secp256k1.o:(secp256k1_ecmult_odd_multiples_table_storage_var.constprop.31) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: malloc
>>> referenced by secp256k1.c
>>> secp256k1.o:(secp256k1_ecmult_odd_multiples_table_storage_var.constprop.31) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: malloc
>>> referenced by secp256k1.c
>>> secp256k1.o:(secp256k1_ecmult_gen_context_build) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: malloc
>>> referenced by secp256k1.c
>>> secp256k1.o:(secp256k1_ecmult_gen_context_build) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: malloc
>>> referenced by secp256k1.c
>>> secp256k1.o:(secp256k1_ecmult_gen_context_build) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: free
>>> referenced by secp256k1.c
>>> secp256k1.o:(secp256k1_ecmult_gen_context_build) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: free
>>> referenced by secp256k1.c
>>> secp256k1.o:(secp256k1_ecmult_gen_context_build) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: malloc
>>> referenced by secp256k1.c
>>> secp256k1.o:(secp256k1_context_create) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: _impure_ptr
>>> referenced by reent.h:814 (/home/user/x-tools/riscv64-unknown-elf/riscv64-unknown-elf/sys-include/sys/reent.h:814)
>>> secp256k1.o:(secp256k1_context_create) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: undefined symbol: fprintf
>>> referenced by secp256k1.c
>>> secp256k1.o:(secp256k1_context_create) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
rust-lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
error: aborting due to previous error
error: Could not compile `secp256k1-test`.
To learn more, run the command again with --verbose.
So I guess the malloc/free is due to context allocation/deallocation and will be solved by updating the secp256k1 tree for bitcoin-core/secp256k1#566 bitcoin-core/secp256k1#614 etc.
THe _impure_ptr is more confusing to me.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Ah, right, you pointed that out. Indeed, should be resolveable, but may require a few more upstream tweaks.
… On Jun 10, 2019, at 12:19, Matt Corallo ***@***.***> wrote:
nostd implies no malloc/free, which we don't yet support. I believe there's some work upstream that will enable this eventually.
> On Jun 10, 2019, at 11:35, Wladimir J. van der Laan ***@***.***> wrote:
>
> (looks like there's some overlap with #114)
>
> I'm trying to build rust-secp256k1 for a bare-metal RISC-V platform, I've built and installed a compatible toolchain using crosstool-ng and do
>
> CC="${HOME}/x-tools/riscv64-unknown-elf/bin/riscv64-unknown-elf-gcc" cargo build --release
> However, I get the following missing symbol errors:
>
> Compiling secp256k1-test v0.1.0 (/home/user/maixgo/k210-sdk-istuff/rust/secp256k1-test)
> error: linking with `rust-lld` failed: exit code: 1
> |
> ...
> = note: rust-lld: error: undefined symbol: _impure_ptr
> >>> referenced by reent.h:814 (/home/user/x-tools/riscv64-unknown-elf/riscv64-unknown-elf/sys-include/sys/reent.h:814)
> >>> secp256k1.o:(default_error_callback_fn) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: fprintf
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(default_error_callback_fn) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: _impure_ptr
> >>> referenced by reent.h:814 (/home/user/x-tools/riscv64-unknown-elf/riscv64-unknown-elf/sys-include/sys/reent.h:814)
> >>> secp256k1.o:(default_illegal_callback_fn) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: fprintf
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(default_illegal_callback_fn) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: malloc
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(secp256k1_ecmult_odd_multiples_table_storage_var.constprop.31) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: malloc
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(secp256k1_ecmult_odd_multiples_table_storage_var.constprop.31) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: malloc
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(secp256k1_ecmult_odd_multiples_table_storage_var.constprop.31) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: free
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(secp256k1_ecmult_odd_multiples_table_storage_var.constprop.31) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: free
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(secp256k1_ecmult_odd_multiples_table_storage_var.constprop.31) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: free
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(secp256k1_ecmult_odd_multiples_table_storage_var.constprop.31) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: malloc
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(secp256k1_ecmult_odd_multiples_table_storage_var.constprop.31) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: malloc
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(secp256k1_ecmult_odd_multiples_table_storage_var.constprop.31) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: malloc
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(secp256k1_ecmult_gen_context_build) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: malloc
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(secp256k1_ecmult_gen_context_build) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: malloc
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(secp256k1_ecmult_gen_context_build) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: free
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(secp256k1_ecmult_gen_context_build) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: free
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(secp256k1_ecmult_gen_context_build) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: malloc
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(secp256k1_context_create) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: _impure_ptr
> >>> referenced by reent.h:814 (/home/user/x-tools/riscv64-unknown-elf/riscv64-unknown-elf/sys-include/sys/reent.h:814)
> >>> secp256k1.o:(secp256k1_context_create) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: undefined symbol: fprintf
> >>> referenced by secp256k1.c
> >>> secp256k1.o:(secp256k1_context_create) in archive /home/user/maixgo/k210-sdk-stuff/rust/target/riscv64gc-unknown-none-elf/release/deps/libsecp256k1-ad9949776962da29.rlib
>
> rust-lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
>
>
> error: aborting due to previous error
>
> error: Could not compile `secp256k1-test`.
>
> To learn more, run the command again with --verbose.
> So I guess the malloc/free is due to context allocation/deallocation and will be solved by updating the secp256k1 tree for bitcoin-core/secp256k1#566 bitcoin-core/secp256k1#614 etc.
> THe _impure_ptr is more confusing to me.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub, or mute the thread.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Trying to recreate this doesn't work well for me :/ |
Ok, I installed the riscv64 crostools and ran |
Very true! With malloc/free it works fine. I've run the secp256k1 tests on this device (except the ones that need >8MB memory) after compiling it using the C SDK, which has a tiny libc. However, the rust embedded environment doesn't have them. I know it's possible to define a custom allocator and heap on embedded ( I was confused because the crate advertises "makes no allocations (except in unit tests) for efficiency and use in freestanding implementations". But I understand this refers to the crate itself, not the code it embeds.
Sure, but the code doesn't do anything at all, it just imports #![allow(dead_code)]
#![allow(non_snake_case)]
#![allow(non_camel_case_types)]
#![no_std]
#![no_main]
use k210_hal::pac;
use k210_hal::prelude::*;
use k210_hal::stdout::Stdout;
use riscv_rt::entry;
use k210_shared::soc::sleep::usleep;
use secp256k1::{Secp256k1, Message, SecretKey, PublicKey};
#[entry]
fn main() -> ! {
let p = pac::Peripherals::take().unwrap();
let clocks = k210_hal::clock::Clocks::new();
usleep(200000);
// Configure UART
let serial = p.UARTHS.constrain(115_200.bps(), &clocks);
let (mut tx, _) = serial.split();
let mut stdout = Stdout(&mut tx);
writeln!(stdout, "testing").unwrap();
let secp = Secp256k1::new();
let secret_key = SecretKey::from_slice(&[0xcd; 32]).expect("32 bytes, within curve order");
let public_key = PublicKey::from_secret_key(&secp, &secret_key);
let message = Message::from_slice(&[0xab; 32]).expect("32 bytes");
let sig = secp.sign(&message, &secret_key);
assert!(secp.verify(&message, &sig, &public_key).is_ok());
loop {
}
}
Yes, you're right—the part that fails is linking the rust code to the C code, to create a binary image for uploading to the device. Compilation works fine. I'm going to try this. |
BTW if you build your rv64 toolchain with crosstool-ng, and want to be able to link against rust code, make sure that you set
As rust's linker only supports softfloat at this point, and I think the default for the architecture is hardfloat (rust-lang/rust#60012) |
If your tiny libc has Altough I see that the linker complained also about p.s. you can even implement your own |
Thanks! But I'd really, really prefer to not link against Kendryte's SDK, I just want to use secp256k1 in my rust-based firmware. (I've already reimplemented most of their peripheral access code in rust, it would be a shame to need to link against it just for memory allocation) But good point that I can just implement my own
👍 |
Should be fixed in 0.14.0. |
yes, thank you ! |
(looks like there's some overlap with #114)
I'm trying to build
rust-secp256k1
for a bare-metal RISC-V platform, I've built and installed a compatible toolchain using crosstool-ng and doCC="${HOME}/x-tools/riscv64-unknown-elf/bin/riscv64-unknown-elf-gcc" cargo build --release
However, I get the following missing symbol errors:
So I guess the malloc/free is due to context allocation/deallocation and will be solved by updating the secp256k1 tree for bitcoin-core/secp256k1#566 bitcoin-core/secp256k1#614 etc.
THe_impure_ptr
is more confusing to me.Edit: Ok, looks like
_impure_ptr
is related, looking at the disassembly it's always used to get to stderr, the first parameter offprintf
, usually invoked throughCHECK
.The text was updated successfully, but these errors were encountered: