Skip to content

C call Rust can not get arguments #118355

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

Closed
Sword-Destiny opened this issue Nov 27, 2023 · 5 comments
Closed

C call Rust can not get arguments #118355

Sword-Destiny opened this issue Nov 27, 2023 · 5 comments

Comments

@Sword-Destiny
Copy link
Contributor

I have a C program call Rust program by function execve("./rust_test", argv, env).
When I read argv in Rust main function by std::env::args(),

I get this message:

thread 'main' panicked at library/alloc/src/raw_vec.rs:534:5:
capacity overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

the target: cross compile aarch64-unknown-linux-gnu

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 27, 2023
@saethlin
Copy link
Member

Perhaps we can treat this as a bug if you provide a way to reproduce the problem. Can you provide enough code to observe the problem?

@saethlin saethlin added S-unactionable and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 28, 2023
@Sword-Destiny
Copy link
Contributor Author

Sword-Destiny commented Nov 28, 2023

Perhaps we can treat this as a bug if you provide a way to reproduce the problem. Can you provide enough code to observe the problem?

this error is caused by cross compile glibc and musl.
If compiled with aarch64-unknown-linux-gnu target and and Run on a musl-based embedded system, this panic will happen when calling std::env::args().collect(). Most of the interfaces is compatible between musl and gllibc, the command line arguments is one of the incompatible.

@bjorn3
Copy link
Member

bjorn3 commented Nov 28, 2023

If you link against musl, you have to use the aarch64-unknown-linux-musl target.

@Sword-Destiny
Copy link
Contributor Author

If you link against musl, you have to use the aarch64-unknown-linux-musl target.

I know this, but some problems here: #118400 , so I tried to use glibc, most of the programs work. I finally succeed to change to musl today.

@Sword-Destiny
Copy link
Contributor Author

closed

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

5 participants