Skip to content

Fix macOS arm64 (Apple Silicon) linker support#470

Open
metaneutrons wants to merge 1 commit into
freebasic:masterfrom
metaneutrons:macos-arm64-final
Open

Fix macOS arm64 (Apple Silicon) linker support#470
metaneutrons wants to merge 1 commit into
freebasic:masterfrom
metaneutrons:macos-arm64-final

Conversation

@metaneutrons
Copy link
Copy Markdown

Summary

Fix linking on macOS arm64 (Apple Silicon, M1/M2/M3/M4).

Changes (3 files, +47/-11)

makefile:

  • Normalize arm64 (from uname -m) to aarch64 before the 32-bit armv% catch-all

src/compiler/fbc.bas:

  • line input in hGet1stOutputLineFromCommand (handles spaces in SDK paths)
  • Add -arch arm64 for FB_CPUFAMILY_AARCH64 on darwin
  • Replace deprecated -macosx_version_min with -platform_version macos <min> <sdk>
    • min: 11.0 for arm64, 10.4 for x86_64 (preserves original minimum)
    • sdk: detected via xcrun --show-sdk-version (fallback 14.0)
  • SDK path via xcrun --show-sdk-path (only on darwin host, respects user -sysroot, quoted with QUOTE)
  • Skip GNU --sysroot= on darwin (Apple ld uses -syslibroot)
  • Remove --eh-frame-hdr on darwin (unsupported by Apple ld)
  • Remove -lgcc from darwin default libs (unavailable with Apple clang)

src/rtlib/profile_cycles.c:

  • Guard ELF __start_/__stop_ section boundary symbol declarations and usage with !defined(HOST_DARWIN)
  • Provide data=NULL, length=0 fallback on darwin (cycle profiling compiles but produces no output)

Testing

make bootstrap-minimal ENABLE_STANDALONE=1

Successfully builds fbc and runtime library on macOS 15 (Sequoia) with Apple clang 21 on M4.

Notes

  • x86_64 darwin builds unaffected (minimum version preserved at 10.4)
  • -profile cycles compiles on darwin but produces no per-procedure data (Mach-O lacks ELF section boundary symbols)
  • Bootstrap requires bootstrap/darwin-aarch64/ (copy from bootstrap/linux-aarch64/ + fix clang computed goto)

Copilot AI review requested due to automatic review settings May 15, 2026 20:00
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the build/link logic to support successful linking on macOS arm64 (Apple Silicon) by adjusting architecture detection and Darwin-specific linker flags/behaviors.

Changes:

  • Normalize arm64 to aarch64 in the makefile’s TARGET_ARCH detection before the 32-bit ARM normalization.
  • Update the Darwin linker invocation in fbc.bas to add -arch arm64 for AArch64 and use modern -platform_version/-syslibroot behavior (including xcrun SDK detection on Darwin hosts), while avoiding GNU-ld-only flags/libs on Darwin.
  • Make cycle profiling compile on Darwin by disabling ELF section-boundary-symbol usage and emitting an empty report payload.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
makefile Normalizes arm64aarch64 ahead of 32-bit ARM matching to select the correct target CPU family on macOS Apple Silicon.
src/compiler/fbc.bas Adjusts Darwin link flags for arm64 and modern Apple ld usage (SDK/sysroot handling, platform version, and default libs).
src/rtlib/profile_cycles.c Guards ELF __start/__stop usage on Darwin and provides a safe no-data fallback so it compiles on Mach-O.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants