2.6 Where __LDBL_MANT_DIG__ comes from

GCC 15.2.0. To run the commands: an installed compiler.

You configure an aarch64-rtems6 cross compiler with --with-long-double-128, because a library you port wants a 128-bit long double. The build succeeds. The library still refuses to build, because it tests __LONG_DOUBLE_128__ and that macro is not defined. You look for whatever defines it, and a grep of GCC 15 for LONG_DOUBLE_TYPE_SIZE, the macro that GCC 14 used, finds no definition. The configure flag you passed changed nothing that you can find.

Every __LDBL_* macro reports a machine mode that the target backend chose. A machine mode is GCC's name for a size and format of data, such as DImode for a 64-bit integer or DFmode for an IEEE double, and the internals manual describes the modes under Machine Modes. Your triple picks the backend. On a few GNU/Linux targets, configure can also set the default of a -m option that the backend reads, and it has no other say in these macros. cc1 defines them before it reads any input, so no header and no C library is their source.

This chapter assumes Chapter 1.2, for the target as a property fixed when the compiler is built, and Chapter 2.1, for gcc/config.gcc as the file that turns a triple into a backend. It also uses the - input file of Chapter 1.4, GCC's own <float.h> from Chapter 1.8, the configure line that gcc -v echoes from Chapter 1.14, and auto-host.h from Chapter 2.4.

Checking the predefined macros with -dM -E

gcc -dM -E on an empty input lists every macro that the compiler defined before it read a line, and it works on any installed compiler, native or cross. It is the first thing to run, because it shows what your compiler reports for long double before you go looking for the source that decided it. The first command prints the floating-point macros, the second the type sizes, and the third the effect of a -m option:

$ gcc -dM -E - < /dev/null | grep -E 'LDBL|FLT128|FLOAT128|LONG_DOUBLE'
$ gcc -dM -E - < /dev/null | grep __SIZEOF
$ gcc -mlong-double-64 -dM -E - < /dev/null | grep __LDBL_MANT_DIG__

-E with the file name - reads standard input (Chapter 1.4), and /dev/null makes that input empty. On x86_64, the first command shows a __LDBL_MANT_DIG__ of 64, and the third shows 53.

The third command needs a backend that has a -mlong-double-64 option, such as x86 or PowerPC, and the GCC manual documents the option under x86 Options and RS/6000 and PowerPC Options. AArch64, ARM and RISC-V have no such option, for a reason that the section on TARGET_C_MODE_FOR_FLOATING_TYPE gives.

-d takes a string of letters, and the GCC manual documents -dM and its siblings under Preprocessor Options. The C-family front end reads the letters in handle_OPT_d, where M sets flag_dump_macros:

/* Args to -d specify what to dump.  Silently ignore
   unrecognized options; they may be aimed at toplev.cc.  */
static void
handle_OPT_d (const char *arg)
{
  char c;

  while ((c = *arg++) != '\0')
    switch (c)
      {
      case 'M':			/* Dump macros only.  */
      case 'N':			/* Dump names.  */
      case 'D':			/* Dump definitions.  */
      case 'U':			/* Dump used macros.  */
	flag_dump_macros = c;
	break;

Listing 2.6-1: the -d letters (gcc/c-family/c-opts.cc:2054-2069).

-dM also sets flag_no_output, so cc1 writes no preprocessed text (c-opts.cc:1545-1548). At the end of the input, preprocess_file walks every identifier and prints each macro as a #define (c-ppoutput.cc:116-118). The list therefore follows every option that reaches cc1. Add -O2, which defines __OPTIMIZE__ (cppbuiltin.cc:104-105), or a -m option to the command, and the output changes with it.

The compiler proper sees -d too, and does nothing with M. Its own letter loop lists D, I, M, N and U as "handled by the preprocessor" and skips them (gcc/opts.cc:3667-3672).

c_cpp_builtins and gcc/cppbuiltin.cc: which file defines which macro

c_cpp_builtins is the C-family hook that defines the front-end and target-specific macros, and its first act is to call into gcc/cppbuiltin.cc for the macros that every preprocessing language shares. Its own file, c-family/c-cppbuiltin.cc, differs from that one by a directory and two characters, and the two greps of the -dM list land in different files. A surprising value therefore sends you to one file or the other, and the table that closes this section says which.

c_finish_options first calls cpp_init_builtins, which defines libcpp's own set, such as __STDC__ (libcpp/init.cc:584-595), and then c_cpp_builtins (c-opts.cc:1642-1643). The -D and -U options on your command line come after both calls, in the loop that follows (:1665-1674). The C-family entry point starts like this:

/* Hook that registers front end and target-specific built-ins.  */
void
c_cpp_builtins (cpp_reader *pfile)
{
  int i;

  /* -undef turns off target-specific built-ins.  */
  if (flag_undef)
    return;

  define_language_independent_builtin_macros (pfile);

Listing 2.6-2: the entry point (gcc/c-family/c-cppbuiltin.cc:902-912).

With -undef, another of the Preprocessor Options, c_cpp_builtins returns before it defines anything, so none of the __LDBL_*, __SIZEOF_*__ or target macros exist. Otherwise define_language_independent_builtin_macros runs first, and the basic type sizes are among the macros it defines. Each line reads the size of a type node, so __SIZEOF_LONG_DOUBLE__ follows long_double_type_node:

/* Define macros for size of basic C types.  */
static void
define_builtin_macros_for_type_sizes (cpp_reader *pfile)
{
#define define_type_sizeof(NAME, TYPE)                             \
    cpp_define_formatted (pfile, NAME"=" HOST_WIDE_INT_PRINT_DEC,   \
                          tree_to_uhwi (TYPE_SIZE_UNIT (TYPE)))

  define_type_sizeof ("__SIZEOF_INT__", integer_type_node);
  define_type_sizeof ("__SIZEOF_LONG__", long_integer_type_node);
  define_type_sizeof ("__SIZEOF_LONG_LONG__", long_long_integer_type_node);
  define_type_sizeof ("__SIZEOF_SHORT__", short_integer_type_node);
  define_type_sizeof ("__SIZEOF_FLOAT__", float_type_node);
  define_type_sizeof ("__SIZEOF_DOUBLE__", double_type_node);
  define_type_sizeof ("__SIZEOF_LONG_DOUBLE__", long_double_type_node);
  define_type_sizeof ("__SIZEOF_SIZE_T__", size_type_node);

Listing 2.6-3: the __SIZEOF_*__ macros (gcc/cppbuiltin.cc:143-158).

gcc/cppbuiltin.cc looks like a file of version macros, because its first function defines __GNUC__, but its own comment states a wider scope: "macros builtins common to all language performing CPP preprocessing". That covers the version, the optimisation and PIC flags, _LP64, the basic type sizes, __CHAR_BIT__ and the byte order (cppbuiltin.cc:198-207). The Fortran front end calls the same function for its own preprocessor (gcc/fortran/cpp.cc:170). The floating-point machinery is in c-family/c-cppbuiltin.cc.

The cpp manual documents what __GNUC__, __VERSION__, __OPTIMIZE__ and the __SIZEOF_*__ macros mean, under Common Predefined Macros. The table adds where each one is defined:

MacrosDefined in
__GNUC__, __VERSION__, __ATOMIC_*define__GNUC__, cppbuiltin.cc:57-74
__OPTIMIZE__, __PIC__, __FAST_MATH__cppbuiltin.cc:77-126
__SIZEOF_LONG_DOUBLE__ and the other basic sizesListing 2.6-3
__FLT_*, __DBL_*, __LDBL_*, __FLT128_*builtin_define_float_constants, in c-family/c-cppbuiltin.cc
__LONG_DOUBLE_128__, __FLOAT128__, __aarch64__the backend's TARGET_CPU_CPP_BUILTINS and TARGET_OS_CPP_BUILTINS (c-cppbuiltin.cc:1652-1659)

builtin_define_float_constants: one function, three prefixes

builtin_define_float_constants defines the float.h macros, __FLT_*, __DBL_* and __LDBL_*, and c_cpp_builtins calls it once for each standard floating type, each time with a different prefix. Nobody wrote down a __LDBL_MANT_DIG__ for long double: the value is a field of the format behind the type's machine mode. The three calls are consecutive:

  builtin_define_float_constants ("FLT", "F", "%s", "F", float_type_node);
  /* Cast the double precision constants.  This is needed when single
     precision constants are specified or when pragma FLOAT_CONST_DECIMAL64
     is used.  The correct result is computed by the compiler when using
     macros that include a cast.  We use a different cast for C++ to avoid
     problems with -Wold-style-cast.  */
  builtin_define_float_constants ("DBL", "L",
				  (c_dialect_cxx ()
				   ? "double(%s)"
				   : "((double)%s)"),
				  "", double_type_node);
  builtin_define_float_constants ("LDBL", "L", "%s", "L",
				  long_double_type_node);

Listing 2.6-4: three types, one function (gcc/c-family/c-cppbuiltin.cc:1268-1280).

Grep for the right names: the function is builtin_define_float_constants, not cpp_define_float_constants, which does not exist, and its hexadecimal helper is builtin_define_with_hex_fp_value. Inside the function, each macro name is pasted from the prefix, and the significand digits come from the format of the type's mode:

  fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
  ...
  /* The number of radix digits, p, in the floating-point significand.  */
  sprintf (name, "__%s_MANT_DIG__", name_prefix);
  builtin_define_with_int_value (name, fmt->p);

Listing 2.6-5: __LDBL_MANT_DIG__ is fmt->p, abridged (gcc/c-family/c-cppbuiltin.cc:142-166).

REAL_MODE_FORMAT maps a machine mode to a struct real_format, and p is that format's "Size of the significand in digits of radix B" (gcc/real.h:118-130). __LDBL_MAX_EXP__ comes from the same table's emax (c-cppbuiltin.cc:196-198). Four of the formats in gcc/real.cc give these values, and the mode of long_double_type_node decides which one applies:

Format in gcc/real.ccp, so __LDBL_MANT_DIG__emax, so __LDBL_MAX_EXP__
ieee_double_format531024
ieee_extended_intel_96_format, one of the x86 XFmode formats6416384
ibm_extended_format106, written 53 + 531024
ieee_quad_format11316384

The LDBL_MANT_DIG in your program is the same number under its standard name, because GCC's own <float.h> defines LDBL_MANT_DIG as __LDBL_MANT_DIG__ (gcc/ginclude/float.h:38-41). Chapter 1.8 explains why that <float.h> is the one you get.

Five of the limits, from __LDBL_MAX__ to __LDBL_DENORM_MIN__, are decimal renderings of hexadecimal constants (c-cppbuiltin.cc:260-297). A comment calls builtin_define_with_hex_fp_value, the helper that renders them, "very expensive" (:1819-1821), so the helper normally defines a placeholder and computes the value when code first uses the macro. It skips that shortcut when flag_dump_macros is set (:1880-1884), so under -dM, cc1 computes every value at once.

TARGET_C_MODE_FOR_FLOATING_TYPE: the backend picks the mode

TARGET_C_MODE_FOR_FLOATING_TYPE is the target hook that gives long double its machine mode, so it decides which format, and which __LDBL_* values, a compiler reports. A target hook is a function in targetm, the table that each backend fills in, so each target can give its own answer. The compiler calls this one when it builds its common types:

  long_double_type_node = make_node (REAL_TYPE);
  machine_mode long_double_type_mode
    = targetm.c.mode_for_floating_type (TI_LONG_DOUBLE_TYPE);
  SET_TYPE_MODE (long_double_type_node, long_double_type_mode);
  TYPE_PRECISION (long_double_type_node)
    = GET_MODE_PRECISION (long_double_type_mode).to_constant ();
  layout_type (long_double_type_node);

Listing 2.6-6: one hook call fixes long double (gcc/tree.cc:9732-9738).

targetm.c.mode_for_floating_type is the hook's entry in that table, and a backend that does not define it gets the default:

/* Return machine mode for a floating type which is indicated
   by the given enum tree_index.  */

machine_mode
default_mode_for_floating_type (enum tree_index ti)
{
  if (ti == TI_FLOAT_TYPE)
    return SFmode;
  gcc_assert (ti == TI_DOUBLE_TYPE || ti == TI_LONG_DOUBLE_TYPE);
  return DFmode;
}

Listing 2.6-7: the default (gcc/targhooks.cc:302-312).

Without the hook, long double is double, so __LDBL_MANT_DIG__ equals __DBL_MANT_DIG__, 53 for the IEEE DFmode that machmode.def declares (gcc/machmode.def:231-232). A grep of gcc/config/ in GCC 15.2.0 finds the hook in seventeen backends. ARM is not one of them, so arm-none-eabi-gcc has a 64-bit long double. AArch64 is one, and its hook returns TFmode for long double with no condition:

/* Implement TARGET_C_MODE_FOR_FLOATING_TYPE.  Return TFmode for
   TI_LONG_DOUBLE_TYPE which is for long double type, go with the default
   one for the others.  */

static machine_mode
aarch64_c_mode_for_floating_type (enum tree_index ti)
{
  if (ti == TI_LONG_DOUBLE_TYPE)
    return TFmode;
  return default_mode_for_floating_type (ti);
}
...
#undef TARGET_C_MODE_FOR_FLOATING_TYPE
#define TARGET_C_MODE_FOR_FLOATING_TYPE aarch64_c_mode_for_floating_type

Listing 2.6-8: AArch64's answer (gcc/config/aarch64/aarch64.cc:29192-29202 and :31687-31688).

AArch64 declares TFmode as FLOAT_MODE (TF, 16, ieee_quad_format) (aarch64-modes.def:260-261), so every GCC 15.2.0 AArch64 compiler reports a __LDBL_MANT_DIG__ of 113 and a __LDBL_MAX_EXP__ of 16384. No -m option and no configure flag reaches that if.

LONG_DOUBLE_TYPE_SIZE before GCC 15: a size in bits, not a mode

LONG_DOUBLE_TYPE_SIZE is how a backend set up long double up to GCC 14: it gave a size in bits, not a mode. GCC 15.1 was the first release with the hook, so advice that tells you to look for the macro predates GCC 15. AArch64 at GCC 14.3.0 set all three sizes in its header:

#define FLOAT_TYPE_SIZE		32

#define DOUBLE_TYPE_SIZE	64

#define LONG_DOUBLE_TYPE_SIZE	128

Listing 2.6-9: AArch64 at releases/gcc-14.3.0 (gcc/config/aarch64/aarch64.h:99-103).

At that tag, tree.cc copied the size into the type's precision (gcc/tree.cc:9618-9620 at 14.3.0). Commit 55947b32, "Replace {FLOAT,{,LONG_}DOUBLE}_TYPE_SIZE with new hook mode_for_floating_type", made the change in June 2024. Its message gives the reason: PowerPC has three 128-bit floating modes, and a precision alone could not say which one a type meant.

The commit also adds the three names to the poison list in system.h, so GCC's own sources can no longer use them (gcc/system.h:950-997). In GCC 15.2.0, a grep of gcc/config/ and of the files at the top of gcc/ for LONG_DOUBLE_TYPE_SIZE finds that poison list and a few comments, and no definition.

cpu_type and out_file: from the triple to aarch64.cc

config.gcc turns the triple into a cpu_type, and configure turns cpu_type into a default out_file, the backend source file that holds the hook. That chain is how the AArch64 hook gets into your compiler. For AArch64, ARM and RISC-V, it is all that decides the mode of long double, because no option reaches their answer.

config.gcc sets cpu_type=aarch64 for every aarch64*-*-* triple (config.gcc:347-348). When the target's entry sets no out_file, configure makes it $cpu_type/$cpu_type.cc (gcc/configure.ac:1946-1947). gcc/Makefile.in compiles that file (Makefile.in:2686-2688) and links it with the compiler's other objects (:1845). At its end, aarch64.cc builds the hook table from every TARGET_* macro it defined, the one in Listing 2.6-8 included:

struct gcc_target targetm = TARGET_INITIALIZER;

Listing 2.6-10: the hook table (gcc/config/aarch64/aarch64.cc:32218).

RISC-V's hook returns TFmode with no condition, as AArch64's does (riscv.cc:13097-13102). Chapter 2.1 follows config.gcc further, into the headers and makefile fragments it also selects.

--with-long-double-128: a default for -mlong-double-128

--with-long-double-128 sets the default of -mlong-double-128 and does nothing else, and only four target families read it: PowerPC, SPARC, s390 and Alpha GNU/Linux. Some backends read an option in their hook, and PowerPC is the clearest case. Its hook tests a variable, the variable has a compile-time default, and configure can set that default:

/* Implement TARGET_C_MODE_FOR_FLOATING_TYPE.  Return TFmode for
   TI_LONG_DOUBLE_TYPE which is for long double type, go with the default
   one for the others.  */

static machine_mode
rs6000_c_mode_for_floating_type (enum tree_index ti)
{
  if (ti == TI_LONG_DOUBLE_TYPE)
    return rs6000_long_double_type_size == 128 ? TFmode : DFmode;
  return default_mode_for_floating_type (ti);
}

Listing 2.6-11: PowerPC's answer depends on a variable (gcc/config/rs6000/rs6000.cc:24377-24387).

rs6000_long_double_type_size is the variable behind -mlong-double-<n> (rs6000.opt:430-433). When you do not pass that option, OPTION_SET_P is false, and the backend fills the variable in from a compile-time default:

  /* Use long double size to select the appropriate long double.  We use
     TYPE_PRECISION to differentiate the 3 different long double types.  We map
     128 into the precision used for TFmode.  */
  int default_long_double_size = (RS6000_DEFAULT_LONG_DOUBLE_SIZE == 64
				  ? 64
				  : 128);

  /* Set long double size before the IEEE 128-bit tests.  */
  if (!OPTION_SET_P (rs6000_long_double_type_size))
    {
      if (main_target_opt != NULL
	  && (main_target_opt->x_rs6000_long_double_type_size
	      != default_long_double_size))
	error ("target attribute or pragma changes %<long double%> size");
      else
	rs6000_long_double_type_size = default_long_double_size;
    }

Listing 2.6-12: the default, used only without -mlong-double- (gcc/config/rs6000/rs6000.cc:4105-4121).

RS6000_DEFAULT_LONG_DOUBLE_SIZE is 64 unless a target header says otherwise (rs6000.cc:3385-3390). The GNU/Linux headers set it to 128 when configure defined TARGET_DEFAULT_LONG_DOUBLE_128 (rs6000/linux64.h:535-538, and the same in rs6000/linux.h:136-139). configure defines it here:

# Check if TFmode long double should be used by default or not.
# Some glibc targets used DFmode long double, but with glibc 2.4
# and later they can use TFmode.
case "$target" in
  powerpc*-*-linux* | \
  sparc*-*-linux* | \
  s390*-*-linux* | \
  alpha*-*-linux*)
    AC_ARG_WITH(long-double-128,

Listing 2.6-13: four target families (gcc/configure.ac:7031-7039).

The install manual documents the flag under Configuration, for "selected GNU/Linux architectures". Without the flag, the default comes from the target C library, and is 128 bits for glibc 2.4 or later. For an older or absent glibc it is 64 bits, unless the target's bits/wordsize.h defines __LONG_DOUBLE_MATH_OPTIONAL. musl gets a fixed answer, 128 bits on s390 and 64 on PowerPC (configure.ac:7042-7060).

configure records a yes as TARGET_DEFAULT_LONG_DOUBLE_128 (configure.ac:7063-7066), in the auto-host.h header that it writes (:29) and Chapter 2.4 covers. SPARC, s390 and Alpha read it as PowerPC does: each sets its MASK_LONG_DOUBLE_128 when you did not choose (sparc.cc:1977-1980, s390.cc:16464-16467, alpha.cc:603-606).

A 128-bit PowerPC long double has a second choice to make, its format. The mode table declares TFmode as IEEE quad, and the backend switches it to IBM double-double unless -mabi=ieeelongdouble is in effect (rs6000-modes.def:41-46, rs6000.cc:4561-4562). On PowerPC GNU/Linux the default is IBM (rs6000.cc:98-104), and --with-long-double-format=ieee or =ibm changes that default through tm_defines (config.gcc:5743-5749).

One PowerPC compiler can therefore report a __LDBL_MANT_DIG__ of 53, 106 or 113, from two options and two configure defaults. The install manual documents --with-long-double-format next to --with-long-double-128, and the GCC manual documents -mabi=ieeelongdouble under RS/6000 and PowerPC Options.

--with-long-double-128 on aarch64-rtems6: accepted, then ignored

On aarch64-rtems6, configure accepts --with-long-double-128 with no warning and then ignores it, because configure reads the value only for PowerPC, SPARC, s390 and Alpha GNU/Linux. The flag therefore has no effect on that compiler, and only the configure line that gcc -v echoes (Chapter 1.14) shows that you passed it.

Autoconf lists the option among the ones the generated gcc/configure knows, for every target (gcc/configure:1046), although AC_ARG_WITH sits inside the case of Listing 2.6-13. configure therefore never gives its "unrecognized options" warning for it (:1501-1506), and reads the value only inside the generated case (:33509-33520).

--with-long-double-format has a case of its own, which stops configure with an error on any target that is not 64-bit PowerPC GNU/Linux (configure.ac:7097-7101). The two flags sit 34 lines apart in configure.ac and fail in opposite ways.

For five common targets, the mode of long double and what can change it are as follows:

Targetlong double mode__LDBL_MANT_DIG__What can change it
aarch64-*TFmode, always113nothing
riscv*-*TFmode, always (riscv-modes.def:23)113nothing
arm-*DFmode, the default53nothing
x86_64-*XFmode, or DFmode or TFmode (i386.cc:26306-26317)64-mlong-double-64 gives 53, -mlong-double-128 gives 113 (i386.opt:223-233)
powerpc64le-*-linux*TFmode or DFmode (Listing 2.6-11)106 with glibc 2.4 or later-mlong-double-64, -mabi=ieeelongdouble, and the two configure defaults

__LONG_DOUBLE_128__ and __FLOAT128__ follow backend options

__LONG_DOUBLE_128__ and __FLOAT128__ report backend options, not the width of a type, so a library that tests them gets the wrong answer on AArch64. They are not float.h constants, and builtin_define_float_constants never defines them. Each backend defines its own macros in TARGET_CPU_CPP_BUILTINS or TARGET_OS_CPP_BUILTINS, which c_cpp_builtins expands (c-cppbuiltin.cc:1652-1659).

In GCC 15.2.0, __LONG_DOUBLE_128__ has five definitions in gcc/config/:

BackendDefinitionCondition
PowerPCrs6000-c.cc:706-708TARGET_LONG_DOUBLE_128
s390s390-c.cc:427-428TARGET_LONG_DOUBLE_128
x86i386-c.cc:916-917TARGET_LONG_DOUBLE_128, set by -mlong-double-128
Alphaalpha.h:68-69TARGET_LONG_DOUBLE_128
SPARC GNU/Linuxsparc/linux.h:25-26, and sparc/linux64.h:27-29 for 32-bit codeTARGET_LONG_DOUBLE_128

Every condition tests the backend's own 128-bit switch, not the width of the type, so __LONG_DOUBLE_128__ means "this backend's -mlong-double-128 is on", not "long double is 128 bits". AArch64 and RISC-V have no such switch and never define the macro, although their long double is always 128 bits. To test the format, test __LDBL_MANT_DIG__. __SIZEOF_LONG_DOUBLE__ gives the storage only, and storage is not format: on x86_64, "XFmode has size and alignment 16" for its 64-bit significand (i386-modes.def:30-38).

__FLOAT128__ has one definition in all of gcc/config/, in the PowerPC backend:

  if ((flags & OPTION_MASK_FLOAT128_KEYWORD) != 0)
    {
      rs6000_define_or_undefine_macro (define_p, "__FLOAT128__");

Listing 2.6-14: the only __FLOAT128__ (gcc/config/rs6000/rs6000-c.cc:567-569).

The macro follows the __float128 keyword, which the GCC manual documents under Additional Floating Types, and which -mfloat128 controls (rs6000.opt:544-546). On GNU/Linux with VSX, the backend turns the keyword on by default (rs6000.cc:4157-4162 and :4183-4186). The x86 backend has __float128 too (extend.texi:238-242) but never defines __FLOAT128__, and defines __SIZEOF_FLOAT128__ instead, with no condition (i386-c.cc:922). libquadmath appears in neither condition, so cc1's options decide __FLOAT128__, and whether libquadmath was built cannot change it.

The portable test for a quad type is __FLT128_MANT_DIG__, because c_cpp_builtins runs builtin_define_float_constants for each _FloatN type that exists (c-cppbuiltin.cc:1282-1301). tree.cc creates _Float128 only if targetm.floatn_mode returns a mode (tree.cc:9740-9752). The default hook returns TFmode when its format is IEEE binary128 and the backend supports the mode (targhooks.cc:584-597). On AArch64, that is the TFmode of Listing 2.6-8.

__LIBGCC_* and -fbuilding-libgcc: macros for libgcc only

c_cpp_builtins defines the __LIBGCC_* macros only under -fbuilding-libgcc, so an ordinary -dM dump shows none of them. They come from the block of c_cpp_builtins that tests whether the backend supports each floating mode, and libgcc is their one reader:

  /* For libgcc-internal use only.  */
  if (flag_building_libgcc)
    {
      ...
	  sprintf (macro_name, "__LIBGCC_%s_MANT_DIG__", name);
	  builtin_define_with_int_value (macro_name,
					 REAL_MODE_FORMAT (mode)->p);
	  if (!targetm.scalar_mode_supported_p (mode)
	      || !targetm.libgcc_floating_mode_supported_p (mode))
	    continue;

Listing 2.6-15: macros for libgcc only, abridged (gcc/c-family/c-cppbuiltin.cc:1380-1398).

The loop visits every floating mode the compiler knows, and each one gets its __LIBGCC_<mode>_MANT_DIG__. Only the modes that pass both hooks go on to get __LIBGCC_HAS_<mode>_MODE__ (c-cppbuiltin.cc:1399-1402). -fbuilding-libgcc is marked Undocumented (c.opt:1707-1708), and libgcc's makefile passes it (libgcc/Makefile.in:248-251). libgcc2.h tests __LIBGCC_HAS_TF_MODE__ and its siblings (libgcc/libgcc2.h:40-68), and Chapter 4.1 covers what libgcc is for.

Three things to carry away

__LDBL_MANT_DIG__ is the p of the format behind the mode that the backend picked. TARGET_C_MODE_FOR_FLOATING_TYPE picks the mode, and builtin_define_float_constants prints the format's fields.

configure picks the backend, and on a few targets the default of a -m option. --with-long-double-128 is that default on PowerPC, SPARC, s390 and Alpha GNU/Linux. On every other target, configure accepts it with no warning and ignores it.

Test __LDBL_MANT_DIG__, not __LONG_DOUBLE_128__ or __FLOAT128__. Those two report backend options, and AArch64 defines neither.

Things that surprise people

A PowerPC GNU/Linux compiler configured without target headers gets a 64-bit long double. With no --with-glibc-version and no target features.h to read, configure takes the glibc version as 0.0 (configure.ac:6019-6037), and the default of Listing 2.6-13 falls to 64 bits. Pass --with-long-double-128 when you build that compiler before its C library.

-D__LDBL_MANT_DIG__=64 changes a macro, not a type. Your -D options run after c_cpp_builtins (c-opts.cc:1665-1674), so they overwrite the report. The type still comes from Listing 2.6-6.

Documentation coverage

The cpp manual lists the generic macros in Common Predefined Macros (gcc/doc/cpp.texi:1930, with __SIZEOF_LONG_DOUBLE__ at :2266). Target macros such as __aarch64__ belong to System-specific Predefined Macros (cpp.texi:2497), which sends you to cpp -dM for the list. -dM is in Preprocessor Options (gcc/doc/cppopts.texi:519-532, included at invoke.texi:19004). The configure flags are on the install manual's Configuration page (gcc/doc/install.texi:2438 for --with-long-double-128, :2446 for --with-long-double-format). The -mlong-double-* options are under RS/6000 and PowerPC Options (invoke.texi:33337) and x86 Options (:35723). The targets that have __float128 and _Float128 are listed in Additional Floating Types (gcc/doc/extend.texi:238-279). The hook is in the internals manual's Storage Layout node (gcc/doc/tm.texi:1047).

What is not documented:

  • Any __FLT_*, __DBL_* or __LDBL_* macro, or __LONG_DOUBLE_128__, or __FLOAT128__. No .texi file in GCC 15.2.0 names them.
  • That their values follow the backend's choice of mode, and that no configure flag changes them on most targets.
  • Which four target families read --with-long-double-128. The install manual says "selected GNU/Linux architectures" (install.texi:2439-2440), and does not say that other targets accept the flag and ignore it.
  • That __LONG_DOUBLE_128__ follows a -m switch, so AArch64 and RISC-V never define it.

Three statements in the GCC 15.2.0 manuals do not match the source:

  • The install manual names a --with-long-double-64 (install.texi:2455). Neither gcc/configure.ac nor gcc/config.gcc reads such an option. The spelling that works is --without-long-double-128.
  • cppopts.texi:535-536 says that -dM without -E means -fdump-rtl-mach. The compiler proper skips the M letter and turns on no RTL dump (opts.cc:3667-3672). RTL, the representation that describes the target's instructions, is explained in Chapter 5.1.
  • extend.texi:264-267 says that PowerPC GNU/Linux needs -mfloat128 for __float128. The backend turns it on by default with VSX, as invoke.texi:32224-32225 says.

Next: Chapter 3.1, The libgcc–libc cycle: make all-gcc and the three cross recipes, on why a cross compiler and its C library each need the other to exist first, and the three recipes that break that cycle.