Skip to content

Name the RISC-V ISA alongside the ABI - #33

Merged
colemancda merged 1 commit into
masterfrom
feature/riscv-abi-flags
Aug 1, 2026
Merged

colemancda merged 1 commit into
masterfrom
feature/riscv-abi-flags

Conversation

@colemancda

Copy link
Copy Markdown
Member

package/swift/swift.mk passed -mabi for riscv64 but never -march. Clang derives neither from the riscv64-unknown-linux-gnu triple: it defaults to -march=rv64gc -mabi=lp64d whatever buildroot configured.

Buildroot's default BR2_riscv_g is IMAFD with no compressed instructions, so even swift_riscv64_defconfig disagreed with the rv64gc clang assumed, and a configuration without F/D would still have had those instructions emitted under a soft-float ABI - -mabi=lp64 does not narrow the ISA, and clang only diagnoses the reverse pairing (-march=rv64ima -mabi=lp64d).

The ISA string has no config symbol on RISC-V: buildroot assembles it in arch/arch.mk.riscv as the make variable GCC_TARGET_ARCH, leaving BR2_GCC_TARGET_ARCH empty. arch.mk is included before package/*/*.mk, so it is in scope in the package, and clang accepts the value verbatim, _zicsr_zifencei suffix included.

The three flags now live in one SWIFT_RISCV_ABI_FLAGS, each part guarded against an empty value, feeding the stdlib build and both flag lists of the SwiftPM toolchain file. The C side (extra-cc-flags) previously carried none of them, so C targets in a SwiftPM package were compiled rv64gc/lp64d with relaxation on however the system was configured.

Validation

Checked against the toolchain this package builds (Swift 6.3.3 clang/swiftc), which is what motivated the change:

  • -Xcc -mabi= reaches swiftc's own code generation, not just the clang importer - swift builds its llvm module through clang's CodeGenerator, so -Xcc -mabi=lp64 lands as !"target-abi", !"lp64" in the module flags and -Xcc -march=/-mno-relax change the target-features of every function swiftc emits.
  • Clang's untouched default for the target triple really is +m,+a,+f,+d,+c / lp64d.
  • BR2_GCC_TARGET_ABI is defined for RISC-V in arch/Config.in.riscv and spells lp64/lp64f/lp64d exactly as clang does; it resolves to lp64d for the shipped defconfig.
  • Make expansion and the JSON the install step writes were checked with a standalone harness, including the empty-value path.

MIPS soft-float and the PowerPC -mcpu asymmetry are left as they are.

clang derives neither the ISA nor the calling convention from
riscv64-unknown-linux-gnu: it defaults to -march=rv64gc -mabi=lp64d
regardless of what buildroot configured. Only -mabi was passed, so the
stdlib was built for rv64gc even where the rest of the system was not -
the default BR2_riscv_g is IMAFD with no compressed instructions, and a
configuration without F/D would still have had those instructions
emitted under a soft-float ABI.

Pass -march too, from the GCC_TARGET_ARCH make variable buildroot
assembles in arch/arch.mk.riscv (BR2_GCC_TARGET_ARCH is left empty on
RISC-V), and emit the same set into both flag lists of the SwiftPM
toolchain file, where the C side previously carried none of them.
@colemancda
colemancda merged commit 63f55e5 into master Aug 1, 2026
8 checks passed
@colemancda
colemancda deleted the feature/riscv-abi-flags branch August 1, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant