Skip to content

Commit 76a694d

Browse files
committed
fix: add -nostdinc++ -stdlib=libc++ for Clang --no-default-config
When bypassing clang++.cfg, the cfg's -nostdinc++ and -stdlib=libc++ flags are also stripped. Without -nostdinc++, Clang may find host libstdc++ headers before the payload's libc++ headers. Without -stdlib=libc++, Clang defaults to libstdc++ runtime. Also remove the /usr/include fallback for linux-headers — mixing host headers with xpkg glibc causes bits/wordsize.h conflicts.
1 parent 2baa031 commit 76a694d

3 files changed

Lines changed: 2 additions & 8 deletions

File tree

src/build/flags.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ CompileFlags compute_flags(const BuildPlan& plan) {
111111
// Clang with cfg: bypass cfg and provide all paths explicitly.
112112
auto llvmRoot = plan.toolchain.binaryPath.parent_path().parent_path();
113113
auto libcxxInclude = llvmRoot / "include" / "c++" / "v1";
114-
sysroot_flag = " --no-default-config";
114+
sysroot_flag = " --no-default-config -nostdinc++";
115115
// libc++ headers
116116
sysroot_flag += " -stdlib=libc++";
117117
sysroot_flag += " -isystem" + escape_path(libcxxInclude);

src/toolchain/probe.cppm

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,6 @@ probe_payload_paths(const std::filesystem::path& compilerBin) {
342342
pp.linuxInclude = linuxInclude;
343343
}
344344

345-
// Fallback: host /usr/include has linux kernel headers on most systems.
346-
if (pp.linuxInclude.empty()) {
347-
if (std::filesystem::exists("/usr/include/linux/limits.h"))
348-
pp.linuxInclude = "/usr/include";
349-
}
350-
351345
return pp;
352346
}
353347

src/toolchain/stdmod.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ std::expected<StdModule, StdModError> ensure_built(
108108
if (std::filesystem::exists(cfgPath)) {
109109
auto llvmRoot = tc.binaryPath.parent_path().parent_path();
110110
auto libcxxInclude = llvmRoot / "include" / "c++" / "v1";
111-
sysroot_flag = " --no-default-config";
111+
sysroot_flag = " --no-default-config -nostdinc++ -stdlib=libc++";
112112
sysroot_flag += std::format(" -isystem'{}'", libcxxInclude.string());
113113
if (!tc.targetTriple.empty()) {
114114
auto targetInclude = llvmRoot / "include"

0 commit comments

Comments
 (0)