From 7a5130b2f17c9dc5b7c710ebf4a753877b6bb1e7 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Tue, 14 Oct 2025 00:27:53 +0800 Subject: [PATCH] Fix llvm-ar detection for Clang LTO builds The original code unconditionally used llvm-ar with Clang, causing build failures on macOS where Apple Clang doesn't provide llvm-ar. When LTO is enabled with Clang, llvm-ar is required to handle LLVM bitcode in object files. System ar on Linux cannot process LLVM bitcode, leading to link-time failures when creating static libraries like 'softfloat.a'. --- Makefile | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b123215a..e0b4abc6 100644 --- a/Makefile +++ b/Makefile @@ -116,7 +116,26 @@ $(call set-feature, EXT_F) ifeq ($(call has, EXT_F), 1) AR := ar ifeq ("$(CC_IS_CLANG)", "1") -AR = llvm-ar + # On macOS, system ar works with Apple Clang's LTO + ifeq ($(UNAME_S),Darwin) + # macOS: system ar is sufficient + else + # Non-macOS with Clang: check if LTO is enabled + ifeq ($(call has, LTO), 1) + # LTO requires llvm-ar to handle LLVM bitcode in object files + LLVM_AR := $(shell which llvm-ar 2>/dev/null) + ifeq ($(LLVM_AR),) + $(error llvm-ar not found. Install LLVM or disable LTO with ENABLE_LTO=0) + endif + AR = llvm-ar + else + # LTO disabled: prefer llvm-ar if available, otherwise use system ar + LLVM_AR := $(shell which llvm-ar 2>/dev/null) + ifneq ($(LLVM_AR),) + AR = llvm-ar + endif + endif + endif endif ifeq ("$(CC_IS_EMCC)", "1") AR = emar