Giter VIP home page Giter VIP logo

Comments (13)

bjorn3 avatar bjorn3 commented on September 24, 2024 1

We should probably just unconditionally call really_init.

That would fix rust-lang/rustc_codegen_cranelift#1048 on Linux + glibc too.

from rust.

workingjubilee avatar workingjubilee commented on September 24, 2024

uh.

from rust.

workingjubilee avatar workingjubilee commented on September 24, 2024

@rjsberry Could you clarify: Does this problem arise with code ran on an ordinary gnu system? Say, a Debian container? Or x86_64-unknown-linux-musl itself?

from rust.

ChrisDenton avatar ChrisDenton commented on September 24, 2024

I can take a guess at why this happens. For glibc targets we assume that the arguments can be retrieved without needing to store argc and argv. However if this musl compatibility layer doesn't use the .init_array then we can't retrieve them.

from rust.

workingjubilee avatar workingjubilee commented on September 24, 2024

Ah yeah, it seems that behavior is a GNU extension that Rich Felker doesn't want to support?

from rust.

workingjubilee avatar workingjubilee commented on September 24, 2024

Does env::args() just not work at all on musl if we're a cdylib, then?

from rust.

bjorn3 avatar bjorn3 commented on September 24, 2024

Correct. When libstd's start function isn't used, env::args() only works on Windows, macOS and Linux with Glibc. On any other target it returns an empty list.

from rust.

workingjubilee avatar workingjubilee commented on September 24, 2024

Apparently we already have this comment:

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);
}

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 really_init.

from rust.

ChrisDenton avatar ChrisDenton commented on September 24, 2024

Note that this was intentionally done #66547 but there have been other issues #105999

from rust.

workingjubilee avatar workingjubilee commented on September 24, 2024

@ChrisDenton I still think we can consider #105999 to still be fixed, as we just get our char **argv and it will be the same thing, even if the char*s behind the char** have been rearranged, right? So we'll set the atomics twice to the same value, which sounds very Working As Intended.

from rust.

workingjubilee avatar workingjubilee commented on September 24, 2024

One other thought: if we initialize arguments this way, we don't also need to initialize them in our main function in binaries. Can you compile out that code on linux-gnu?

@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.

from rust.

ChrisDenton avatar ChrisDenton commented on September 24, 2024

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.

from rust.

workingjubilee avatar workingjubilee commented on September 24, 2024

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?

from rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.