Skip to content

Figure out which target features are required/incompatible for which ABI #131799

Open
1 of 2 issues completed
Open

Description

@RalfJung

View all comments

The context for this is #116344: some target features change the way floats are passed between functions. Changing those target features is unsound as code compiled for the same target may now use different ABIs.

In #134794, I am adding the infrastructure to have the compiler recognize this. But this infrastructure needs to be fed with information about which ABIs exist (e.g. softfloat/hardfloat), and which target features they require or are incompatible with. This will have to be done for each architecture we support.

Tier 3 only:

  • bpf
  • csky
  • hexagon
  • mips
  • m68k
  • sparc32
  • more?

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 16, 2024
  2. RalfJung commented on Oct 16, 2024

    @RalfJung
    MemberAuthor

    @rust-lang/wg-llvm @bjorn3 @chorman0773 if you happen to know anything that needs to be added to the list, please let me know, or edit the issue. :) I'm mostly focusing on float ABI here; if it turns out there's a ton of architecture-specific ABI-affecting non-float features we might want to split this up into float and non-float.

  3. changed the title [-]Figure out which target features affect ABI[/-] [+]Figure out which target features affect float ABI[/+] on Oct 16, 2024
  4. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-floating-pointArea: Floating point numbers and arithmetic
    A-ABIArea: Concerning the application binary interface (ABI)
    A-target-featureArea: Enabling/disabling target features like AVX, Neon, etc.
    on Oct 16, 2024
  5. chorman0773 commented on Oct 16, 2024

    @chorman0773
    Contributor

    sse should be included for x86-64 and x87 should not be. Floats on 64-bit x86 use xmm registers rather than the x87 stack.

  6. RalfJung commented on Oct 16, 2024

    @RalfJung
    MemberAuthor

    Does -x87 not also disable SSE?

  7. chorman0773 commented on Oct 16, 2024

    @chorman0773
    Contributor

    I would assume not, they're entirely separate instruction sets and units.
    In regardless, sse still affects float abi on x86_64.

  8. beetrees commented on Oct 16, 2024

    @beetrees
    Contributor
  9. RalfJung commented on Oct 17, 2024

    @RalfJung
    MemberAuthor

    On x86 (32-bit and 64-bit), f16 will get passed in an integer register instead of an SSE register if the sse2 feature is disabled.

    What is the default register for f16 on x86-32? I would have expected it matches f32 and f64, i.e., it uses an x87 register for returns and gets passed on the stack for arguments? Why is SSE involved at all?

  10. beetrees commented on Oct 17, 2024

    @beetrees
    Contributor

    Oops, I meant returned (passed only applies for x86-64): you're correct that 32-bit x86 always passes arguments on the stack. I've updated my comment. On 32-bit x86, the ABI specifies that f16 gets returned in xmm0, which is what Clang and GCC do (neither Clang nor GCC support _Float16 when SSE2 is disabled).

  11. RalfJung commented on Oct 17, 2024

    @RalfJung
    MemberAuthor

    On 32-bit x86, the ABI specifies that f16 gets returned in xmm0, which is what Clang and GCC do (neither Clang nor GCC support _Float16 when SSE2 is disabled).

    Oh wow that's Just Great. Probably justifies a separate issue: #131819

  12. 24 remaining items

  13. kjetilkjeka commented on Oct 10, 2025

    @kjetilkjeka
    Contributor

    But IIUC that's something that happens to be the case now, but not a promise going forward, so this could still become an issue in the future...

    That's how I understand it. But it also very much seems like something there will be put effort into not breaking in practice.

    Target features are meant for things you can mix-and-match freely in the same binary. I am slightly concerned that the way the nvptx backend uses them may not be compatible with that. I also don't actually understand these target features so maybe those concerns are unnecessary. ;)

    Your concerns are completely justified. A binary will end up with one exact ptx and sm version. From the target docs on nvptx

    Although Rust follows LLVM in representing ptx* and sm_* as target features, they should be thought of as having crate granularity, set via (either via -Ctarget-cpu and optionally -Ctarget-feature). While the compiler accepts #[target_feature(enable = "ptx80", enable = "sm_89")], it is not supported, may not behave as intended, and may become erroneous in the future.

    I think whats meant with "crate granularity" is really more of a "per binary" granularity

    Considering that having control of sm/ptx versions is very important for the nvptx target. Do you have a more suitable way to represent these properties in mind?

  14. bjorn3 commented on Oct 10, 2025

    @bjorn3
    Member

    This seems like something for which -Ctarget-cpu would make sense. Avr and amdgpu already require specifying a -Ctarget-cpu and maybe deny mixing crates compiled with different -Ctarget-cpu values.

  15. RalfJung commented on Oct 10, 2025

    @RalfJung
    MemberAuthor

    Yeah, maybe we could use the target modifier infrastructure to reject mixing different target-cpu on targets where those are mutually exclusive. Let's move this discussion to #141468

    I feel like maybe nvptx went tier 2 a bit too quickly, there are some basic aspects of this target that still need figuring out...

  16. added a commit that references this issue on Jun 3, 2026
  17. added a commit that references this issue on Jun 3, 2026
  18. added a commit that references this issue on Jun 3, 2026
  19. added 3 commits that reference this issue on Jul 17, 2026
  20. added a commit that references this issue on Jul 20, 2026
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-ABIArea: Concerning the application binary interface (ABI)A-floating-pointArea: Floating point numbers and arithmeticA-target-featureArea: Enabling/disabling target features like AVX, Neon, etc.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-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