Skip to content

Commit

Permalink
Unrolled build for rust-lang#124447
Browse files Browse the repository at this point in the history
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``
  • Loading branch information
rust-timer committed Apr 28, 2024
2 parents aed2187 + fa73ebb commit c8d7b07
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions library/std/src/sys/pal/unix/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,10 @@ mod imp {
}

#[inline(always)]
pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
// On Linux-GNU, we rely on `ARGV_INIT_ARRAY` below to initialize
// `ARGC` and `ARGV`. But in Miri that does not actually happen so we
// still initialize here.
#[cfg(any(miri, not(all(target_os = "linux", target_env = "gnu"))))]
really_init(_argc, _argv);
pub unsafe fn init(argc: isize, argv: *const *const u8) {
// on GNU/Linux if we are main then we will init argv and argc twice, it "duplicates work"
// BUT edge-cases are real: only using .init_array can break most emulators, dlopen, etc.
really_init(argc, argv);
}

/// glibc passes argc, argv, and envp to functions in .init_array, as a non-standard extension.
Expand Down

0 comments on commit c8d7b07

Please sign in to comment.