[clang] [clang][Fuchsia] Add __Fuchsia_Compiler_ABI__ predefine (PR #211744)
Roland McGrath via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 24 01:05:26 PDT 2026
https://github.com/frobtech created https://github.com/llvm/llvm-project/pull/211744
This establishes a new canonical predefine for *-fuchsia targets:
`__Fuchsia_Compiler_ABI__` is set to an integer for the version
number of the Fuchsia Compiler ABI the compiler supports. The
value will change as appropriate with changes to *-fuchsia target
ABI expectations. It is not anticipated that the compiler will
support selecting target ABI versions, only the latest as the
canonical target-specific behavior. Fuchsia Compiler ABI
versions are unrelated to the Fuchsia API levels supported by
Fuchsia systems; newly-built programs may target older API levels
with `-ffuchsia-api-level`, but everything relying on the Fuchsia
Compiler ABI is built and deployed together as an isolated unit.
>From e9e84e81af8943227275eeddc7171c969d0d1088 Mon Sep 17 00:00:00 2001
From: Roland McGrath <mcgrathr at google.com>
Date: Fri, 24 Jul 2026 00:47:29 -0700
Subject: [PATCH] [clang][Fuchsia] Add __Fuchsia_Compiler_ABI__ predefine
This establishes a new canonical predefine for *-fuchsia targets:
`__Fuchsia_Compiler_ABI__` is set to an integer for the version
number of the Fuchsia Compiler ABI the compiler supports. The
value will change as appropriate with changes to *-fuchsia target
ABI expectations. It is not anticipated that the compiler will
support selecting target ABI versions, only the latest as the
canonical target-specific behavior. Fuchsia Compiler ABI
versions are unrelated to the Fuchsia API levels supported by
Fuchsia systems; newly-built programs may target older API levels
with `-ffuchsia-api-level`, but everything relying on the Fuchsia
Compiler ABI is built and deployed together as an isolated unit.
---
clang/lib/Basic/Targets/OSTargets.cpp | 19 +++++++++++++++++++
clang/test/Preprocessor/init-fuchsia.c | 1 +
2 files changed, 20 insertions(+)
diff --git a/clang/lib/Basic/Targets/OSTargets.cpp b/clang/lib/Basic/Targets/OSTargets.cpp
index 915cd566ed6e4..04d9e13d3c9a6 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -306,6 +306,25 @@ void getFuchsiaDefines(MacroBuilder &Builder, const LangOptions &Opts,
if (Opts.CPlusPlus)
Builder.defineMacro("_GNU_SOURCE");
Builder.defineMacro("__Fuchsia_API_level__", Twine(Opts.FuchsiaAPILevel));
+
+ // __Fuchsia_Compiler_ABI__ gives the version of the Fuchsia Compiler ABI
+ // supported by the compiler. This is a single small integer that increases
+ // monotonically for any kinds of ABI change, across any of the supported
+ // machines, and including language-specific ABI aspects such as the Fuchsia
+ // variant of the Itanium C++ ABI. Changes affecting just one machine and/or
+ // just one language will cause this single number to advance regardless.
+ //
+ // * Version 0 is the original Fuchsia Compiler ABI.
+ // - Custom SafeStack ABI on every machine
+ // - ShadowCallStack ABI on aarch64, riscv64
+ // - Itanium C++ ABI as modified: ctor/dtor return value; relative vtables
+ //
+ // * Version 1 is first iteration formalizing the version number scheme.
+ // - SafeStack ABI no longer supported on aarch64, riscv64 (x86 only)
+ //
+ // The predefine can be checked by code relying on the Fuchsia Compiler ABI
+ // to ensure that a compiler new enough for the required version is in use.
+ Builder.defineMacro("__Fuchsia_Compiler_ABI__", Twine(1));
}
} // namespace targets
diff --git a/clang/test/Preprocessor/init-fuchsia.c b/clang/test/Preprocessor/init-fuchsia.c
index 057218711b8b2..04b5ef573cc07 100644
--- a/clang/test/Preprocessor/init-fuchsia.c
+++ b/clang/test/Preprocessor/init-fuchsia.c
@@ -9,3 +9,4 @@
// FUCHSIA-DAG: #define __Fuchsia__ 1
// FUCHSIA-DAG: #define __Fuchsia_API_level__ {{[0-9]+}}
+// FUCHSIA-DAG: #define __Fuchsia_Compiler_ABI__ 1
More information about the cfe-commits
mailing list