From bf1ed062c0a93dc5ef738ddd3c0a74fbfb20e16f Mon Sep 17 00:00:00 2001 From: chen3feng Date: Sun, 28 Jun 2026 22:29:57 +0800 Subject: [PATCH] thirdparty: pin AR/RANLIB in autotools foreign builds (fix macOS jemalloc link) _configure passed CC/CXX from the resolved toolchain but let AR/RANLIB fall through to PATH. On macOS, a stray GNU-format `ar` ahead of /usr/bin/ar (e.g. Homebrew binutils / an llvm-ar in --format=gnu mode) builds a package's static archive in GNU format -- with `/` and `//` index members -- which Apple's ld rejects at link time: ld: archive member '/' not a mach-o file in '.../lib/libjemalloc.a' This surfaced on je_server (jemalloc's libjemalloc.a is built by a direct $(AR) crus Makefile rule, so it picks up the PATH ar; libtool-built archives like libtcmalloc/jsoncpp/ctemplate were unaffected because libtool drives the archiver consistently). The gperftools profiler archives hit the same GNU format but are gated Linux-only, so they never reached a macOS link. Pin AR/RANLIB the same way CC/CXX already are: force the system BSD ar/ranlib on macOS (they emit a `__.SYMDEF` archive ld accepts), and honor the toolchain ar elsewhere (GNU archives are fine for GNU ld). Passed both as env and as autoconf precious-vars so the generated Makefile uses them (verified: `AR = /usr/bin/ar`, archive members are `__.SYMDEF SORTED` + objects, je_server links). Co-Authored-By: Claude Opus 4.8 --- thirdparty/foreign_build.bld | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/thirdparty/foreign_build.bld b/thirdparty/foreign_build.bld index 91f8ac2..298c99b 100644 --- a/thirdparty/foreign_build.bld +++ b/thirdparty/foreign_build.bld @@ -118,20 +118,30 @@ def _configure(name, package_name, source_dir, install_dir, with_packages, deps, # blade.cc_toolchain.tool() decided at config time. cc = blade.cc_toolchain.tool('cc') or 'cc' cxx = blade.cc_toolchain.tool('cxx') or 'c++' + # Pin the archiver too. blade.cc_toolchain.tool('ar') is the bare name `ar`, + # so an autotools package falls back to whatever `ar`/`ranlib` is first in + # PATH. On macOS a stray GNU/LLVM `ar` (e.g. from Homebrew binutils) there + # produces a GNU-format archive -- with `/` and `//` index members -- that + # Apple's ld then rejects at link time ("archive member '/' not a mach-o + # file"). Force the system BSD ar/ranlib, which emit a `__.SYMDEF` archive + # ld accepts. Off macOS, GNU archives are fine, so honor the toolchain ar. + ar = '/usr/bin/ar' if is_darwin else (blade.cc_toolchain.tool('ar') or 'ar') + ranlib = '/usr/bin/ranlib' if is_darwin else 'ranlib' configure = ('cd $OUT_DIR/%s && ' 'LD_LIBRARY_PATH=%s:$LD_LIBRARY_PATH ' '%s' - 'CC=%s CXX=%s ' + 'CC=%s CXX=%s AR=%s RANLIB=%s ' 'LDFLAGS="$LDFLAGS %s" ' - './%s --prefix=%s %s' % ( + './%s --prefix=%s %s AR=%s RANLIB=%s' % ( source_dir, lib_path_env, dyld_path, - cc, cxx, + cc, cxx, ar, ranlib, rpath_flags, configure_file_name, full_install_dir, - configure_options)) + configure_options, + ar, ranlib)) if with_packages: for pkg in with_packages: pkg = pkg[1:] # remove prefix ':'