kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

commit 2c1127782f786415c1334e10e399b1ac33f33b54
parent f203f822edbed3bc9c9ee38095985e542bdd43db
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Tue, 16 Jun 2026 17:12:39 -0700

arm32 Phase 2: -mfloat-abi parsing + soft-float resolution (float_abi=SOFT)

The driver swallowed -mfloat-abi=soft into the generic -m<feature> recorder,
which rejected 'float-abi=soft' as an unknown arm32 feature. Parse -mfloat-abi
(soft only; hard/softfp are a follow-on) and -mfpu (accept+ignore for the
soft-float build) explicitly. Add arm32_resolve_float_abi pinning float_abi to
SOFT so the arch-neutral soft-float lowering (src/cg/arith.c) is active for
both the cross lane (no flag) and -mfloat-abi=soft, without stamping a float
e_flag (soft objects stay ABI-agnostic, matching clang/gas).

Diffstat:
Mdriver/lib/target.c | 33+++++++++++++++++++++++++++++++++
Msrc/arch/arm32/arch.c | 27++++++++++++++++++++++++++-
2 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/driver/lib/target.c b/driver/lib/target.c @@ -210,6 +210,39 @@ int driver_target_features_try_consume(DriverTargetFeatures* tf, DriverEnv* env, tf->tune = kit_slice_cstr(v); return 1; } + /* -mfloat-abi / -mfpu: ARM float-ABI selection. v1 supports soft-float only + * (FP via the AEABI helpers); the arch's resolve_float_abi pins float_abi to + * SOFT. Consume the flag here so it does not fall through to the generic + * -m<feature> recorder (which would reject "float-abi=soft" as an unknown + * feature). hard/softfp are a follow-on. -mfpu only matters with hard-float, + * so it is accepted and ignored for the soft-float build. */ + if (driver_strneq(a, "-mfloat-abi=", 12)) { + if (!driver_streq(a + 12, "soft")) { + driver_errf(tool, + "-mfloat-abi=%s is unsupported (soft-float only; hard/softfp " + "are a follow-on)", + a + 12); + return -1; + } + return 1; + } + if (driver_streq(a, "-mfloat-abi")) { + v = target_features_pull_value(tool, argc, argv, i, 11, "-mfloat-abi"); + if (!v) return -1; + if (!driver_streq(v, "soft")) { + driver_errf(tool, + "-mfloat-abi %s is unsupported (soft-float only; hard/softfp " + "are a follow-on)", + v); + return -1; + } + return 1; + } + if (driver_strneq(a, "-mfpu=", 6)) return 1; + if (driver_streq(a, "-mfpu")) { + if (!target_features_pull_value(tool, argc, argv, i, 5, "-mfpu")) return -1; + return 1; + } if (driver_strneq(a, "-mno-", 5) && a[5] != '\0') { if (target_features_record_feature(tf, env, kit_slice_cstr(a + 5), 0) != 0) { diff --git a/src/arch/arm32/arch.c b/src/arch/arm32/arch.c @@ -161,6 +161,30 @@ static KitStatus arm32_target_feature_apply_isa(const Target* t, KitSlice isa, return KIT_UNSUPPORTED; } +/* arm-none-eabi v1 is soft-float only: `float` and `double` are lowered through + * the AEABI / compiler-rt helpers regardless of -mfpu, and FP args travel in the + * core registers (AAPCS soft). So float_abi resolves unconditionally to SOFT — + * this is what gates the arch-neutral soft-float lowering in src/cg/arith.c + * (api_target_has_no_hw_double). Without this hook the spec would stay at + * KIT_FLOAT_ABI_DEFAULT and `double`/`float` ops would take the (unimplemented) + * hardware path. The driver rejects -mfloat-abi=hard/softfp before we get here; + * single-precision hard-float (FPv4-SP) is a follow-on that will thread the + * requested ABI through this hook. */ +static KitStatus arm32_resolve_float_abi(const ArchImpl* impl, + KitTargetSpec* spec, + const u64* feature_words, + u32 nfeature_words, KitSlice abi, + char* err, size_t errcap) { + (void)impl; + (void)feature_words; + (void)nfeature_words; + (void)abi; + (void)err; + (void)errcap; + if (spec) spec->float_abi = (uint8_t)KIT_FLOAT_ABI_SOFT; + return KIT_OK; +} + static int arm32_supports_call_conv(const Compiler* c, KitCgCallConv cc) { (void)c; return cc == KIT_CG_CC_TARGET_C; @@ -265,5 +289,6 @@ const ArchImpl arch_impl_arm32 = { .atomic_lock_free_max = 4u, /* no LDREXD/STREXD on M-profile -> 8B spinlock */ .supports_call_conv = arm32_supports_call_conv, .supports_intrinsic = arm32_supports_intrinsic, - /* .resolve_float_abi omitted (NULL) for Phase 1 (soft-float only). */ + /* v1 is soft-float: float_abi resolves to SOFT (gates cg soft-float). */ + .resolve_float_abi = arm32_resolve_float_abi, };