https://github.com/hussam-alhassan created https://github.com/llvm/llvm-project/pull/224613
Set the _GNU_SOURCE macro when compiling for aarch64-none-elf in C++ mode to enable libc++ headers to use GNU interfaces. This matches ARM.cpp when compiling or arm-none-eabi. >From 2d39fb4c9a5b83be0bc333bd4bdfdf4b640a9013 Mon Sep 17 00:00:00 2001 From: Hussam Alhassan <[email protected]> Date: Fri, 18 Sep 2026 12:42:25 +0100 Subject: [PATCH] [clang] Set _GNU_SOURCE for AArch64 bare-metal targets Set the _GNU_SOURCE macro when compiling for aarch64-none-elf in C++ mode to enable libc++ headers to use GNU interfaces --- clang/lib/Basic/Targets/AArch64.cpp | 11 +++++++++-- clang/test/Preprocessor/init-aarch64.c | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index a4841514be35e..9aac476a078f5 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -402,8 +402,9 @@ void AArch64TargetInfo::getTargetDefinesARMV97A(const LangOptions &Opts, void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const { + const llvm::Triple &T = getTriple(); // Target identification. - if (getTriple().isWindowsArm64EC()) { + if (T.isWindowsArm64EC()) { // Define the same set of macros as would be defined on x86_64 to ensure that // ARM64EC datatype layouts match those of x86_64 compiled code Builder.defineMacro("__amd64__"); @@ -415,7 +416,13 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__aarch64__"); } - if (getTriple().isLFI()) + // For bare-metal none-elf. + if (T.getOS() == llvm::Triple::UnknownOS && T.getEnvironmentName() == "elf" && + Opts.CPlusPlus) { + Builder.defineMacro("_GNU_SOURCE"); + } + + if (T.isLFI()) Builder.defineMacro("__LFI__"); // Inline assembly supports AArch64 flag outputs. diff --git a/clang/test/Preprocessor/init-aarch64.c b/clang/test/Preprocessor/init-aarch64.c index 44b92ea2331b0..c1ee51902ff66 100644 --- a/clang/test/Preprocessor/init-aarch64.c +++ b/clang/test/Preprocessor/init-aarch64.c @@ -1170,3 +1170,6 @@ // CMODEL_TINY: #define __AARCH64_CMODEL_TINY__ 1 // CMODEL_SMALL: #define __AARCH64_CMODEL_SMALL__ 1 // CMODEL_LARGE: #define __AARCH64_CMODEL_LARGE__ 1 + +// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=aarch64-none-elf < /dev/null | FileCheck --match-full-lines --check-prefix=AARCH64-NONE-ELF-CXX %s +// AARCH64-NONE-ELF-CXX: #define _GNU_SOURCE 1 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
