Skip to content

Emit a warning when gold is used as the linker #141748

Closed
@Noratrieb

Description

@Noratrieb

ld.gold is officially deprecated and doesn't seem entirely work properly for Rust: #139425

Once rustc starts emitting SHF_GNU_RETAIN sections for #[used] (#140872), it will get even worse, as gold miscompiles SHF_GNU_RETAIN (it doesn't just ignore it, it breaks the program in other ways).

It may be possible for rustc to detect usage of gold an emit an appropriate warning, telling the user to switch to a different linker like BFD or LLD instead.

@bjorn3 suggested looking at .comment after linking in #139425 (comment). From local testing, it looks like gold only adds this if you pass --enable-linker-version, which cc doesn't seem to pass by default.

But it looks like gold always emits a note, .note.gnu.gold-version/NT_GNU_GOLD_VERSION, which seems like a reliable way to detect gold.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-linkersArea: linkers... you gotta love linkersC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions