Skip to content

Commit 7a5130b

Browse files
committed
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'.
1 parent 65a1ec6 commit 7a5130b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Makefile

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,26 @@ $(call set-feature, EXT_F)
116116
ifeq ($(call has, EXT_F), 1)
117117
AR := ar
118118
ifeq ("$(CC_IS_CLANG)", "1")
119-
AR = llvm-ar
119+
# On macOS, system ar works with Apple Clang's LTO
120+
ifeq ($(UNAME_S),Darwin)
121+
# macOS: system ar is sufficient
122+
else
123+
# Non-macOS with Clang: check if LTO is enabled
124+
ifeq ($(call has, LTO), 1)
125+
# LTO requires llvm-ar to handle LLVM bitcode in object files
126+
LLVM_AR := $(shell which llvm-ar 2>/dev/null)
127+
ifeq ($(LLVM_AR),)
128+
$(error llvm-ar not found. Install LLVM or disable LTO with ENABLE_LTO=0)
129+
endif
130+
AR = llvm-ar
131+
else
132+
# LTO disabled: prefer llvm-ar if available, otherwise use system ar
133+
LLVM_AR := $(shell which llvm-ar 2>/dev/null)
134+
ifneq ($(LLVM_AR),)
135+
AR = llvm-ar
136+
endif
137+
endif
138+
endif
120139
endif
121140
ifeq ("$(CC_IS_EMCC)", "1")
122141
AR = emar

0 commit comments

Comments
 (0)