nuttx/libs/libbuiltin/compiler-rt/Make.defs
Udit Jain 6f0da60bd7
Some checks are pending
Build Documentation / build-html (push) Waiting to run
MemBrowse Memory Report / changes-filter (push) Waiting to run
MemBrowse Memory Report / load-targets (push) Waiting to run
MemBrowse Memory Report / identical (push) Blocked by required conditions
MemBrowse Memory Report / analyze (push) Blocked by required conditions
libs/libbuiltin/compiler-rt: skip unsupported Arm VFP builtins asm
The compiler-rt builtins build globs every arm/*.S source, but several of
those hand-written assembly files require FPU features the target may not
have.  Upstream compiler-rt selects them conditionally; NuttX did not, so
BUILTIN_COMPILER_RT builds for single-precision-FPU Arm targets (e.g.
Cortex-M33, -mfpu=fpv5-sp-d16) failed to assemble with errors such as
"selected FPU does not support instruction -- vadd.f64".

Filter the source list to match the configured FPU, in both the Makefile
and CMake builds:
  - chkstk.S / chkstk2.S are Windows/MinGW-only stack probes, always dropped;
  - with no hardware FPU (!CONFIG_ARCH_FPU) all arm/*vfp.S are dropped;
  - with a single-precision FPU (!CONFIG_ARCH_DPFPU) the double-precision
    *df*vfp.S routines are dropped.

Reproduced against compiler-rt 17.0.1 with arm-none-eabi-gcc 14.2 using the
Cortex-M33 single-precision flags: 18 of 86 arm/*.S files failed to assemble
(17 double-precision *df*vfp.S plus chkstk.S); after the filter all remaining
68 files assemble cleanly.

Fixes: https://github.com/apache/nuttx/issues/17386
Generated-by: Claude (Anthropic)
Signed-off-by: Udit Jain <uditjainstjis@gmail.com>
2026-07-31 15:37:33 -03:00

172 lines
5.8 KiB
Text

############################################################################
# libs/libbuiltin/compiler-rt/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/Make.defs
COMPILER_RT_VERSION=$(CONFIG_LIB_COMPILER_RT_VERSION)
ifeq ($(CONFIG_ARCH_ARM),y)
ARCH = arm
else ifeq ($(CONFIG_ARCH_RISCV),y)
ARCH = riscv
else ifeq ($(CONFIG_ARCH_X86_64),y)
ARCH = x86_64
else ifeq ($(CONFIG_ARCH_ARM64),y)
ARCH = aarch64
endif
COMPILER_RT_OBJDIR = compiler-rt \
compiler-rt/compiler-rt \
compiler-rt/compiler-rt/lib \
compiler-rt/compiler-rt/lib/builtins \
compiler-rt/compiler-rt/lib/profile
ifneq ($(ARCH),)
COMPILER_RT_OBJDIR += compiler-rt/compiler-rt/lib/builtins/$(ARCH)
endif
BIN_OBJDIR = $(addprefix $(BINDIR)$(DELIM),$(COMPILER_RT_OBJDIR))
KBIN_OBJDIR = $(addprefix $(KBINDIR)$(DELIM),$(COMPILER_RT_OBJDIR))
$(BIN_OBJDIR) $(KBIN_OBJDIR):
$(Q) mkdir -p $@
ifeq ($(wildcard compiler-rt/compiler-rt/lib),)
compiler-rt-$(COMPILER_RT_VERSION).src.tar.xz:
$(call DOWNLOAD,https://github.com/llvm/llvm-project/releases/download/llvmorg-$(COMPILER_RT_VERSION),$@)
compiler-rt/compiler-rt: compiler-rt-$(COMPILER_RT_VERSION).src.tar.xz
$(Q) tar -xf $<
$(Q) mv compiler-rt-$(COMPILER_RT_VERSION).src $@
$(call DELDIR, $<)
compiler-rt: compiler-rt/compiler-rt
endif
ifeq ($(CONFIG_LIB_COMPILER_RT),y)
.PHONY: compiler-rt
depend:: compiler-rt $(BIN_OBJDIR) $(KBIN_OBJDIR)
distclean::
$(call DELDIR, $(BIN_OBJDIR))
$(call DELDIR, $(KBIN_OBJDIR))
ifeq ($(wildcard compiler-rt/compiler-rt/.git),)
$(call DELDIR, compiler-rt/compiler-rt)
endif
FLAGS += ${INCDIR_PREFIX}$(CURDIR)/compiler-rt/compiler-rt/include
endif
################# Builtin Library #################
ifeq ($(CONFIG_BUILTIN_COMPILER_RT),y)
FLAGS += ${INCDIR_PREFIX}$(CURDIR)/compiler-rt/compiler-rt/lib/builtins
FLAGS += -Wno-undef -Wno-macro-redefined
CSRCS += $(wildcard compiler-rt/compiler-rt/lib/builtins/*.c)
ifneq ($(ARCH),)
FLAGS += ${INCDIR_PREFIX}$(CURDIR)/compiler-rt/compiler-rt/lib/builtins/${ARCH}
ASRCS += $(wildcard compiler-rt/compiler-rt/lib/builtins/$(ARCH)/*.S)
CSRCS += $(wildcard compiler-rt/compiler-rt/lib/builtins/$(ARCH)/*.c)
endif
ifeq ($(CONFIG_LIB_COMPILER_RT_HAS_BFLOAT16),)
BFLOAT16_SRCS := compiler-rt/compiler-rt/lib/builtins/truncdfbf2.c
BFLOAT16_SRCS += compiler-rt/compiler-rt/lib/builtins/truncsfbf2.c
CSRCS := $(filter-out $(BFLOAT16_SRCS), $(CSRCS))
endif
ifeq ($(CONFIG_ARCH_X86_64),)
x86_80_BIT_SOURCES := divxc3.c extendxftf2.c fixxfdi.c fixxfti.c fixunsxfdi.c
x86_80_BIT_SOURCES += fixunsxfsi.c fixunsxfti.c floatdixf.c floattixf.c floatundixf.c
x86_80_BIT_SOURCES += floatuntixf.c mulxc3.c powixf2.c trunctfxf2.c
x86_80_BIT_SOURCES := $(addprefix compiler-rt/compiler-rt/lib/builtins/, $(x86_80_BIT_SOURCES))
CSRCS := $(filter-out $(x86_80_BIT_SOURCES), $(CSRCS))
endif
# The Arm builtins ship hand-written VFP assembly whose FPU requirements the
# wildcard glob above ignores. Upstream compiler-rt selects these files
# conditionally, so assemble only the ones the configured FPU supports;
# otherwise single-precision-FPU targets (e.g. Cortex-M33, fpv5-sp-d16) fail
# with "selected FPU does not support instruction". See apache/nuttx#17386.
# - chkstk.S / chkstk2.S are Windows/MinGW-only stack probes;
# - every *vfp.S needs a hardware FPU;
# - the double-precision *df*vfp.S routines additionally need a
# double-precision FPU.
ifeq ($(CONFIG_ARCH_ARM),y)
COMPILER_RT_ARM_EXCLUDE := chkstk.S chkstk2.S
ifneq ($(CONFIG_ARCH_FPU),y)
COMPILER_RT_ARM_EXCLUDE += $(notdir \
$(wildcard compiler-rt/compiler-rt/lib/builtins/arm/*vfp.S))
else ifneq ($(CONFIG_ARCH_DPFPU),y)
COMPILER_RT_ARM_EXCLUDE += adddf3vfp.S divdf3vfp.S eqdf2vfp.S extendsfdf2vfp.S
COMPILER_RT_ARM_EXCLUDE += fixdfsivfp.S fixunsdfsivfp.S floatsidfvfp.S
COMPILER_RT_ARM_EXCLUDE += floatunssidfvfp.S gedf2vfp.S gtdf2vfp.S ledf2vfp.S
COMPILER_RT_ARM_EXCLUDE += ltdf2vfp.S muldf3vfp.S nedf2vfp.S subdf3vfp.S
COMPILER_RT_ARM_EXCLUDE += truncdfsf2vfp.S unorddf2vfp.S
endif
ASRCS := $(filter-out $(addprefix \
compiler-rt/compiler-rt/lib/builtins/arm/, $(COMPILER_RT_ARM_EXCLUDE)), \
$(ASRCS))
endif
endif
################# Profile Library #################
ifeq ($(CONFIG_COVERAGE_COMPILER_RT),y)
FLAGS += ${INCDIR_PREFIX}$(CURDIR)/compiler-rt/compiler-rt/lib/profile
FLAGS += -fno-profile-instr-generate -fno-coverage-mapping
FLAGS += -Wno-undef -Wno-strict-prototypes -Wno-shadow
FLAGS += -DCOMPILER_RT_HAS_UNAME
ifeq ($(CONFIG_HOST_MACOS),y)
FLAGS += -D__APPLE__
endif
CSRCS += $(wildcard compiler-rt/compiler-rt/lib/profile/*.c)
CPPSRCS += $(wildcard compiler-rt/compiler-rt/lib/profile/*.cpp)
CSRCS += InstrProfilingPlatform.c
else ifeq ($(CONFIG_COVERAGE_MINI)$(CONFIG_ARCH_TOOLCHAIN_CLANG),yy)
FLAGS += ${INCDIR_PREFIX}$(CURDIR)/compiler-rt/compiler-rt/lib/profile
FLAGS += -fno-profile-instr-generate -fno-coverage-mapping
CSRCS += coverage.c
endif
AFLAGS += $(FLAGS)
CFLAGS += $(FLAGS)
CXXFLAGS += $(FLAGS)
DEPPATH += --dep-path compiler-rt
VPATH += :compiler-rt