public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* improve stdint.h handling for VxWorks
@ 2017-06-12  9:17 Olivier Hainque
  2017-06-12 11:19 ` Nathan Sidwell
  0 siblings, 1 reply; 3+ messages in thread
From: Olivier Hainque @ 2017-06-12  9:17 UTC (permalink / raw)
  To: GCC Patches, Nathan Sidwell; +Cc: Douglas B Rupp, Joel Brobecker, Joseph Myers

[-- Attachment #1: Type: text/plain, Size: 3203 bytes --]

Building a powerpc-wrs-vxworks compiler with a very recent mainline
fails with numerous instances or error like:

In file included from <prefix>/powerpc-wrs-vxworks/sys-include/types/vxTypesOld.h:123:0,
                 from <build-dir>/gcc/include-fixed/stdint.h:16,
                 from <prefix>/powerpc-wrs-vxworks/sys-include/types/vxANSI.h:59,
                 from <build-dir>/gcc/include-fixed/stdio.h:84,
                 from <src-dir>/libgcc/../gcc/tsystem.h:87,
                 from <src-dir>/libgcc/unwind-dw2.c:26:
<prefix>/powerpc-wrs-vxworks/sys-include/base/e_vxTypesOld.h:260:5: error: unknown type name 'int8_t'

Note that stdint.h is picked from <build-dir>/gcc/include-fixed.

There are several issues with fixincludes for VxWorks and I'll come to those
later. The one we hit here suggests more generally that the current handling
of stdint.h needs to be improved.

Indeed, the current "hack" (in fixincludes parlance) for stdint on VxWorks has
become incorrect, as it produces a stdint.h file which starts with:

     /* get int*_t, uint*_t */
     #include <types/vxTypes.h>

This doesn't work in general as on the VxWorks end (looking at 6.9),
we apparently have the opposite expectation in types/vxTypes.h, via

  #ifdef _WRS_KERNEL
  #include <types/vxANSI.h>       /* includes kernel's stdint.h */

The proposal here is to remove the fixincludes hack and have gcc provide
stdint.h instead. The attached patch does this by setting use_gcc_stdint to
"provide" in config.gcc and adding vxworks-stdint.h, crafted by looking at
the definitions of the relevant types in headers from a number of VxWorks
installations (version and target variants).

Thanks to Doug Rupp for the in investigation and work involved.


An alternative resolution to the immediate build issue would be to just remove
the fixincludes hack. We are observing numerous testsuite failures afterwards
in this setup, however, as we then rely on the system stdint.h in this case
and it misses at least some macro definitions in some configurations.

This, in principle, should be solvable with alternative fixincludes hacks,
as suggested by https://gcc.gnu.org/ml/gcc/2004-11/msg00254.html.

Getting this right for the wide range of VxWorks variants is tedious and
error prone though, and it seems much simpler to just override consistently
with a gcc provided version.

The proposed patch both fixes the build issues and addresses the shortcomings
of VxWorks' stdint.h that we have observed, curing hundreds of test failures
in our nightly testsuite runs, on both vx6 and vx7.

It also provides a vxworks-stdint.h file, which recent comments on bug 448
suggest was missing. See e.g.

  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=448#c31

(Joseph cc'ed).

Nathan, how does this look to you ?

Thanks in advance,

With Kind Regards,

Olivier

2017-06-12  Doug Rupp <rupp@adacore.com>

	gcc/
	* config.gcc (*-*-vxworks*): Set use_gcc_stdint to "provide".
	Append vxworks-stdint.h to the tm_file list.
	* config/vxworks-stdint.h: New file.

	fixincludes/
	* inclhack.def (AAB_vxworks_stdint): Remove hack.
	* fixincl.x: Regenerate.


[-- Attachment #2: vx-stdint.diff --]
[-- Type: application/octet-stream, Size: 12585 bytes --]

Index: gcc/config.gcc
===================================================================
--- gcc/config.gcc	(revision 248832)
+++ gcc/config.gcc	(working copy)
@@ -917,6 +917,8 @@
   xm_defines=POSIX
   extra_options="${extra_options} vxworks.opt"
   extra_objs="$extra_objs vxworks.o"
+  use_gcc_stdint=provide
+  tm_file="${tm_file} vxworks-stdint.h"
   case ${enable_threads} in
     no) ;;
     "" | yes | vxworks) thread_file='vxworks' ;;
Index: gcc/config/vxworks-stdint.h
===================================================================
--- gcc/config/vxworks-stdint.h	(revision 0)
+++ gcc/config/vxworks-stdint.h	(revision 0)
@@ -0,0 +1,53 @@
+/* Definitions for <stdint.h> types on systems using VxWorks.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#define SIG_ATOMIC_TYPE "unsigned char"
+
+#define INT8_TYPE "signed char"
+#define INT16_TYPE "short int"
+#define INT32_TYPE "int"
+#define INT64_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "long long int")
+#define UINT8_TYPE "unsigned char"
+#define UINT16_TYPE "short unsigned int"
+#define UINT32_TYPE "unsigned int"
+#define UINT64_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "long long unsigned int")
+#define INT_LEAST8_TYPE "signed char"
+#define INT_LEAST16_TYPE "short int"
+#define INT_LEAST32_TYPE "int"
+#define INT_LEAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "long long int")
+#define UINT_LEAST8_TYPE "unsigned char"
+#define UINT_LEAST16_TYPE "short unsigned int"
+#define UINT_LEAST32_TYPE "unsigned int"
+#define UINT_LEAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "long long unsigned int")
+#define INT_FAST8_TYPE "signed char"
+#define INT_FAST16_TYPE "int"
+#define INT_FAST32_TYPE "int"
+#define INT_FAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "long long int")
+#define UINT_FAST8_TYPE "unsigned char"
+#define UINT_FAST16_TYPE "unsigned int"
+#define UINT_FAST32_TYPE "unsigned int"
+#define UINT_FAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "long long unsigned int")
+
+#define INTPTR_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "int")
+#define UINTPTR_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "unsigned int")
Index: fixincludes/fixincl.x
===================================================================
--- fixincludes/fixincl.x	(revision 248673)
+++ fixincludes/fixincl.x	(working copy)
@@ -1,12 +1,12 @@
 /*  -*- buffer-read-only: t -*- vi: set ro:
- * 
+ *
  * DO NOT EDIT THIS FILE   (fixincl.x)
- * 
- * It has been AutoGen-ed  Saturday February 25, 2017 at 03:25:44 PM EST
+ *
+ * It has been AutoGen-ed  June  8, 2017 at 10:50:04 AM by AutoGen 5.18.4
  * From the definitions    inclhack.def
  * and the template file   fixincl
  */
-/* DO NOT SVN-MERGE THIS FILE, EITHER Sat 25 Feb 2017 15:25:44 EST
+/* DO NOT SVN-MERGE THIS FILE, EITHER Thu Jun  8 10:50:04 CEST 2017
  *
  * You must regenerate it.  Use the ./genfixes script.
  *
@@ -15,7 +15,7 @@
  * certain ANSI-incompatible system header files which are fixed to work
  * correctly with ANSI C and placed in a directory that GNU C will search.
  *
- * This file contains 248 fixup descriptions.
+ * This file contains 247 fixup descriptions.
  *
  * See README for more information.
  *
@@ -581,120 +581,6 @@
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * *
  *
- *  Description of Aab_Vxworks_Stdint fix
- */
-tSCC zAab_Vxworks_StdintName[] =
-     "AAB_vxworks_stdint";
-
-/*
- *  File name selection pattern
- */
-tSCC zAab_Vxworks_StdintList[] =
-  "stdint.h\0";
-/*
- *  Machine/OS name selection pattern
- */
-tSCC* apzAab_Vxworks_StdintMachs[] = {
-        "*-*-vxworks*",
-        (const char*)NULL };
-#define AAB_VXWORKS_STDINT_TEST_CT  0
-#define aAab_Vxworks_StdintTests   (tTestDesc*)NULL
-
-/*
- *  Fix Command Arguments for Aab_Vxworks_Stdint
- */
-static const char* apzAab_Vxworks_StdintPatch[] = {
-"#ifndef _STDINT_H\n\
-#define _STDINT_H\n\
-/* get int*_t, uint*_t */\n\
-#include <types/vxTypes.h>\n\n\
-/* get legacy vxworks types for compatibility */\n\
-#include <types/vxTypesOld.h>\n\n\
-typedef long intptr_t;\n\
-typedef unsigned long uintptr_t;\n\n\
-typedef int64_t intmax_t;\n\
-typedef uint64_t uintmax_t;\n\n\
-typedef int8_t int_least8_t;\n\
-typedef int16_t int_least16_t;\n\
-typedef int32_t int_least32_t;\n\
-typedef int64_t int_least64_t;\n\n\
-typedef uint8_t uint_least8_t;\n\
-typedef uint16_t uint_least16_t;\n\
-typedef uint32_t uint_least32_t;\n\
-typedef uint64_t uint_least64_t;\n\n\
-typedef int8_t int_fast8_t;\n\
-typedef int int_fast16_t;\n\
-typedef int32_t int_fast32_t;\n\
-typedef int64_t int_fast64_t;\n\n\
-typedef uint8_t uint_fast8_t;\n\
-typedef unsigned int uint_fast16_t;\n\
-typedef uint32_t uint_fast32_t;\n\
-typedef uint64_t uint_fast64_t;\n\n\
-/* Ranges */\n\
-#define UINT8_MAX (~(uint8_t)0)\n\
-#define UINT8_MIN 0\n\
-#define UINT16_MAX (~(uint16_t)0)\n\
-#define UINT16_MIN 0\n\
-#define UINT32_MAX (~(uint32_t)0)\n\
-#define UINT32_MIN 0\n\
-#define UINT64_MAX (~(uint64_t)0)\n\
-#define UINT64_MIN 0\n\n\
-#define UINTPTR_MAX (~(uintptr_t)0)\n\
-#define UINTPTR_MIN 0\n\n\
-/* Need to do int_fast16_t as well, as type\n\
-   size may be architecture dependent */\n\
-#define UINT_FAST16_MAX (~(uint_fast16_t)0)\n\
-#define UINT_FAST16_MAX 0\n\n\
-#define INT8_MAX (UINT8_MAX>>1)\n\
-#define INT8_MIN (INT8_MAX+1)\n\
-#define INT16_MAX (UINT16_MAX>>1)\n\
-#define INT16_MIN (INT16_MAX+1)\n\
-#define INT32_MAX (UINT32_MAX>>1)\n\
-#define INT32_MIN (INT32_MAX+1)\n\
-#define INT64_MAX (UINT64_MAX>>1)\n\
-#define INT64_MIN (INT64_MAX+1)\n\n\
-#define INTPTR_MAX (UINTPTR_MAX>>1)\n\
-#define INTPTR_MIN (INTPTR_MAX+1)\t\n\n\
-#define INT_FAST16_MAX (UINT_FAST16_MAX>>1)\n\
-#define INT_FAST16_MIN (INT_FAST16_MAX+1)\n\n\
-/* now define equiv. constants */\n\
-#define UINT_FAST8_MAX UINT8_MAX\n\
-#define UINT_FAST8_MIN UINT_FAST8_MIN\n\
-#define INT_FAST8_MAX INT8_MAX\n\
-#define INT_FAST8_MIN INT8_MIN\n\
-#define UINT_FAST32_MAX UINT32_MAX\n\
-#define UINT_FAST32_MIN UINT32_MIN\n\
-#define INT_FAST32_MAX INT32_MAX\n\
-#define INT_FAST32_MIN INT32_MIN\n\
-#define UINT_FAST64_MAX UINT64_MAX\n\
-#define UINT_FAST64_MIN UINT64_MIN\n\
-#define INT_FAST64_MAX INT64_MAX\n\
-#define INT_FAST64_MIN INT64_MIN\n\n\
-#define UINT_LEAST8_MAX UINT8_MAX\n\
-#define UINT_LEAST8_MIN UINT8_MIN\n\
-#define INT_LEAST8_MAX INT8_MAX\n\
-#define INT_LEAST8_MIN INT8_MIN\n\
-#define UINT_LEAST16_MAX UINT16_MAX\n\
-#define UINT_LEAST16_MIN UINT16_MIN\n\
-#define INT_LEAST16_MAX INT16_MAX\n\
-#define INT_LEAST16_MIN INT16_MIN\n\
-#define UINT_LEAST32_MAX UINT32_MAX\n\
-#define UINT_LEAST32_MIN UINT32_MIN\n\
-#define INT_LEAST32_MAX INT32_MAX\n\
-#define INT_LEAST32_MIN INT32_MIN\n\
-#define UINT_LEAST64_MAX UINT64_MAX\n\
-#define UINT_LEAST64_MIN UINT64_MIN\n\
-#define INT_LEAST64_MAX INT64_MAX\n\
-#define INT_LEAST64_MIN INT64_MIN\n\n\
-#define UINTMAX_MAX UINT64_MAX\n\
-#define UINTMAX_MIN UINT64_MIN\n\
-#define INTMAX_MAX INT64_MAX\n\
-#define INTMAX_MIN INT64_MIN\n\n\
-#endif",
-    (char*)NULL };
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * *
- *
  *  Description of Aab_Vxworks_Unistd fix
  */
 tSCC zAab_Vxworks_UnistdName[] =
@@ -10141,7 +10027,7 @@
  */
 #define REGEX_COUNT          285
 #define MACH_LIST_SIZE_LIMIT 187
-#define FIX_COUNT            248
+#define FIX_COUNT            247
 
 /*
  *  Enumerate the fixes
@@ -10157,7 +10043,6 @@
     AAB_SUN_MEMCPY_FIXIDX,
     AAB_VXWORKS_ASSERT_FIXIDX,
     AAB_VXWORKS_REGS_VXTYPES_FIXIDX,
-    AAB_VXWORKS_STDINT_FIXIDX,
     AAB_VXWORKS_UNISTD_FIXIDX,
     AIX_ASSERT_FIXIDX,
     AIX_COMPLEX_FIXIDX,
@@ -10448,11 +10333,6 @@
      AAB_VXWORKS_REGS_VXTYPES_TEST_CT, FD_MACH_ONLY | FD_REPLACEMENT,
      aAab_Vxworks_Regs_VxtypesTests,   apzAab_Vxworks_Regs_VxtypesPatch, 0 },
 
-  {  zAab_Vxworks_StdintName,    zAab_Vxworks_StdintList,
-     apzAab_Vxworks_StdintMachs,
-     AAB_VXWORKS_STDINT_TEST_CT, FD_MACH_ONLY | FD_REPLACEMENT,
-     aAab_Vxworks_StdintTests,   apzAab_Vxworks_StdintPatch, 0 },
-
   {  zAab_Vxworks_UnistdName,    zAab_Vxworks_UnistdList,
      apzAab_Vxworks_UnistdMachs,
      AAB_VXWORKS_UNISTD_TEST_CT, FD_MACH_ONLY | FD_REPLACEMENT,
Index: fixincludes/inclhack.def
===================================================================
--- fixincludes/inclhack.def	(revision 248673)
+++ fixincludes/inclhack.def	(working copy)
@@ -427,122 +427,6 @@
 };
 
 /*
- * Make VxWorks stdint.h a bit more compliant - add typedefs
- */
-fix = {
-    hackname    = AAB_vxworks_stdint;
-    files       = stdint.h;
-    mach        = "*-*-vxworks*";
-        
-    replace     = <<- _EndOfHeader_
-	#ifndef _STDINT_H
-	#define _STDINT_H
-	/* get int*_t, uint*_t */
-	#include <types/vxTypes.h>
-	
-	/* get legacy vxworks types for compatibility */
-	#include <types/vxTypesOld.h>
-	
-	typedef long intptr_t;
-	typedef unsigned long uintptr_t;
-	
-	typedef int64_t intmax_t;
-	typedef uint64_t uintmax_t;
-	
-	typedef int8_t int_least8_t;
-	typedef int16_t int_least16_t;
-	typedef int32_t int_least32_t;
-	typedef int64_t int_least64_t;
-	
-	typedef uint8_t uint_least8_t;
-	typedef uint16_t uint_least16_t;
-	typedef uint32_t uint_least32_t;
-	typedef uint64_t uint_least64_t;
-	
-	typedef int8_t int_fast8_t;
-	typedef int int_fast16_t;
-	typedef int32_t int_fast32_t;
-	typedef int64_t int_fast64_t;
-	
-	typedef uint8_t uint_fast8_t;
-	typedef unsigned int uint_fast16_t;
-	typedef uint32_t uint_fast32_t;
-	typedef uint64_t uint_fast64_t;
-	
-	/* Ranges */
-	#define UINT8_MAX (~(uint8_t)0)
-	#define UINT8_MIN 0
-	#define UINT16_MAX (~(uint16_t)0)
-	#define UINT16_MIN 0
-	#define UINT32_MAX (~(uint32_t)0)
-	#define UINT32_MIN 0
-	#define UINT64_MAX (~(uint64_t)0)
-	#define UINT64_MIN 0
-	
-	#define UINTPTR_MAX (~(uintptr_t)0)
-	#define UINTPTR_MIN 0
-	
-	/* Need to do int_fast16_t as well, as type
-	   size may be architecture dependent */
-	#define UINT_FAST16_MAX (~(uint_fast16_t)0)
-	#define UINT_FAST16_MAX 0
-	
-	#define INT8_MAX (UINT8_MAX>>1)
-	#define INT8_MIN (INT8_MAX+1)
-	#define INT16_MAX (UINT16_MAX>>1)
-	#define INT16_MIN (INT16_MAX+1)
-	#define INT32_MAX (UINT32_MAX>>1)
-	#define INT32_MIN (INT32_MAX+1)
-	#define INT64_MAX (UINT64_MAX>>1)
-	#define INT64_MIN (INT64_MAX+1)
-	
-	#define INTPTR_MAX (UINTPTR_MAX>>1)
-	#define INTPTR_MIN (INTPTR_MAX+1)	
-	
-	#define INT_FAST16_MAX (UINT_FAST16_MAX>>1)
-	#define INT_FAST16_MIN (INT_FAST16_MAX+1)
-	
-	/* now define equiv. constants */
-	#define UINT_FAST8_MAX UINT8_MAX
-	#define UINT_FAST8_MIN UINT_FAST8_MIN
-	#define INT_FAST8_MAX INT8_MAX
-	#define INT_FAST8_MIN INT8_MIN
-	#define UINT_FAST32_MAX UINT32_MAX
-	#define UINT_FAST32_MIN UINT32_MIN
-	#define INT_FAST32_MAX INT32_MAX
-	#define INT_FAST32_MIN INT32_MIN
-	#define UINT_FAST64_MAX UINT64_MAX
-	#define UINT_FAST64_MIN UINT64_MIN
-	#define INT_FAST64_MAX INT64_MAX
-	#define INT_FAST64_MIN INT64_MIN
-	
-	#define UINT_LEAST8_MAX UINT8_MAX
-	#define UINT_LEAST8_MIN UINT8_MIN
-	#define INT_LEAST8_MAX INT8_MAX
-	#define INT_LEAST8_MIN INT8_MIN
-	#define UINT_LEAST16_MAX UINT16_MAX
-	#define UINT_LEAST16_MIN UINT16_MIN
-	#define INT_LEAST16_MAX INT16_MAX
-	#define INT_LEAST16_MIN INT16_MIN
-	#define UINT_LEAST32_MAX UINT32_MAX
-	#define UINT_LEAST32_MIN UINT32_MIN
-	#define INT_LEAST32_MAX INT32_MAX
-	#define INT_LEAST32_MIN INT32_MIN
-	#define UINT_LEAST64_MAX UINT64_MAX
-	#define UINT_LEAST64_MIN UINT64_MIN
-	#define INT_LEAST64_MAX INT64_MAX
-	#define INT_LEAST64_MIN INT64_MIN
-	
-	#define UINTMAX_MAX UINT64_MAX
-	#define UINTMAX_MIN UINT64_MIN
-	#define INTMAX_MAX INT64_MAX
-	#define INTMAX_MIN INT64_MIN
-	
-	#endif
-	_EndOfHeader_;
-};
-
-/*
  *  This hack makes makes unistd.h more POSIX-compliant on VxWorks
  */
 fix = {

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: improve stdint.h handling for VxWorks
  2017-06-12  9:17 improve stdint.h handling for VxWorks Olivier Hainque
@ 2017-06-12 11:19 ` Nathan Sidwell
  2017-06-12 12:16   ` Olivier Hainque
  0 siblings, 1 reply; 3+ messages in thread
From: Nathan Sidwell @ 2017-06-12 11:19 UTC (permalink / raw)
  To: Olivier Hainque, GCC Patches; +Cc: Douglas B Rupp, Joel Brobecker, Joseph Myers

On 06/12/2017 05:17 AM, Olivier Hainque wrote:

> Nathan, how does this look to you ?

I'm fine with it.  Previously we tried to avoid fixincludes so that aan 
updated toolchain could just drop in to an existing tornado 
distribution.  But that's no longer a concern.

nathan
-- 
Nathan Sidwell

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: improve stdint.h handling for VxWorks
  2017-06-12 11:19 ` Nathan Sidwell
@ 2017-06-12 12:16   ` Olivier Hainque
  0 siblings, 0 replies; 3+ messages in thread
From: Olivier Hainque @ 2017-06-12 12:16 UTC (permalink / raw)
  To: Nathan Sidwell
  Cc: Olivier Hainque, GCC Patches, Douglas B Rupp, Joel Brobecker,
	Joseph Myers


> On Jun 12, 2017, at 13:19 , Nathan Sidwell <nathan@acm.org> wrote:
> 
> On 06/12/2017 05:17 AM, Olivier Hainque wrote:
> 
>> Nathan, how does this look to you ?
> 
> I'm fine with it.

Great, thanks :-)

>  Previously we tried to avoid fixincludes so that aan updated toolchain could just drop in to an existing tornado distribution.  But that's no longer a concern.

OK. I'll follow up on the fixincludes business as a separate
message. There are concerns disjoint from the stdint.h particular
issue and that would better be tracked on a separate thread.

Thanks a lot for your prompt feedback,

With Kind Regards,

Olivier

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-06-12 12:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-12  9:17 improve stdint.h handling for VxWorks Olivier Hainque
2017-06-12 11:19 ` Nathan Sidwell
2017-06-12 12:16   ` Olivier Hainque

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).