Skip to content

arch/x86: default CROSSDEV on a macOS host - #19567

Merged
jerpelea merged 1 commit into
apache:masterfrom
casaroli:fix-x86-crossdev
Jul 28, 2026
Merged

arch/x86: default CROSSDEV on a macOS host#19567
jerpelea merged 1 commit into
apache:masterfrom
casaroli:fix-x86-crossdev

Conversation

@casaroli

Copy link
Copy Markdown
Contributor

Note: Please adhere to Contributing Guidelines.

Summary

arch/x86/src/common/Toolchain.defs sets CROSSDEV only under Cygwin:

ifeq ($(CONFIG_WINDOWS_CYGWIN),y)
CROSSDEV = i486-nuttx-elf-
endif

CC = $(CROSSDEV)gcc

Everywhere else CROSSDEV is empty, so CC becomes the bare host gcc. That
is fine on an x86 Linux box and useless anywhere else. On macOS the host
compiler is Apple clang, which on Apple Silicon cannot target i386 at all, so
the build fails in a thoroughly misleading way — the ARM assembler rejecting
x86 inline asm out of an x86 header:

include/arch/i486/irq.h:249:5: error: invalid instruction, did you mean: push?
include/arch/i486/irq.h:283:16: error: invalid instruction, did you mean: stc, stm, stmib, str, tst?

This gives CROSSDEV a sane default on macOS and makes the Cygwin one
overridable (=?=), matching what arch/x86_64 already does.

Homebrew's i686-elf-gcc is the intended target; a 64-bit x86 toolchain with
-m32 is not a substitute unless built with multilib, since it compiles 32-bit
objects and then has no 32-bit libgcc to link them against — which surfaces
only at the final link as undefined __udivdi3 and friends.

Impact

Only CONFIG_HOST_MACOS=y builds of arch/x86 change, and only by picking a
compiler that can actually target the architecture. ?= keeps any existing
override — including the Cygwin default — working.

Testing

qemu-i486:nsh on macOS 15 / Apple Silicon, Homebrew i686-elf-gcc 16.1.0:

  • before: host clang is invoked, build dies on ARM instruction errors.
  • after: i686-elf-gcc is invoked and the build completes — rc 0, 3.0 MB
    nuttx.elf.

One caveat worth recording for anyone reproducing this: the shipped
qemu-i486:nsh defconfig sets CONFIG_LIBM_TOOLCHAIN=y, which defers math.h
to the toolchain, and Homebrew's i686-elf-gcc is bare-metal with no newlib
headers. Selecting NuttX's own CONFIG_LIBM=y instead builds cleanly. That is
independent of this change and is not addressed here.

tools/checkpatch.sh -c -u -m -g clean.

Comment thread arch/x86/src/common/Toolchain.defs Outdated
arch/x86 set CROSSDEV only under Cygwin, so everywhere else the build used
the bare tool names and got the host compiler.  On Linux that is a native
gcc which can produce i486 ELF objects, which is what the board README
assumes.  On macOS it is Apple clang, and on Apple Silicon that cannot
target i386 in any form -- so there is no configuration in which the default
works and a cross toolchain is not optional.

Default it to i686-elf-, which Homebrew packages and which accepts the
-march=i486 -mtune=i486 already in ARCHCPUFLAGS.  arch/x86_64 has had
exactly this stanza for its own toolchain all along; this is the same shape.

The Cygwin assignment becomes ?= to match, so that a CROSSDEV passed in from
the environment or the command line is honoured rather than overridden.

Note for anyone tempted by the toolchain they already have: a 64-bit x86
compiler with -m32 is not a substitute unless it was built with multilib.
Homebrew's x86_64-elf-gcc compiles 32-bit objects perfectly happily and has
no 32-bit libgcc to link them against, so the entire build succeeds and only
the final link fails, on __udivdi3, __divdi3, __moddi3 and __udivmoddi4.
`x86_64-elf-gcc -print-multi-lib' prints just `.;', which is the toolchain
saying so up front.

Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
@casaroli

casaroli commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Done

The two comment blocks are merged into one above it. Re-verified after the change: qemu-i486:nsh on macOS/arm64 still selects i686-elf-gcc and builds to rc 0.

@casaroli
casaroli marked this pull request as ready for review July 28, 2026 07:18
@casaroli
casaroli requested review from anchao and jerpelea as code owners July 28, 2026 07:18
@github-actions github-actions Bot added Arch: x86 Issues related to the x86 architecture Size: S The size of the change in this PR is small labels Jul 28, 2026

@jerpelea jerpelea left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please replace
Co-Authored-By: Claude Opus 5 (1M context) noreply@anthropic.com
with
Assisted-by: Claude Opus 5 (1M context) noreply@anthropic.com

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@casaroli
casaroli force-pushed the fix-x86-crossdev branch 2 times, most recently from 57b3f4a to 8996364 Compare July 28, 2026 07:55
@casaroli
casaroli requested a review from jerpelea July 28, 2026 08:57
@casaroli

Copy link
Copy Markdown
Contributor Author

@jerpelea hello can you please re-review?

@jerpelea
jerpelea merged commit d5e6cd3 into apache:master Jul 28, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: x86 Issues related to the x86 architecture Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants