printflike vs kprintflike

Alexander Kabaev kan at freebsd.org
Wed May 4 19:56:12 PDT 2005


On Wed, May 04, 2005 at 06:16:06PM -0400, Jeff Roberson wrote:
> I have a patch from Neal Fachan of isilon that implements a new gcc
> attribute 'kprintflike' that is used in place of 'printflike' in the
> kernel.  This is done to stop us from leaking kernel printf formats into
> userspace.  Apparently -fformat-extensions is broken in gcc3.  This also
> stops our formats from leaking into any other custom formats defined in
> gcc.
> 

I would like to avoid introduction of a new printf attribute if possible.
Does fixed -fformat-extensions suffice your needs? If so, can you try the
patch below instead?


Index: c-common.h
===================================================================
RCS file: /home/ncvs/src/contrib/gcc/c-common.h,v
retrieving revision 1.7
diff -u -r1.7 c-common.h
--- c-common.h	28 Jul 2004 03:46:02 -0000	1.7
+++ c-common.h	5 May 2005 02:45:10 -0000
@@ -840,6 +840,9 @@
 /* Nonzero means the expression being parsed will never be evaluated.
    This is a count, since unevaluated expressions can nest.  */
 
+/* Nonzero allows FreeBSD kenrel-specific printf formats.  */
+extern int flag_format_extensions;
+
 extern int skip_evaluation;
 
 /* C types are partitioned into three subsets: object, function, and
Index: c-format.c
===================================================================
RCS file: /home/ncvs/src/contrib/gcc/c-format.c,v
retrieving revision 1.9
diff -u -r1.9 c-format.c
--- c-format.c	28 Jul 2004 03:57:21 -0000	1.9
+++ c-format.c	5 May 2005 02:33:31 -0000
@@ -257,7 +257,8 @@
   STD_C94,
   STD_C9L, /* C99, but treat as C89 if -Wno-long-long.  */
   STD_C99,
-  STD_EXT
+  STD_EXT,
+  STD_BSD
 };
 
 /* The C standard version C++ is treated as equivalent to
@@ -785,9 +786,9 @@
      ("%6D", ptr, ":")		-> XX:XX:XX:XX:XX:XX
      ("%*D", len, ptr, " ")	-> XX XX XX XX ...
    */
-  { "D",   1, STD_EXT, { T89_C,  BADLEN,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "-wp",      "cR" },
-  { "b",   1, STD_EXT, { T89_C,  BADLEN,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "-wp",      ""   },
-  { "ry",  0, STD_EXT, { T89_I,  BADLEN,   BADLEN,   T89_L,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "-wp0 +#",  "i"  },
+  { "D",   1, STD_BSD, { T89_C,  BADLEN,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "-wp",      "cR" },
+  { "b",   1, STD_BSD, { T89_C,  BADLEN,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "-wp",      ""   },
+  { "ry",  0, STD_BSD, { T89_I,  BADLEN,   BADLEN,   T89_L,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "-wp0 +#",  "i"  },
   { NULL,  0, 0, NOLENGTHS, NULL, NULL }
 };
 
@@ -2091,7 +2092,8 @@
       format_chars++;
       fci = fki->conversion_specs;
       while (fci->format_chars != 0
-	     && strchr (fci->format_chars, format_char) == 0)
+	     && (strchr (fci->format_chars, format_char) == 0 ||
+	        (!flag_format_extensions && fci->std == STD_BSD)))
 	  ++fci;
       if (fci->format_chars == 0)
 	{
Index: c-opts.c
===================================================================
RCS file: /home/ncvs/src/contrib/gcc/c-opts.c,v
retrieving revision 1.2
diff -u -r1.2 c-opts.c
--- c-opts.c	29 Jul 2004 02:04:58 -0000	1.2
+++ c-opts.c	5 May 2005 02:41:26 -0000
@@ -1047,6 +1047,7 @@
       break;
 
     case OPT_fformat_extensions:
+      flag_format_extensions = value;
       break;
     }
 


More information about the freebsd-arch mailing list