Skip to content

Fix CG_CLIF_JIT_ARGS on Linux, macOS and Windows #1048

@bjorn3

Description

@bjorn3
Member

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.

Activity

added
C-bugCategory: This is a bug.
O-linuxOperating system: Linux
on Jun 20, 2020
bjorn3

bjorn3 commented on Jun 20, 2020

@bjorn3
MemberAuthor

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

changed the title [-]Fix CG_CLIF_JIT_ARGS on Linux[/-] [+]Fix CG_CLIF_JIT_ARGS on Linux, macOS and Windows[/+] on Jun 20, 2020
workingjubilee

workingjubilee commented on Apr 27, 2024

@workingjubilee
Member

Hrm, can you explain this issue in more detail?

bjorn3

bjorn3 commented on Apr 27, 2024

@bjorn3
MemberAuthor

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

workingjubilee commented on Apr 27, 2024

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

bjorn3 commented on Apr 27, 2024

@bjorn3
MemberAuthor

Correct, that would be how to test it.

bjorn3

bjorn3 commented on May 3, 2024

@bjorn3
MemberAuthor

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-jitArea: JIT compilationC-bugCategory: This is a bug.O-linuxOperating system: LinuxO-macosOperating system: MacOSO-windowsOperating system: Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bjorn3@workingjubilee

        Issue actions

          Fix CG_CLIF_JIT_ARGS on Linux, macOS and Windows · Issue #1048 · rust-lang/rustc_codegen_cranelift