-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
std::env::args_os always returns an empty iterator in a musl+gcompat environment #124126
Comments
uh. |
@rjsberry Could you clarify: Does this problem arise with code ran on an ordinary gnu system? Say, a Debian container? Or |
I can take a guess at why this happens. For glibc targets we assume that the arguments can be retrieved without needing to store |
Ah yeah, it seems that behavior is a GNU extension that Rich Felker doesn't want to support? |
Does |
Correct. When libstd's start function isn't used, |
Apparently we already have this comment: rust/library/std/src/sys/pal/unix/args.rs Lines 101 to 107 in 07d0d7c
In other words, we are already hacking around this issue for the miri emulator, and not using the fact that we are still given argv "naturally" via execve. We should probably just unconditionally call |
That would fix rust-lang/rustc_codegen_cranelift#1048 on Linux + glibc too. |
@ChrisDenton I still think we can consider #105999 to still be fixed, as we just get our |
— @joshtriplett in #66547 (review) Well, given the remarks here seem to position this as a "wouldn't it be nice if we didn't do extra work?" and that this seems to be non-resilient in practice, as it has caused more than one open issue, I think we should be unafraid of doing a bit of extra computation. |
I more meant that the fact that libraries mess about with (what should be) immutable memory is a safety issue so ideally we would parse it at the point where it's least likely that the are multiple threads. But people would probably complain about doing unnecessary allocating and extra work pre-main. Just storing argc and argv should be cheap though so I'm definitely not arguing against that. |
the dilemma: strictly conforming posix programs shouldn't mutate argc and argv, but strictly conforming posix programs also shouldn't be aware of argc and argv if if they're dylibs, eh? |
…nu, r=ChrisDenton Unconditionally call `really_init` on GNU/Linux This makes miri not diverge in behavior, it fixes running Rust linux-gnu binaries on musl with gcompat, it fixes dlopen edge-cases that cranelift somehow hits, etc. Fixes rust-lang#124126 thou hast gazed into this abyss with me: r? `@ChrisDenton`
Rollup merge of rust-lang#124447 - workingjubilee:set-argv-twice-on-gnu, r=ChrisDenton Unconditionally call `really_init` on GNU/Linux This makes miri not diverge in behavior, it fixes running Rust linux-gnu binaries on musl with gcompat, it fixes dlopen edge-cases that cranelift somehow hits, etc. Fixes rust-lang#124126 thou hast gazed into this abyss with me: r? ``@ChrisDenton``
Could we check, first, whether we've already had these initialized, and only call this in the unusual case where they're not initialized? That would avoid the extra work in the common case, and do the work in the unusual case. |
@joshtriplett I don't know what you mean? We aren't doing substantial extra work. The thing that costs the most in runtime startup, I expect, is having the static initializer at all, which we then don't get to make choices about whether its called. It simply is or isn't. |
@workingjubilee Nevermind: #124447 (comment) ; forgot that |
I tried this code in Alpine Linux cross compiled to
x86_64-unknown-linux-gnu
:For reference I ran this in a container on an M1 Macbook:
I always see
[]
printed, even when I pass the program arguments.I'm not sure this is an issue with the environment as the following C program works as expected:
Meta
rustc +nightly --version --verbose
:The text was updated successfully, but these errors were encountered: