Skip to content
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

Fix CG_CLIF_JIT_ARGS on Linux, macOS and Windows #1048

Open
bjorn3 opened this issue Jun 20, 2020 · 6 comments
Open

Fix CG_CLIF_JIT_ARGS on Linux, macOS and Windows #1048

bjorn3 opened this issue Jun 20, 2020 · 6 comments
Labels
A-jit Area: JIT compilation C-bug Category: This is a bug. O-linux Operating system: Linux O-macos Operating system: MacOS O-windows Operating system: Windows

Comments

@bjorn3
Copy link
Member

bjorn3 commented Jun 20, 2020

On Linux since 5c6bf83, the arguments passed to libstd by glibc when dlopening it are used, which are the arguments of the rustc process, not those in CG_CLIF_JIT_ARGS.

@bjorn3 bjorn3 added C-bug Category: This is a bug. O-linux Operating system: Linux labels Jun 20, 2020
@bjorn3
Copy link
Member Author

bjorn3 commented Jun 20, 2020

The same problem seems to exist on macOS and Windows. On macOS libstd uses _NSGetArgv. On Windows libstd uses GetCommandLineW.

@bjorn3 bjorn3 added O-macos Operating system: MacOS O-windows Operating system: Windows labels Jun 20, 2020
@bjorn3 bjorn3 changed the title Fix CG_CLIF_JIT_ARGS on Linux Fix CG_CLIF_JIT_ARGS on Linux, macOS and Windows Jun 20, 2020
@bjorn3 bjorn3 added the A-jit Area: JIT compilation label Mar 31, 2021
@workingjubilee
Copy link
Member

Hrm, can you explain this issue in more detail?

@bjorn3
Copy link
Member Author

bjorn3 commented Apr 27, 2024

When in JIT mode, the CG_CLIF_JIT_ARGS env var is used to specify which arguments to pass to the main function of the jitted program. On most targets this will be reflected in the std::env::args() of the jitted program, however on Linux + glibc, macOS and Windows, libstd instead directly requests the arguments from the OS/libc, thus causing the arguments passed to rustc to be returned by std::env::args() instead. One potential fix would be to always respect the arguments passed to main and only request them from the OS/libc as fallback. This would result in slightly bigger programs however.

@workingjubilee
Copy link
Member

Ah, thank you!

Yes, it will result in slightly bigger programs, but I think it is fine.

The test case then would be running rustc with the cranelift backend enabled and CG_CLIF_JIT_ARGS set and then checking if the return of std::env::args() has the desired args, or if it has the ones passed to rustc, yes?

@bjorn3
Copy link
Member Author

bjorn3 commented Apr 27, 2024

Correct, that would be how to test it.

@bjorn3
Copy link
Member Author

bjorn3 commented May 3, 2024

So, it turns out a couple of years ago in e86b954 I changed the jit code to intentionally skip over the libstd start function to fix #1151. I pushed a couple of fixes in c41a7db...4d6ac05, but have kept skipping the libstd start function. In any case I can confirm it works now with glibc if I stop skipping the libstd start function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-jit Area: JIT compilation C-bug Category: This is a bug. O-linux Operating system: Linux O-macos Operating system: MacOS O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

2 participants