Skip to content

Using a shebang-less script as a linker doesn't work anymore on Linux #101511

Description

@glandium

STR:

  • cargo new foo
  • cd foo
  • echo exit 42 > linker
  • chmod +x linker
  • RUSTFLAGS="-Clinker=$PWD/linker" cargo +nightly build

Actual result:

error: could not exec the linker `/tmp/foo/linker`
  |
  = note: Exec format error (os error 8)

With 1.63:

error: linking with `/tmp/foo/linker` failed: exit status: 42

This is a regression from #95026. What's going on is that before that merge, the linker was executed via posix_spawnp@GLIBC_2.2.5, and after, it's executed via posix_spawnp@GLIBC_2.15. The difference between the two is that the former retries executing through the shell when the execution first failed with ENOEXEC. This applies to anything the compiler or cargo would execute via std::process::Command. The change in posix_spawnp behavior in glibc comes from https://sourceware.org/bugzilla/show_bug.cgi?id=13134. It's probably for the better, but it should probably be highlighted in the release notes.

Activity

  1. added
    C-bugCategory: This is a bug.
    regression-untriagedUntriaged performance or correctness regression.
    on Sep 7, 2022
  2. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Sep 7, 2022
  3. Mark-Simulacrum commented on Sep 7, 2022

    @Mark-Simulacrum
    Member

    This would happen with anything using Command, right? Not just rustc/cargo.

  4. added
    T-libs-api[DEPRECATED; DO NOT USE]
    and removed
    regression-untriagedUntriaged performance or correctness regression.
    on Sep 7, 2022
  5. Mark-Simulacrum commented on Sep 7, 2022

    @Mark-Simulacrum
    Member

    Nominating for libs-api to consider whether we want to workaround this by implementing the re-execution ourselves; my feeling is no but it is a regression so I think worth asking.

  6. added this to the 1.64.0 milestone on Sep 7, 2022
  7. glandium commented on Sep 7, 2022

    @glandium
    ContributorAuthor

    It only happens when using libstd-*.so from the newer rustc builds, or when building with any rustc against an old glibc.

  8. glandium commented on Sep 7, 2022

    @glandium
    ContributorAuthor

    That is, if you build some random crate that uses Command with any version of rustc, the behavior depends on whether the libc used for the crate compile is < 2.15 or not, not whether rustc is 1.64 or not.

  9. glandium commented on Sep 7, 2022

    @glandium
    ContributorAuthor

    rustc 1.64 itself is affected by the change because it's built with a newer glibc, while older versions of rustc were built with an older glibc.

  10. glandium commented on Sep 7, 2022

    @glandium
    ContributorAuthor

    Note that it might be worth reviewing what other functions from glibc used by rustc/cargo have changed and how, because there might be subtle changes like this hidden somewhere.

  11. Mark-Simulacrum commented on Sep 7, 2022

    @Mark-Simulacrum
    Member

    Ah, that makes sense. It seems likely that folks might bump their build environments to a newer glibc since we only support newer ones now, so I think I'll still leave this nominated, but it's good if it affects few users in practice.

    T-compiler may want to do that checking as you suggest and consider a (temporary, perhaps with a future compat warning?) fallback, separately from any decisions by std.

  12. 10 remaining items

  13. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Dec 9, 2022
  14. added
    T-cargoRelevant to the cargo team, which will review and decide on the PR/issue.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    T-cargoRelevant to the cargo team, which will review and decide on the PR/issue.
    on Dec 14, 2022
  15. m-ou-se commented on Dec 14, 2022

    @m-ou-se
    Member

    Reassigning to the compiler team. We're not planning to change std::process::Command, but they might want to consider adding special handling in the compiler for this.

  16. joshtriplett commented on Dec 14, 2022

    @joshtriplett
    Member

    I don't think the compiler team should have a special case for this, unless there's some real-world use case that's affecting projects. @glandium, is there some case that's hitting the specific use case of a linker in practice, or is this a more theoretical concern or a concern about the behavior of Command in general?

  17. glandium commented on Dec 14, 2022

    @glandium
    ContributorAuthor

    I don't remember on what I hit this specifically, but I did hit it on some existing code that was using a linker wrapper without a shebang. I can tell for sure it was not Firefox. At the very least, the behavior change should be called out.

  18. apiraino commented on Dec 15, 2022

    @apiraino
    Contributor

    WG-prioritization assigning priority (Zulip discussion).

    Tagging for release notes, I feel the suggestion in the first comment makes sense.

    @rustbot label -I-prioritize +P-low +release-notes

  19. added
    P-lowLow priority
    relnotesMarks issues that should be documented in the release notes of the next release.
    and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Dec 15, 2022
  20. jieyouxu commented on May 2, 2025

    @jieyouxu
    Member

    Triage: I don't think the compiler will be adding any special cases for this, and it's long past the release that would've corresponded to the relnotes here.

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

    C-bugCategory: This is a bug.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.relnotesMarks issues that should be documented in the release notes of the next release.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions