This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: Handle BSD4.4 <stdio.h> vs. attribute format checking
- From: Loren James Rittle <rittle at latour dot rsch dot comm dot mot dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 28 Jun 2002 16:54:21 -0500 (CDT)
- Subject: PATCH: Handle BSD4.4 <stdio.h> vs. attribute format checking
- Reply-to: rittle at labs dot mot dot com
Joseph was kind enough to give me private feedback on how to fix these
failures back in mid-March, but it took me until early June to get it
right for at least one port (and in general, I hope). It has been in
my tree since then. But, of course, I'd like to commit the broadest
fix possible since other ports started with the same system headers
and display the exact same issue.
This patch fixes:
FAIL: gcc.dg/format/c99-scanf-3.c vfscanf (test for warnings, line 21)
FAIL: gcc.dg/format/c99-scanf-3.c vfscanf (test for warnings, line 21)
FAIL: gcc.dg/format/ext-6.c vfscanf (test for warnings, line 42)
FAIL: gcc.dg/format/ext-6.c vfscanf (test for warnings, line 42)
on *-unknown-freebsd* and should also help other platforms using
system headers derived from BSD4.4 sources. Applications that include
proper system headers actually saw no issue as exposed by the test
cases; but the cc1 binary, as built, contained an ATTR for __svfscanf
instead of vfscanf (used to support -Wformat).
Tested on *-*-freebsd4.6 via full bootstrap/check cycle. No
regressions. cc1 binary, as built, noted to now contain proper
reference to ATTR_vfscanf instead of errant ATTR___svfscanf. This
should also address recently reported similar issue with NetBSD (and
testresults-only reported issue seen on OpenBSD; Darwin situation
unknown since they don't *ever* post test results).
Reasoning to support this exact fix: I suggested to Joseph that I
convert the macro to an inline function to generate a proper point for
the compiler to attach the attribute and allow proper pickup of symbol
name within c-common.c (but subtly breaks ABI in corner cases). He
suggested conversion from simple macro to function-like macro (but
-Wformat attribute checking occurs after preprocessor thus although
the test cases are fixed, real code using the system headers fail to
be checked properly). Neither solution handles all cases. Using the
__asm__ renaming upon definition trick looked promising. To work for
all affected ports semi-automatically appeared to require using
__USER_LABEL_PREFIX__ along with the convert-to-string trick.
Comments in various locations suggest using __gnu_va_list in fixed
headers instead of va_list. Of course, this makes perfect sense given
the rules of ISO C (only <stdarg.h> may expose the user-level name for
that type). However, I had to use __builtin_va_list since during
bootstrap, the compiler starts using the fixed <stdio.h> before other
headers were staged into gcc/include.
Perhaps the best fix would be to arrange for all such ATTR structures
to be assembled outside the presence of any system header pollution.
That is a major structural change to the compiler...
OK for mainline? Comments from other port maintainers using BSD4.4
system headers on why this might break you? In particular, does
Darwin need this fix or should I remove the special mach line I
proposed adding for your port? (Aside, could someone from that camp
please post dejagnu results once and awhile?)
* fixinc/inclhack.def (bsd_stdio_attrs_conflict): New.
* fixinc/fixincl.x: Rebuilt.
Index: fixinc/inclhack.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fixinc/inclhack.def,v
retrieving revision 1.133
diff -c -r1.133 inclhack.def
*** fixinc/inclhack.def 2 Jun 2002 23:17:30 -0000 1.133
--- fixinc/inclhack.def 14 Jun 2002 04:03:11 -0000
***************
*** 836,841 ****
--- 836,860 ----
/*
+ * Various systems derived from BSD4.4 contain a macro definition
+ * for vfscanf that interacts badly with requirements of builtin-attrs.def.
+ */
+ fix = {
+ hackname = bsd_stdio_attrs_conflict;
+ mach = *-*-*bsd*;
+ mach = *-*-*darwin*;
+ files = stdio.h;
+ select = "^#define[ \t]*vfscanf[ \t]*__svfscanf[ \t]*$";
+ c_fix = format;
+ c_fix_arg = '#define _BSD_STRING(_BSD_X) _BSD_STRINGX(_BSD_X)' "\n"
+ '#define _BSD_STRINGX(_BSD_X) #_BSD_X' "\n"
+ 'int vfscanf(FILE *, const char *, __builtin_va_list) '
+ '__asm__ (_BSD_STRING(__USER_LABEL_PREFIX__) "__svfscanf");';
+ test_text = '#define vfscanf __svfscanf';
+ };
+
+
+ /*
* check for broken assert.h that needs stdio.h
*/
fix = {