Skip to content

Lint unsupported, target-specifc codegen flags #957

@wesleywiser

Description

@wesleywiser

Proposal

Some rustc codegen flags are target specific (or specific to families of targets) and have no effect when used on unsupported targets. For example:

  • -C control-flow-guard - Only supported on Windows targets
  • -C dlltool - Only used on *-windows-gnu targets
  • -C dwarf-version - Has no effect on *-windows-msvc targets
  • -C relro-level - Has no effect on *-windows-msvc targets

The question of "what should a codegen flag do on unsupported targets" has previously come up during stabilization of some codegen flags.

I propose that we add a lint which fires when a codegen flag is passed to the compiler which is ignored for the active target:

$ rustc -C dlltool=something.exe -C control-flow-guard=on --target x86_64-unknown-linux-gnu hello_world.rs
warning: `-C dlltool` has no effect on the target platform
warning: `-C control-flow-guard` has no effect on the target platform

The lint should default to the warn level but users can choose to deny or allow it via -D or -A flags respectively. Ideally the lint would only flag attempts to activate unsupported options as to avoid unnecessary diagnostic noise (eg rustc -C control-flow-guard=off --target x86_64-unknown-linux-gnu ... would not trigger the lint).

Mentors or Reviewers

I'm willing to mentor or implement the proposal.

Process

The main points of the Major Change Process are as follows:

  • File an issue describing the proposal.
  • A compiler team member who is knowledgeable in the area can second by writing @rustbot second or kickoff a team FCP with @rfcbot fcp $RESOLUTION.
  • Once an MCP is seconded, the Final Comment Period begins.
    • Final Comment Period lasts for 10 days after all outstanding concerns are solved.
    • Outstanding concerns will block the Final Comment Period from finishing. Once all concerns are resolved, the 10 day countdown is restarted.
    • If no concerns are raised after 10 days since the resolution of the last outstanding concern, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerAdd this label so rfcbot knows to poll the compiler teamfinal-comment-periodThe FCP has started, most (if not all) team members are in agreementmajor-changeA proposal to make a major change to rustcto-announceAnnounce this issue on triage meeting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions