[clang] [Clang][Hexagon] Define _GNU_SOURCE when using picolibc in C++ mode (PR #201599)
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 5 22:04:11 PDT 2026
================
@@ -813,6 +815,13 @@ void HexagonToolChain::addClangTargetOptions(const ArgList &DriverArgs,
CC1Args.push_back("-mllvm");
CC1Args.push_back("-hexagon-autohvx");
}
+
+ // picolibc guards GNU-extension functions (e.g. strtold_l) with __GNU_VISIBLE
+ // which requires _GNU_SOURCE. Define it automatically for C++ compilations
+ // so that building libcxx against picolibc works without -D_GNU_SOURCE.
+ if (GetCStdlibType(DriverArgs) == ToolChain::CST_Picolibc &&
+ getDriver().CCCIsCXX())
+ CC1Args.push_back("-D_GNU_SOURCE");
}
----------------
MaskRay wrote:
Such macro definitions should be moved to clang/lib/Basic/Targets/OSTargets.h from clangDriver. g++ defines `_GNU_SOURCE` for C++ mode.
Defining different macros depending on `GetCStdlibType` is not a good idea...
https://github.com/llvm/llvm-project/pull/201599
More information about the cfe-commits
mailing list