Skip to content

Use of RiscV "+forced-atomics" target feature triggers hard-float ABI for symbols.o #114153

Closed
@paulmenage

Description

When building for RiscV-32, adding the "+forced-atomics" target feature (in this case, adding it to a custom target .json file) causes the symbols.o file to be built with the single-float ABI rather than the soft-float ABI used for the all .rcgu.o files, which causes the link to fail due to incompatible float ABIs.

It appears to be due to this code in compiler/rustc_codegen_ssa/src/back/metadata.rs:

        Architecture::Riscv32 | Architecture::Riscv64 => {
            // Source: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/079772828bd10933d34121117a222b4cc0ee2200/riscv-elf.adoc
            let mut e_flags: u32 = 0x0;
            let features = &sess.target.options.features;
            // Check if compressed is enabled
            if features.contains("+c") {
                e_flags |= elf::EF_RISCV_RVC;
            }

            // Select the appropriate floating-point ABI
            if features.contains("+d") {
                e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE;
            } else if features.contains("+f") {
                e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE;
            } else {
                e_flags |= elf::EF_RISCV_FLOAT_ABI_SOFT;
            }
            e_flags
        }

which assumes that any feature beginning with "+f" is in fact exactly "+f", so the addition of "+forced-atomics" triggers the single-float ABI.

Should this check (and most other feature checks) actually be something like: features.split(",").any(|f| f == "+f") (probably useful as a TargetOptions::has_feature() helper method)?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-target-featureArea: Enabling/disabling target features like AVX, Neon, etc.C-bugCategory: This is a bug.O-riscvTarget: RISC-V architectureT-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