git: 91431b0114be - main - devel/freebsd-gcc12: Fix support for FreeBSD kernel printf.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Fri, 18 Nov 2022 21:38:00 UTC
The branch main has been updated by jhb (doc, src committer):

URL: https://cgit.FreeBSD.org/ports/commit/?id=91431b0114be7f4c380829f1ff7c4f9252adbba1

commit 91431b0114be7f4c380829f1ff7c4f9252adbba1
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-11-18 21:37:25 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-11-18 21:37:25 +0000

    devel/freebsd-gcc12: Fix support for FreeBSD kernel printf.
    
    Remove -fformat-extensions and instead follow clang and add a new
    format type: __freebsd_kprintf__.  This permits removing unsupported
    width specifies such as 'D' which conflict with the local %D specifier
    used in the kernel which the old -fformat-extensions did not handle.
---
 devel/freebsd-gcc12/Makefile                       |   1 +
 .../files/patch-freebsd-format-extensions          | 101 ++++++++++-----------
 2 files changed, 50 insertions(+), 52 deletions(-)

diff --git a/devel/freebsd-gcc12/Makefile b/devel/freebsd-gcc12/Makefile
index 7727bf99aa44..4a9bd5abe2e2 100644
--- a/devel/freebsd-gcc12/Makefile
+++ b/devel/freebsd-gcc12/Makefile
@@ -1,5 +1,6 @@
 PORTNAME=	gcc
 PORTVERSION=	12.1.0
+PORTREVISION=	1
 CATEGORIES=	devel
 MASTER_SITES=	GCC
 PKGNAMEPREFIX=	${TARGETARCH}-
diff --git a/devel/freebsd-gcc12/files/patch-freebsd-format-extensions b/devel/freebsd-gcc12/files/patch-freebsd-format-extensions
index 197ba7fa50d8..7bce7950c4db 100644
--- a/devel/freebsd-gcc12/files/patch-freebsd-format-extensions
+++ b/devel/freebsd-gcc12/files/patch-freebsd-format-extensions
@@ -1,15 +1,48 @@
 --- gcc/c-family/c-format.cc.orig	2022-05-06 00:30:56.000000000 -0700
-+++ gcc/c-family/c-format.cc	2022-05-20 13:56:43.632917000 -0700
-@@ -721,6 +721,26 @@ static const format_char_info print_char_table[] =
++++ gcc/c-family/c-format.cc	2022-11-18 11:27:29.832693000 -0800
+@@ -496,6 +496,17 @@ static const format_length_info printf_length_specs[] 
+   { NO_FMT, NO_FMT, 0 }
+ };
+ 
++static const format_length_info freebsd_kprintf_length_specs[] =
++{
++  { "h", FMT_LEN_h, STD_C89, "hh", FMT_LEN_hh, STD_C99, 0 },
++  { "l", FMT_LEN_l, STD_C89, "ll", FMT_LEN_ll, STD_C9L, 0 },
++  { "q", FMT_LEN_ll, STD_EXT, NO_FMT, 0 },
++  { "z", FMT_LEN_z, STD_C99, NO_FMT, 0 },
++  { "t", FMT_LEN_t, STD_C99, NO_FMT, 0 },
++  { "j", FMT_LEN_j, STD_C99, NO_FMT, 0 },
++  { NO_FMT, NO_FMT, 0 }
++};
++
+ /* Length specifiers valid for asm_fprintf.  */
+ static const format_length_info asm_fprintf_length_specs[] =
+ {
+@@ -721,6 +732,41 @@ static const format_char_info print_char_table[] =
    { NULL,  0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
  };
  
-+static const format_char_info fbsd_ext_char_info =
++static const format_char_info freebsd_ext_char_info =
 +{ NULL,   1, STD_EXT, { T89_C,  BADLEN,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN, BADLEN }, "",      "cR", NULL };
 +
-+static const format_char_info fbsd_print_char_table[] =
++static const format_char_info freebsd_kprintf_char_table[] =
 +{
-+  /* BSD conversion specifiers.  */
++  /* C89 conversion specifiers.  */
++  { "di",  0, STD_C89, { T89_I,   T99_SC,  T89_S,   T89_L,   T9L_LL,  TEX_LL,  T99_SST, T99_PD,  T99_IM,  BADLEN,  BADLEN,  BADLEN  }, "-wp0 +'I",  "i",  NULL },
++  { "oxX", 0, STD_C89, { T89_UI,  T99_UC,  T89_US,  T89_UL,  T9L_ULL, TEX_ULL, T99_ST,  T99_UPD, T99_UIM, BADLEN,  BADLEN,  BADLEN }, "-wp0#",     "i",  NULL },
++  { "u",   0, STD_C89, { T89_UI,  T99_UC,  T89_US,  T89_UL,  T9L_ULL, TEX_ULL, T99_ST,  T99_UPD, T99_UIM, BADLEN,  BADLEN,  BADLEN }, "-wp0'I",    "i",  NULL },
++  { "fgG", 0, STD_C89, { T89_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T89_LD,  BADLEN,  BADLEN,  BADLEN,  T2X_D32, T2X_D64, T2X_D128 }, "-wp0 +#'I", "",   NULL },
++  { "eE",  0, STD_C89, { T89_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T89_LD,  BADLEN,  BADLEN,  BADLEN,  T2X_D32, T2X_D64, T2X_D128 }, "-wp0 +#I",  "",   NULL },
++  { "c",   0, STD_C89, { T89_I,   BADLEN,  BADLEN,  T94_WI,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-w",        "",   NULL },
++  { "s",   1, STD_C89, { T89_C,   BADLEN,  BADLEN,  T94_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-wp",       "cR", NULL },
++  { "p",   1, STD_C89, { T89_V,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-w",        "c",  NULL },
++  { "n",   1, STD_C89, { T89_I,   T99_SC,  T89_S,   T89_L,   T9L_LL,  BADLEN,  T99_SST, T99_PD,  T99_IM,  BADLEN,  BADLEN,  BADLEN }, "",          "W",  NULL },
++  /* C99 conversion specifiers.  */
++  { "F",   0, STD_C99, { T99_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  T2X_D32, T2X_D64, T2X_D128 }, "-wp0 +#'I", "",   NULL },
++  { "aA",  0, STD_C99, { T99_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  T2X_D32, T2X_D64,  T2X_D128 }, "-wp0 +#",   "",   NULL },
++  /* X/Open conversion specifiers.  */
++  { "C",   0, STD_EXT, { TEX_WI,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-w",        "",   NULL },
++  { "S",   1, STD_EXT, { TEX_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-wp",       "R",  NULL },
 +  /* FreeBSD kernel extensions (src/sys/kern/subr_prf.c).
 +     The format %b is supported to decode error registers.
 +     Its usage is:	printf("reg=%b\n", regval, "<base><arg>*");
@@ -18,8 +51,8 @@
 +     ("%6D", ptr, ":")		-> XX:XX:XX:XX:XX:XX
 +     ("%*D", len, ptr, " ")	-> XX XX XX XX ...
 +   */
-+  { "D",   1, STD_EXT, { T89_V,  BADLEN,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-wp",      "cR", &fbsd_ext_char_info },
-+  { "b",   0, STD_EXT, { T89_I,  BADLEN,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "-wp",      "",   &fbsd_ext_char_info },
++  { "D",   1, STD_EXT, { T89_V,  BADLEN,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-wp",      "cR", &freebsd_ext_char_info },
++  { "b",   0, STD_EXT, { T89_I,  BADLEN,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "-wp",      "",   &freebsd_ext_char_info },
 +  { "ry",  0, STD_EXT, { T89_I,  BADLEN,   BADLEN,   T89_L,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "-wp0 +#",  "i",  NULL  },
 +  { NULL,  0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
 +};
@@ -27,7 +60,7 @@
  static const format_char_info asm_fprintf_char_table[] =
  {
    /* C89 conversion specifiers.  */
-@@ -991,6 +1011,12 @@ static const format_kind_info format_types_orig[] =
+@@ -991,6 +1037,18 @@ static const format_kind_info format_types_orig[] =
      strfmon_flag_specs, strfmon_flag_pairs,
      FMT_FLAG_ARG_CONVERT, 'w', '#', 'p', 0, 'L', 0,
      NULL, NULL
@@ -36,11 +69,17 @@
 +    printf_flag_specs, printf_flag_pairs,
 +    FMT_FLAG_ARG_CONVERT|FMT_FLAG_DOLLAR_MULTIPLE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_EMPTY_PREC_OK|FMT_FLAG_NULL_FORMAT_OK,
 +    'w', 0, 'p', 0, 'L', 0,
++    &integer_type_node, &integer_type_node
++  },
++  { "freebsd_kprintf",  freebsd_kprintf_length_specs,  freebsd_kprintf_char_table, " +#0-'", NULL,
++    printf_flag_specs, printf_flag_pairs,
++    FMT_FLAG_ARG_CONVERT|FMT_FLAG_DOLLAR_MULTIPLE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_EMPTY_PREC_OK,
++    'w', 0, 'p', 0, 'L', 0,
 +    &integer_type_node, &integer_type_node
    }
  };
  
-@@ -1635,6 +1661,9 @@ check_format_arg (void *ctx, tree format_tree,
+@@ -1635,6 +1693,9 @@ check_format_arg (void *ctx, tree format_tree,
  
    if (integer_zerop (format_tree))
      {
@@ -50,37 +89,8 @@
        /* Skip to first argument to check, so we can see if this format
  	 has any arguments (it shouldn't).  */
        while (arg_num + 1 < info->first_arg_num)
-@@ -2465,6 +2494,13 @@ argument_parser::read_any_length_modifier ()
-   while (fli->name != 0
- 	 && strncmp (fli->name, format_chars, strlen (fli->name)))
-     fli++;
-+
-+  /* Make sure FreeBSD's D format char takes preference over new DD
-+     length specifier if FreeBSD format extensions are requested.  */
-+  if (fli->index == FMT_LEN_D && flag_format_extensions
-+      && fki->conversion_specs == print_char_table)
-+    while (fli->name != 0)
-+      fli++;
-   if (fli->name != 0)
-     {
-       format_chars += strlen (fli->name);
-@@ -2537,6 +2573,14 @@ argument_parser::find_format_char_info (char format_ch
-   while (fci->format_chars != 0
- 	 && strchr (fci->format_chars, format_char) == 0)
-     ++fci;
-+  if (fci->format_chars == 0 && flag_format_extensions
-+      && fki->conversion_specs == print_char_table)
-+    {
-+      fci = fbsd_print_char_table;
-+      while (fci->format_chars != 0
-+	     && strchr (fci->format_chars, format_char) == 0)
-+	++fci;
-+    }
-   if (fci->format_chars == 0)
-     {
-       format_warning_at_char (format_string_loc, format_string_cst,
 --- gcc/c-family/c-format.h.orig	2022-05-06 00:30:56.000000000 -0700
-+++ gcc/c-family/c-format.h	2022-05-20 13:56:43.633782000 -0700
++++ gcc/c-family/c-format.h	2022-11-17 17:31:38.546594000 -0800
 @@ -77,11 +77,12 @@ enum
    FMT_FLAG_DOLLAR_GAP_POINTER_OK = 128,
    /* The format arg is an opaque object that will be parsed by an external
@@ -95,16 +105,3 @@
  };
  
  /* Structure describing a length modifier supported in format checking, and
---- gcc/config/freebsd.opt.orig	2022-05-06 00:30:56.000000000 -0700
-+++ gcc/config/freebsd.opt	2022-05-20 13:56:43.634497000 -0700
-@@ -34,6 +34,10 @@ Driver JoinedOrMissing
- defsym=
- Driver JoinedOrMissing
- 
-+fformat-extensions
-+Common Var(flag_format_extensions) Init(0)
-+Allow FreeBSD kernel-specific printf format specifiers.
-+
- posix
- Driver
-