Skip to content

Commit 1a96088

Browse files
committed
fix(macos): static libc++ via ld64 -hidden-l (gtest SIGABRT on exit)
Linking the archives by path left their symbols with default visibility; the system libc++/libc++abi that libSystem pulls in indirectly then clashes with the static copy and processes abort during static destruction — every gtest binary exited 6 on macos CI (the mcpp/xlings entry points only survived via their _Exit guards). -hidden-l is the ld64 feature built for static libc++: it links the archive (never the sibling dylib) and gives its symbols hidden visibility, so the two copies can coexist.
1 parent cf975ca commit 1a96088

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/build/flags.cppm

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,20 @@ CompileFlags compute_flags(const BuildPlan& plan) {
363363
// lld ships with the exact toolchain doing the compile.
364364
std::string stdlib_link = " -lc++";
365365
if (f.staticStdlib && !llvmRootForStdlib.empty()) {
366-
auto libcxxA = llvmRootForStdlib / "lib" / "libc++.a";
367-
auto libcxxAbiA = llvmRootForStdlib / "lib" / "libc++abi.a";
366+
auto libDir = llvmRootForStdlib / "lib";
367+
auto libcxxA = libDir / "libc++.a";
368+
auto libcxxAbiA = libDir / "libc++abi.a";
368369
if (std::filesystem::exists(libcxxA)
369370
&& std::filesystem::exists(libcxxAbiA)) {
370-
stdlib_link = " -nostdlib++ " + escape_path(libcxxA)
371-
+ " " + escape_path(libcxxAbiA);
371+
// -hidden-l: ld64/lld feature made for exactly this —
372+
// links the ARCHIVE (never the sibling dylib) and gives
373+
// its symbols hidden visibility. Without it the static
374+
// libc++/libc++abi symbols clash with the system copies
375+
// that libSystem pulls in indirectly, and processes
376+
// SIGABRT during static destruction (observed: every
377+
// gtest binary exiting 6 on macos CI).
378+
stdlib_link = " -nostdlib++ -L" + escape_path(libDir)
379+
+ " -Wl,-hidden-lc++ -Wl,-hidden-lc++abi";
372380
}
373381
}
374382
std::string version_min;

0 commit comments

Comments
 (0)