On Friday 24 April 2009 10:05:00, Vincent R. wrote:
> Once again we are  referencing i386/t-gthr-win32, i386/t-dw2-eh and
> i386/t-sjlj-eh 
> and this is stupid because those files have only one definition that is not
> i386 specific.

That's the definition of a ...

> +#hack! using i386 file directly...
   ^^^^^

... hack.  This is not stupid.  It was a deliberate decision ---
it makes it much easier to carry around small local changes in the original
files, than to keep around local patches moving a bunch of things around...

On Friday 24 April 2009 14:50:06, Dave Korn wrote:
>   I think there are more options than just those two, but certainly it is
> right to common out the shared functionality.  


> I believe it should just go one 
> level up in config/ rather than have a subdir; there's a ton of shared stuff
> in that directory already.

I completelly agree.  This option has been my intent all along.  It just
needs someone to seriously propose doing it, and then, doing it.

How would people prefer something like this going forward?  Start with
extracting common stuff into config/, while making sure e.g, at least
one of mingw or cygwin still bootstraps/tests OK; or, start by
updating config/arm/ with copies of what's under config/i386/, and once
that is in, work on extracting/abstracting common stuff out?

Vincent pointed out the obvious abuses that are 100% reusable, but,
I'd like to reuse e.g., config/i386/winnt.c, config/i386/winnt-cxx.c,
config/i386/winnt-stubs.c for ARM as well.  E.g, currently, I've copied
config/i386/winnt.c over the current config/arm/pe.c (completelly replacing
it), and adjusted it a bit to make it work for ARM.  As you can see from
the hunk below, the main juice is shareable here (there's no fastcall
on ARM WinCE):

-- 
Pedro Alves

--- i386/winnt.c        2009-04-19 21:56:24.000000000 +0100
+++ arm/pe.c    2009-04-19 21:56:30.000000000 +0100
@@ -1,7 +1,6 @@
-/* Subroutines for insn-output.c for Windows NT.
-   Contributed by Douglas Rupp (dr...@cs.washington.edu)
-   Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+/* Routines for GCC for ARM/pe.
+   Copyright (C) 1995, 1996, 2000, 2001, 2002, 2004, 2005, 2007, 2008
+   Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -32,13 +31,11 @@ along with GCC; see the file COPYING3.  
 #include "tm_p.h"
 #include "toplev.h"
 #include "hashtab.h"
-#include "langhooks.h"
 #include "ggc.h"
-#include "target.h"
 
-/* i386/PE specific attribute support.
+/* arm/PE specific attribute support.
 
-   i386/PE has two new attributes:
+   arm/PE has two new attributes:
    dllexport - for exporting a function/variable that will live in a dll
    dllimport - for importing a function/variable from a dll
 
@@ -50,7 +47,7 @@ along with GCC; see the file COPYING3.  
 /* Handle a "shared" attribute;
    arguments as in struct attribute_spec.handler.  */
 tree
-ix86_handle_shared_attribute (tree *node, tree name,
+arm_pe_handle_shared_attribute (tree *node, tree name,
                              tree args ATTRIBUTE_UNUSED,
                              int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
 {
@@ -67,7 +64,7 @@ ix86_handle_shared_attribute (tree *node
 /* Handle a "selectany" attribute;
    arguments as in struct attribute_spec.handler.  */
 tree
-ix86_handle_selectany_attribute (tree *node, tree name,
+arm_pe_handle_selectany_attribute (tree *node, tree name,
                                 tree args ATTRIBUTE_UNUSED,
                                 int flags ATTRIBUTE_UNUSED,
                                 bool *no_add_attrs)
@@ -77,7 +74,7 @@ ix86_handle_selectany_attribute (tree *n
      until the language frontend has processed the decl. We'll check for
      initialization later in encode_section_info.  */
   if (TREE_CODE (*node) != VAR_DECL || !TREE_PUBLIC (*node))
-    {  
+    {
       error ("%qs attribute applies only to initialized variables"
                     " with external linkage",  IDENTIFIER_POINTER (name));
       *no_add_attrs = true;
@@ -100,7 +97,7 @@ associated_type (tree decl)
 /* Return true if DECL should be a dllexport'd object.  */
 
 static bool
-i386_pe_determine_dllexport_p (tree decl)
+arm_pe_determine_dllexport_p (tree decl)
 {
   tree assoc;
 
@@ -113,7 +110,7 @@ i386_pe_determine_dllexport_p (tree decl
   /* Also mark class members of exported classes with dllexport.  */
   assoc = associated_type (decl);
   if (assoc && lookup_attribute ("dllexport", TYPE_ATTRIBUTES (assoc)))
-    return i386_pe_type_dllexport_p (decl);
+    return arm_pe_type_dllexport_p (decl);
 
   return false;
 }
@@ -121,7 +118,7 @@ i386_pe_determine_dllexport_p (tree decl
 /* Return true if DECL should be a dllimport'd object.  */
 
 static bool
-i386_pe_determine_dllimport_p (tree decl)
+arm_pe_determine_dllimport_p (tree decl)
 {
   tree assoc;
 
@@ -139,109 +136,32 @@ i386_pe_determine_dllimport_p (tree decl
      out-of-class definition.  */
   assoc = associated_type (decl);
   if (assoc && lookup_attribute ("dllimport", TYPE_ATTRIBUTES (assoc)))
-    return i386_pe_type_dllimport_p (decl);
+    return arm_pe_type_dllimport_p (decl);
 
   return false;
 }
 
 /* Handle the -mno-fun-dllimport target switch.  */
-
 bool
-i386_pe_valid_dllimport_attribute_p (const_tree decl)
+arm_pe_valid_dllimport_attribute_p (const_tree decl)
 {
    if (TARGET_NOP_FUN_DLLIMPORT && TREE_CODE (decl) == FUNCTION_DECL)
      return false;
    return true;
 }
 
-/* Return string which is the function name, identified by ID, modified
-   with a suffix consisting of an atsign (@) followed by the number of
-   bytes of arguments.  If ID is NULL use the DECL_NAME as base. If
-   FASTCALL is true, also add the FASTCALL_PREFIX.
-   Return NULL if no change required.  */
-
-static tree
-gen_stdcall_or_fastcall_suffix (tree decl, tree id, bool fastcall)
-{
-  HOST_WIDE_INT total = 0;
-  const char *old_str = IDENTIFIER_POINTER (id != NULL_TREE ? id : DECL_NAME 
(decl));
-  char *new_str, *p;
-  tree type = TREE_TYPE (decl);
-  tree arg;
-  function_args_iterator args_iter;
-
-  gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);  
-
-  if (prototype_p (type))
-    {
-      /* This attribute is ignored for variadic functions.  */ 
-      if (stdarg_p (type))
-       return NULL_TREE;
-
-      /* Quit if we hit an incomplete type.  Error is reported
-        by convert_arguments in c-typeck.c or cp/typeck.c.  */
-      FOREACH_FUNCTION_ARGS(type, arg, args_iter)
-       {
-         HOST_WIDE_INT parm_size;
-         HOST_WIDE_INT parm_boundary_bytes = PARM_BOUNDARY / BITS_PER_UNIT;
-
-         if (! COMPLETE_TYPE_P (arg))
-           break;
-
-         parm_size = int_size_in_bytes (arg);
-         if (parm_size < 0)
-           break;
-
-         /* Must round up to include padding.  This is done the same
-            way as in store_one_arg.  */
-         parm_size = ((parm_size + parm_boundary_bytes - 1)
-                      / parm_boundary_bytes * parm_boundary_bytes);
-         total += parm_size;
-       }
-      }
-  /* Assume max of 8 base 10 digits in the suffix.  */
-  p = new_str = XALLOCAVEC (char, 1 + strlen (old_str) + 1 + 8 + 1);
-  if (fastcall)
-    *p++ = FASTCALL_PREFIX;
-  sprintf (p, "%s@" HOST_WIDE_INT_PRINT_DEC, old_str, total);
-
-  return get_identifier (new_str);
-}
-
-/* Maybe decorate and get a new identifier for the DECL of a stdcall or
-   fastcall function. The original identifier is supplied in ID. */
-
-static tree
-i386_pe_maybe_mangle_decl_assembler_name (tree decl, tree id)
-{
-  tree new_id = NULL_TREE;
-
-  if (TREE_CODE (decl) == FUNCTION_DECL)
-    { 
-      tree type_attributes = TYPE_ATTRIBUTES (TREE_TYPE (decl));
-      if (lookup_attribute ("stdcall", type_attributes))
-       new_id = gen_stdcall_or_fastcall_suffix (decl, id, false);
-      else if (lookup_attribute ("fastcall", type_attributes))
-       new_id = gen_stdcall_or_fastcall_suffix (decl, id, true);
-    }
-
-  return new_id;
-}
-
 /* This is used as a target hook to modify the DECL_ASSEMBLER_NAME
    in the language-independent default hook
    langhooks,c:lhd_set_decl_assembler_name ()
    and in cp/mangle,c:mangle_decl ().  */
 tree
-i386_pe_mangle_decl_assembler_name (tree decl, tree id)
+arm_pe_mangle_decl_assembler_name (tree decl, tree id)
 {
-  tree new_id = i386_pe_maybe_mangle_decl_assembler_name (decl, id);   
-
-  return (new_id ? new_id : id);
+  return id;
 }
 
 void
-i386_pe_encode_section_info (tree decl, rtx rtl, int first)
+arm_pe_encode_section_info (tree decl, rtx rtl, int first)
 {
   rtx symbol;
   int flags;
@@ -259,20 +179,6 @@ i386_pe_encode_section_info (tree decl, 
   switch (TREE_CODE (decl))
     {
     case FUNCTION_DECL:
-      /* FIXME:  Imported stdcall names are not modified by the Ada frontend.
-        Check and decorate the RTL name now.  */
-      if  (strcmp (lang_hooks.name, "GNU Ada") == 0)
-       {
-         tree new_id;
-         tree old_id = DECL_ASSEMBLER_NAME (decl);
-         const char* asm_str = IDENTIFIER_POINTER (old_id);
-         /* Do not change the identifier if a verbatim asmspec
-            or if stdcall suffix already added. */
-         if (!(*asm_str == '*' || strchr (asm_str, '@'))
-             && (new_id = i386_pe_maybe_mangle_decl_assembler_name (decl,
-                                                                    old_id)))
-           XSTR (symbol, 0) = IDENTIFIER_POINTER (new_id);
-       }
       break;
 
     case VAR_DECL:
@@ -301,9 +207,9 @@ i386_pe_encode_section_info (tree decl, 
      handles dllexport/dllimport override semantics.  */
   flags = (SYMBOL_REF_FLAGS (symbol) &
           ~(SYMBOL_FLAG_DLLIMPORT | SYMBOL_FLAG_DLLEXPORT));
-  if (i386_pe_determine_dllexport_p (decl))
+  if (arm_pe_determine_dllexport_p (decl))
     flags |= SYMBOL_FLAG_DLLEXPORT;
-  else if (i386_pe_determine_dllimport_p (decl))
+  else if (arm_pe_determine_dllimport_p (decl))
     {
       flags |= SYMBOL_FLAG_DLLIMPORT;
       /* If we went through the associated_type path, this won't already
@@ -319,7 +225,7 @@ i386_pe_encode_section_info (tree decl, 
 }
 
 bool
-i386_pe_binds_local_p (const_tree exp)
+arm_pe_binds_local_p (const_tree exp)
 {
   /* PE does not do dynamic binding.  Indeed, the only kind of
      non-local reference comes from a dllimport'd symbol.  */
@@ -333,32 +239,20 @@ i386_pe_binds_local_p (const_tree exp)
 /* Also strip the fastcall prefix and stdcall suffix.  */
 
 const char *
-i386_pe_strip_name_encoding_full (const char *str)
+arm_pe_strip_name_encoding_full (const char *str)
 {
-  const char *p;
-  const char *name = default_strip_name_encoding (str);
-
-  /* Strip leading '@' on fastcall symbols.  */
-  if (*name == '@')
-    name++;
-
-  /* Strip trailing "@n".  */
-  p = strchr (name, '@');
-  if (p)
-    return ggc_alloc_string (name, p - name);
-
-  return name;
+  return arm_strip_name_encoding (str);
 }
 
 void
-i386_pe_unique_section (tree decl, int reloc)
+arm_pe_unique_section (tree decl, int reloc)
 {
   int len;
   const char *name, *prefix;
   char *string;
 
   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
-  name = i386_pe_strip_name_encoding_full (name);
+  name = arm_pe_strip_name_encoding_full (name);
 
   /* The object is put in, for example, section .text$foo.
      The linker will then ultimately place them in .text
@@ -397,7 +291,7 @@ i386_pe_unique_section (tree decl, int r
 #define SECTION_PE_SHARED      SECTION_MACH_DEP
 
 unsigned int
-i386_pe_section_type_flags (tree decl, const char *name, int reloc)
+arm_pe_section_type_flags (tree decl, const char *name, int reloc)
 {
   static htab_t htab;
   unsigned int flags;
@@ -451,7 +345,7 @@ i386_pe_section_type_flags (tree decl, c
 }
 
 void
-i386_pe_asm_named_section (const char *name, unsigned int flags, 
+arm_pe_asm_named_section (const char *name, unsigned int flags,
                           tree decl)
 {
   char flagchars[8], *f = flagchars;
@@ -462,7 +356,7 @@ i386_pe_asm_named_section (const char *n
       *f++ ='d';  /* This is necessary for older versions of gas.  */
       *f++ ='r';
     }
-  else 
+  else
     {
       if (flags & SECTION_CODE)
         *f++ = 'x';
@@ -483,17 +377,17 @@ i386_pe_asm_named_section (const char *n
         Instead, have the linker pick one, without warning.
         If 'selectany' attribute has been specified,  MS compiler
         sets 'discard' characteristic, rather than telling linker
-        to warn of size or content mismatch, so do the same.  */ 
+        to warn of size or content mismatch, so do the same.  */
       bool discard = (flags & SECTION_CODE)
                      || lookup_attribute ("selectany",
-                                          DECL_ATTRIBUTES (decl));      
+                                          DECL_ATTRIBUTES (decl));
       fprintf (asm_out_file, "\t.linkonce %s\n",
               (discard  ? "discard" : "same_size"));
     }
 }
 
 void
-i386_pe_asm_output_aligned_decl_common (FILE *stream, tree decl,
+arm_pe_asm_output_aligned_decl_common (FILE *stream, tree decl,
                                        const char *name, HOST_WIDE_INT size,
                                        HOST_WIDE_INT align ATTRIBUTE_UNUSED)
 {
@@ -505,10 +399,16 @@ i386_pe_asm_output_aligned_decl_common (
   rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
   rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
             * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
-  
-  i386_pe_maybe_record_exported_symbol (decl, name, 1);
 
+  arm_pe_maybe_record_exported_symbol (decl, name, 1);
+
+#if 1
+  switch_to_section (bss_section);
+  fprintf (stream, "\t.balign %d\n\t.comm \t", ((int) align) / BITS_PER_UNIT);
+#else  
   fprintf (stream, "\t.comm\t");
+#endif
+
   assemble_name (stream, name);
   fprintf (stream, ", " HOST_WIDE_INT_PRINT_DEC "\t" ASM_COMMENT_START
           " " HOST_WIDE_INT_PRINT_DEC "\n",
@@ -528,7 +428,7 @@ i386_pe_asm_output_aligned_decl_common (
    visible.  */
 
 void
-i386_pe_declare_function_type (FILE *file, const char *name, int pub)
+arm_pe_declare_function_type (FILE *file, const char *name, int pub)
 {
   fprintf (file, "\t.def\t");
   assemble_name (file, name);
@@ -555,7 +455,7 @@ static GTY(()) struct extern_list *exter
    for it then.  */
 
 void
-i386_pe_record_external_function (tree decl, const char *name)
+arm_pe_record_external_function (tree decl, const char *name)
 {
   struct extern_list *p;
 
@@ -584,7 +484,7 @@ static GTY(()) struct export_list *expor
    linkonce.  */
 
 void
-i386_pe_maybe_record_exported_symbol (tree decl, const char *name, int is_data)
+arm_pe_maybe_record_exported_symbol (tree decl, const char *name, int is_data)
 {
   rtx symbol;
   struct export_list *p;
@@ -606,11 +506,11 @@ i386_pe_maybe_record_exported_symbol (tr
    output the .drectve section.  */
 
 void
-i386_pe_file_end (void)
+arm_pe_file_end (void)
 {
   struct extern_list *p;
 
-  ix86_file_end ();
+  arm_file_end ();
 
   for (p = extern_head; p != NULL; p = p->next)
     {
@@ -623,7 +523,7 @@ i386_pe_file_end (void)
          && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
        {
          TREE_ASM_WRITTEN (decl) = 1;
-         i386_pe_declare_function_type (asm_out_file, p->name,
+         arm_pe_declare_function_type (asm_out_file, p->name,
                                         TREE_PUBLIC (decl));
        }
     }
@@ -635,10 +535,10 @@ i386_pe_file_end (void)
       for (q = export_head; q != NULL; q = q->next)
        {
          fprintf (asm_out_file, "\t.ascii \" -export:%s%s\"\n",
-                  default_strip_name_encoding (q->name),
+                  arm_pe_strip_name_encoding_full (q->name),
                   (q->is_data ? ",data" : ""));
        }
     }
 }
 
-#include "gt-winnt.h"
+#include "gt-pe.h"

Reply via email to