This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[RFD/PATCH 2.95.4] vxworks-varargs.patch



    Good afternoon, everybody.

  Varargs handling has not worked for the powerpc-wrs-vxworks target for
some time now.

  VxWorks bypasses the usual varargs headers, and defines all the va_
macros in a header file arch/ppc/toolPpc.h.  This header uses the
__builtin_args_info functions, which are no longer valid in 2.95.3,
particularly since the rs6000_args_info structure was altered, removing
the varargs_offset member that previously was __builtin_args_info(4).
When the VxWorks headers try that, they get the new member #4, which is
the prototype count.  This is usually around 1000 (decimal) which isn't
right at all.

  A related problem is that this file is included indirectly from stdarg.h
and varargs.h via a second vxworks specific header, arch/ppc/toolPpc.h.
However this header uses #include "" rather than #include <>; thus even
if we fix the first header, in a standard VxWorks makefile (which specifies
the Vxworks include directory as a -I path), the fixed header will not
be found.

  We have to patch that file to use va-ppc.h instead, and we also have to
patch the file that includes it to enforce it's being found on the system
include path.

  There are some predefines needed in the spec file as well:

  The standard macro __PPC__ is not predefined by the specs in the
vxworks-ppc target header.  This means that any attempt to include gcc's
stdarg.h fails, since the lack of the __PPC__ macro means it doesn't know
to include va-ppc.h, it falls back to the default void * type for va_list,
and everything errors for lack of va_ macros being defined.

  In order for the fixed headers to still work with the old compiler, I
used a feature select macro.  This is just a minor kindness to anyone who
overwrites their VxWorks header files and then wants to go back.  I also
define __PPC__ since a) it's true and b) it makes the new varargs.h /
stdarg.h find va-ppc.h correctly.  I suppose to be really kind I could
have fixed those two headers to include the old VxWorks header file if the
feature select macro was off, but that's way too target specific to go in
somewhere so generic, so I wouldn't want to modify the originals in 
gcc/ginclude.  I am under the impression that fixincludes isn't run on
those headers; if it was, it could put target specific stuff into them
in a way that didn't clutter all the other targets

  VxWorks users will still have problems if they continue to use the 
-nostdinc flag that is set in VxWorks default makefiles, but I didn't
think hacking the compiler to turn '#include <arch/ppc/toolPpc.h>' into
'#include <va-ppc.h>\n#include <arch/ppc/toolPpc.h> is a very good idea,
so end users will have to either i) remove -nostdinc from their CFLAGS,
ii) copy the fixed headers into the directory tree set up by a vxworks
toolchain installation, or iii) work outside the standard vxworks directory
tree / build environment altogether.

  Tested on powerpc-wrs-vxworks, with make check-gcc check-g++; fixed *all*
the tests involving varargs/stdargs, none of which previously would even
compile (and had they been compiled using the VxWorks standard headers,
they would have failed at runtime when trying to use __builtin_args_info
(4) to access arguments on the stack); no regressions introduced.

  Comments, questions, flames ?

       DaveK

 [ This is an ever-so-slight rewrite of a previous mail I sent on the
subject; the previous one wasn't intended for inclusion in the CVS but just
for people who searched the gcc mailing lists for help with vxworks and
2.95.3 to find.  I have slightly modified the text of one comment in the
patch but it is functionally identical to the original. ]

  For the record, I do not have a copyright assignment on file, but could
certainly get one filed if need be; I don't think this patch is complex
enough to need one but stand ready to be corrected.

  My apologies in advance if this M$ rubbish tampers with my line wrapping.


2001-03-22  Dave Korn  <davek-ml@ntlworld.com>

      * fixinc/inclhack.def:  Add two new entries to fix vxworks varargs
      header problems.

      * config/rs6000/vxppc.h: (CPP_PREDEFINES)  Add feature select macros
      to enable fixes in fixincluded vxworks headers.

diff -c3prN /gcc.orig/gcc/gcc/config/rs6000/vxppc.h
/gcc.dev/gcc/gcc/config/rs6000/vxppc.h
*** /gcc.orig/gcc/gcc/config/rs6000/vxppc.h Mon May 17 02:30:56 1999
--- /gcc.dev/gcc/gcc/config/rs6000/vxppc.h Mon Jan 29 23:41:20 2001
*************** Boston, MA 02111-1307, USA.  */
*** 47,53 ****
  #undef CPP_PREDEFINES
  #define CPP_PREDEFINES "\
  -D__vxworks -Asystem(vxworks) -Asystem(embedded) \
! -Acpu(powerpc) -Amachine(powerpc)"

  /* VxWorks does all the library stuff itself.  */

--- 47,53 ----
  #undef CPP_PREDEFINES
  #define CPP_PREDEFINES "\
  -D__vxworks -Asystem(vxworks) -Asystem(embedded) \
! -Acpu(powerpc) -Amachine(powerpc) -D__PPC__ -D__VXVARGS__"

  /* VxWorks does all the library stuff itself.  */

diff -c3prN /gcc.orig/gcc/gcc/fixinc/inclhack.def
/gcc.dev/gcc/gcc/fixinc/inclhack.def
*** /gcc.orig/gcc/gcc/fixinc/inclhack.def Fri Aug 13 09:44:06 1999
--- /gcc.dev/gcc/gcc/fixinc/inclhack.def Wed Jan 24 20:38:26 2001
*************** fix = {
*** 2234,2239 ****
--- 2234,2267 ----
          "#endif\n";
  };

+ /*
+  *   Fix VxWorks varargs header
+  */
+ fix = {
+     hackname = vxworks_varargs_problem;
+     files    = arch/ppc/toolPpc.h;
+     select   = "GNU C varargs support for the PowerPC with V.4 calling
sequence";
+
+     sed = "/\\/\\* GNU C varargs support for the PowerPC with V.4 calling
sequence \\*\\//a\\\n"
+      "#ifdef __VXVARGS__\\\n"
+   "#include <va-ppc.h>\\\n"
+   "#else /* !defined(__VXVARGS__) */\\\n";
+
+     sed = "/\\/\\* END CYGNUS LOCAL Waiting for 2.7.1 to unfreeze
\\*\\//i\\\n"
+   "#endif /* !defined(__VXVARGS__) */\\\n";
+ };
+
+ /*
+  *   That last fix won't even work unless we make archPpc.h use the system
+  *  include search path when it includes toolPpc.h
+  *
+  */
+ fix = {
+     hackname = vxworks_arch_includepath;
+     files    = arch/ppc/archPpc.h;
+     select = 'include.*"toolPpc.h"';
+     sed    = "s,\"toolPpc.h\",<arch/ppc/toolPpc.h>,";
+ };

  /*
   *  Fix VxWorks <time.h> to not require including <vxTypes.h>.


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]