]> gcc.gnu.org Git - gcc.git/commitdiff
Update weak symbol support
authorJason Merrill <merrill@gnu.org>
Tue, 16 May 1995 01:02:59 +0000 (01:02 +0000)
committerJason Merrill <merrill@gnu.org>
Tue, 16 May 1995 01:02:59 +0000 (01:02 +0000)
From-SVN: r9697

13 files changed:
gcc/c-decl.c
gcc/c-pragma.h
gcc/config/aoutos.h
gcc/config/i386/freebsd.h
gcc/config/i386/osfrose.h
gcc/config/m88k/m88k.h
gcc/config/netbsd.h
gcc/config/sparc/sunos4.h
gcc/config/svr4.h
gcc/defaults.h
gcc/libgcc2.c
gcc/tree.h
gcc/varasm.c

index db9903507d11702974db839fd2d25e94c9103edc..f06be296d8fb9827fcb72c972ccb94dfd23adcb2 100644 (file)
@@ -1791,6 +1791,7 @@ duplicate_decls (newdecl, olddecl)
     }
 
   /* Merge the storage class information.  */
+  DECL_WEAK (newdecl) |= DECL_WEAK (olddecl);    
   /* For functions, static overrides non-static.  */
   if (TREE_CODE (newdecl) == FUNCTION_DECL)
     {
index 061f416aa141531550e958b4b223f298716ab976..530492b06b321f9d8e4579094cdd11b7661b33ae 100644 (file)
@@ -17,10 +17,10 @@ You should have received a copy of the GNU General Public License
 along with GNU CC; see the file COPYING.  If not, write to
 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
-/* Support #pragma weak by default if WEAK_ASM_OP and ASM_OUTPUT_DEF
-   are defined.  */
-#if !defined (HANDLE_PRAGMA_WEAK) && defined (WEAK_ASM_OP) && defined (ASM_OUTPUT_DEF)
-#define HANDLE_PRAGMA_WEAK 1
+/* Support #pragma weak iff ASM_WEAKEN_LABEL and ASM_OUTPUT_DEF are
+   defined.  */
+#if defined (ASM_WEAKEN_LABEL) && defined (ASM_OUTPUT_DEF)
+#define HANDLE_PRAGMA_WEAK SUPPORTS_WEAK
 #endif
 
 enum pragma_state
index f7bfc905982b510e0b16cf28813eacbb15596618..b398965e7adb835d34e005ce04c3d9518a749434 100644 (file)
@@ -85,18 +85,3 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
        fputc ('\n', FILE);                                             \
       }                                                                        \
   } while (0)
-
-/* If we're using GNU as and ld, we support weak symbols.  */
-
-#define HANDLE_PRAGMA_WEAK flag_gnu_linker
-#define WEAK_ASM_OP    ".weak"
-#define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2)                             \
- do { if (flag_gnu_linker)                                             \
-       {                                                               \
-         fprintf ((FILE), "\t%s\t", ".set");                           \
-         assemble_name (FILE, LABEL1);                                 \
-         fprintf (FILE, ",");                                          \
-         assemble_name (FILE, LABEL2);                                 \
-         fprintf (FILE, "\n");                                         \
-       }                                                               \
-  } while (0)
index 10a486d8c01c350e90804379c1de916d3cd1e21e..102cb94813401e15abdf3d2c1ea0b111c7b05520 100644 (file)
@@ -118,7 +118,12 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #define TYPE_ASM_OP    ".type"
 #define SIZE_ASM_OP    ".size"
-#define WEAK_ASM_OP    ".weak"
+
+/* This is how we tell the assembler that a symbol is weak.  */
+
+#define ASM_WEAKEN_LABEL(FILE,NAME) \
+  do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \
+       fputc ('\n', FILE); } while (0)
 
 /* The following macro defines the format used to output the second
    operand of the .type assembler directive.  Different svr4 assemblers
index fa2040c239d638d26e2144df530ed6300a83328b..159c1840268a670ca2e03a50a81a12d5566dd3bf 100644 (file)
@@ -94,7 +94,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 /* Handle #pragma weak and #pragma pack.  */
 
 #define HANDLE_SYSV_PRAGMA
-#define HANDLE_PRAGMA_WEAK     TARGET_ELF
+#define SUPPORTS_WEAK  TARGET_ELF
 
 /* Change default predefines.  */
 #undef CPP_PREDEFINES
@@ -617,9 +617,14 @@ while (0)
 
 #define TYPE_ASM_OP    ".type"
 #define SIZE_ASM_OP    ".size"
-#define WEAK_ASM_OP    ".weak"
 #define SET_ASM_OP     ".set"
 
+/* This is how we tell the assembler that a symbol is weak.  */
+
+#define ASM_WEAKEN_LABEL(FILE,NAME) \
+  do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \
+       fputc ('\n', FILE); } while (0)
+
 /* The following macro defines the format used to output the second
    operand of the .type assembler directive.  Different svr4 assemblers
    expect various different forms for this operand.  The one given here
index 76a7083f3e8a1476c63e6233b7fd137c138ec264..3f84cd672a336bfc5a6857bd3dd5ccde00ad892f 100644 (file)
@@ -198,13 +198,13 @@ extern char * reg_names[];
    Redefined in sysv4.h, and luna.h.  */
 #define VERSION_INFO1  "88open OCS/BCS, "
 #ifndef VERSION_INFO2
-#define VERSION_INFO2   "$Revision: 1.1.1.2.2.2 $"
+#define VERSION_INFO2   "$Revision: 1.63 $"
 #endif
 
 #ifndef VERSION_STRING
 #define VERSION_STRING  version_string
 #ifdef __STDC__
-#define TM_RCS_ID      "@(#)" __FILE__ " $Revision: 1.1.1.2.2.2 $ " __DATE__
+#define TM_RCS_ID      "@(#)" __FILE__ " $Revision: 1.63 $ " __DATE__
 #else
 #define TM_RCS_ID      "$What: <@(#) m88k.h,v  1.1.1.2.2.2> $"
 #endif  /* __STDC__ */
@@ -1542,7 +1542,7 @@ enum reg_class { NO_REGS, AP_REG, XRF_REGS, GENERAL_REGS, AGRF_REGS,
 #define HANDLE_SYSV_PRAGMA
 
 /* Tell when to handle #pragma weak.  This is only done for V.4.  */
-#define HANDLE_PRAGMA_WEAK TARGET_SVR4
+#define SUPPORTS_WEAK TARGET_SVR4
 
 /* Max number of bytes we can move from memory to memory
    in one reasonably fast instruction.  */
@@ -1725,7 +1725,6 @@ enum reg_class { NO_REGS, AP_REG, XRF_REGS, GENERAL_REGS, AGRF_REGS,
 #undef FINI_SECTION_ASM_OP
 #undef TYPE_ASM_OP
 #undef SIZE_ASM_OP
-#undef WEAK_ASM_OP
 #undef SET_ASM_OP
 #undef SKIP_ASM_OP
 #undef COMMON_ASM_OP
@@ -1776,12 +1775,18 @@ enum reg_class { NO_REGS, AP_REG, XRF_REGS, GENERAL_REGS, AGRF_REGS,
 /* These are specific to PIC.  */
 #define TYPE_ASM_OP            "type"
 #define SIZE_ASM_OP            "size"
-#define WEAK_ASM_OP            "weak"
 #ifndef AS_BUG_POUND_TYPE /* Faulty assemblers require @ rather than #.  */
 #undef TYPE_OPERAND_FMT
 #define TYPE_OPERAND_FMT       "#%s"
 #endif
 
+/* This is how we tell the assembler that a symbol is weak.  */
+
+#undef ASM_WEAKEN_LABEL
+#define ASM_WEAKEN_LABEL(FILE,NAME) \
+  do { fputs ("\tweak\t", FILE); assemble_name (FILE, NAME); \
+       fputc ('\n', FILE); } while (0)
+
 /* These are specific to version 03.00 assembler syntax.  */
 #define INTERNAL_ASM_OP                "local"
 #define VERSION_ASM_OP         "version"
index af4f62ebe91c0c8ac19539b306ea3e03aa93bfd4..8c0974ade4dafca578a1de01c6ae96e7235713c0 100644 (file)
 
 #undef TYPE_ASM_OP
 #undef SIZE_ASM_OP
-#undef WEAK_ASM_OP
 #define TYPE_ASM_OP    ".type"
 #define SIZE_ASM_OP    ".size"
-#define WEAK_ASM_OP    ".weak"
+
+/* This is how we tell the assembler that a symbol is weak.  */
+
+#undef ASM_WEAKEN_LABEL
+#define ASM_WEAKEN_LABEL(FILE,NAME) \
+  do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \
+       fputc ('\n', FILE); } while (0)
 
 /* The following macro defines the format used to output the second
    operand of the .type assembler directive.  Different svr4 assemblers
index fd108e85db868047213f2da6b2a0eeb015f8ddcd..c7bcaad12c414c5a958a0ad99101bea34d0ba6c6 100644 (file)
@@ -20,18 +20,3 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #define SUNOS4_SHARED_LIBRARIES 1
 
 #include "sparc/sparc.h"
-
-/* If we're using GNU as and ld, we support weak symbols.  */
-
-#define HANDLE_PRAGMA_WEAK flag_gnu_linker
-#define WEAK_ASM_OP    ".weak"
-#define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2)                             \
- do { if (flag_gnu_linker)                                             \
-       {                                                               \
-         fprintf ((FILE), "\t%s\t", ".set");                           \
-         assemble_name (FILE, LABEL1);                                 \
-         fprintf (FILE, ",");                                          \
-         assemble_name (FILE, LABEL2);                                 \
-         fprintf (FILE, "\n");                                         \
-       }                                                               \
-  } while (0)
index 051187bc43ac2aafb6d90160649132bcb53664d1..c1c8692aea3d5643950b14547fdabedc4a26f2e9 100644 (file)
@@ -648,7 +648,12 @@ dtors_section ()                                                   \
 
 #define TYPE_ASM_OP    ".type"
 #define SIZE_ASM_OP    ".size"
-#define WEAK_ASM_OP    ".weak"
+
+/* This is how we tell the assembler that a symbol is weak.  */
+
+#define ASM_WEAKEN_LABEL(FILE,NAME) \
+  do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \
+       fputc ('\n', FILE); } while (0)
 
 /* The following macro defines the format used to output the second
    operand of the .type assembler directive.  Different svr4 assemblers
index df5ce1cc1dc10feae2f3a8400c2668fe0680015a..f43a3f084c8e27376c6268d7ac99d929c1c3a31e 100644 (file)
@@ -131,3 +131,12 @@ do { fprintf (FILE, "\t%s\t", ASM_SHORT);                          \
   } while (0)
 #endif
 #endif
+
+/* This determines whether or not we support weak symbols.  */
+#ifndef SUPPORTS_WEAK
+#ifdef ASM_WEAKEN_LABEL
+#define SUPPORTS_WEAK 1
+#else
+#define SUPPORTS_WEAK 0
+#endif
+#endif
index 7647baa254d9596c63501cab4a3f5f9ed64a0ed0..32cb00bca05b5294b21c56b03fdf4adab09415e1 100644 (file)
@@ -31,6 +31,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include "tconfig.h"
 #include "machmode.h"
+#include "defaults.h" 
 #ifndef L_trampoline
 #include <stddef.h>
 #endif
@@ -40,6 +41,10 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #undef abort
 #endif
 
+#if (SUPPORTS_WEAK == 1) && defined (ASM_OUTPUT_DEF)
+#define WEAK_ALIAS
+#endif
+
 /* Permit the tm.h file to select the endianness to use just for this
    file.  This is used when the endianness is determined when the
    compiler is run.  */
@@ -1606,9 +1611,15 @@ typedef void (*vfp)(void);
 extern vfp __new_handler;
 extern void __default_new_handler (void);
 
-void * __builtin_new (size_t sz) __attribute__ ((weak));
+#ifdef WEAK_ALIAS
+void * __builtin_new (size_t sz)
+     __attribute__ ((weak, alias ("___builtin_new")));
+void *
+___builtin_new (size_t sz)
+#else
 void *
 __builtin_new (size_t sz)
+#endif
 {
   void *p;
   vfp handler = (__new_handler) ? __new_handler : __default_new_handler;
@@ -1633,9 +1644,15 @@ __builtin_new (size_t sz)
 
 extern void * __builtin_new (size_t);
 
-void * __builtin_vec_new (size_t sz) __attribute__ ((weak));
+#ifdef WEAK_ALIAS
+void * __builtin_vec_new (size_t sz)
+     __attribute__ ((weak, alias ("___builtin_vec_new")));
+void *
+___builtin_vec_new (size_t sz)
+#else
 void *
 __builtin_vec_new (size_t sz)
+#endif
 {
   return __builtin_new (sz);
 }
@@ -1696,9 +1713,15 @@ __default_new_handler ()
    by C++ programs to return to the free store a block of memory allocated
    as a single object. */
 
-void __builtin_delete (void *ptr) __attribute__ ((weak));
+#ifdef WEAK_ALIAS
+void __builtin_delete (void *ptr)
+     __attribute__ ((weak, alias ("___builtin_delete")));
+void
+___builtin_delete (void *ptr)
+#else
 void
 __builtin_delete (void *ptr)
+#endif
 {
   if (ptr)
     free (ptr);
@@ -1712,9 +1735,15 @@ __builtin_delete (void *ptr)
 
 extern void __builtin_delete (void *);
 
-void __builtin_vec_delete (void *ptr) __attribute__ ((weak));
+#ifdef WEAK_ALIAS
+void __builtin_vec_delete (void *ptr)
+     __attribute__ ((weak, alias ("___builtin_vec_delete")));
+void
+___builtin_vec_delete (void *ptr)
+#else
 void
 __builtin_vec_delete (void *ptr)
+#endif
 {
   __builtin_delete (ptr);
 }
index 47c5d6f6a68fb6fd08d91107fac23a22c7faba89..e30fe04743e979085f41569a189f20144c6981a0 100644 (file)
@@ -958,6 +958,9 @@ struct tree_type
 /* Used to indicate that this DECL represents a compiler-generated entity.  */
 #define DECL_ARTIFICIAL(NODE) ((NODE)->decl.artificial_flag)
 
+/* Used to indicate that this DECL has weak linkage.  */
+#define DECL_WEAK(NODE) ((NODE)->decl.weak_flag)
+
 /* Additional flags for language-specific uses.  */
 #define DECL_LANG_FLAG_0(NODE) ((NODE)->decl.lang_flag_0)
 #define DECL_LANG_FLAG_1(NODE) ((NODE)->decl.lang_flag_1)
@@ -997,7 +1000,8 @@ struct tree_decl
   unsigned static_ctor_flag : 1;
   unsigned static_dtor_flag : 1;
   unsigned artificial_flag : 1;
-  /* room for one more */
+  unsigned weak_flag : 1;
+  /* room for no more */
 
   unsigned lang_flag_0 : 1;
   unsigned lang_flag_1 : 1;
index 613ec4fb356e161623d950fa6c000b424b140e61..a06680b40b22659d5790ae2d205a0e6e7308d49d 100644 (file)
@@ -802,6 +802,11 @@ assemble_start_function (decl, fnname)
     {
       if (!first_global_object_name)
        STRIP_NAME_ENCODING (first_global_object_name, fnname);
+#ifdef ASM_WEAKEN_LABEL
+      if (DECL_WEAK (decl))
+       ASM_WEAKEN_LABEL (asm_out_file, fnname);
+      else
+#endif
       if (output_bytecode)
        BC_GLOBALIZE_LABEL (asm_out_file, fnname);
       else
@@ -1172,6 +1177,11 @@ assemble_variable (decl, top_level, at_end, dont_output_data)
     {
       if (!first_global_object_name)
        STRIP_NAME_ENCODING(first_global_object_name, name);
+#ifdef ASM_WEAKEN_LABEL
+      if (DECL_WEAK (decl))
+       ASM_WEAKEN_LABEL (asm_out_file, name);
+      else
+#endif
       ASM_GLOBALIZE_LABEL (asm_out_file, name);
     }
 #if 0
@@ -3964,14 +3974,12 @@ void
 declare_weak (decl)
      tree decl;
 {
-#ifdef HANDLE_PRAGMA_WEAK
   if (! TREE_PUBLIC (decl))
     error_with_decl (decl, "weak declaration of `%s' must be public");
-  else
-    handle_pragma_weak (ps_name,
-                       IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
-                       NULL_PTR);
-#endif
+  else if (TREE_ASM_WRITTEN (decl))
+    error_with_decl (decl, "weak declaration of `%s' must precede definition");
+  else if (SUPPORTS_WEAK)
+    DECL_WEAK (decl) = 1;
 }
 
 /* Emit any pending weak declarations.  */
@@ -3985,14 +3993,7 @@ weak_finish ()
       struct weak_syms *t;
       for (t = weak_decls; t; t = t->next)
        {
-         fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
-
-         if (output_bytecode)
-           BC_OUTPUT_LABELREF (asm_out_file, t->name);
-         else
-           ASM_OUTPUT_LABELREF (asm_out_file, t->name);
-
-         fputc ('\n', asm_out_file);
+         ASM_WEAKEN_LABEL (asm_out_file, t->name);
          if (t->value)
            ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
        }
@@ -4014,6 +4015,11 @@ assemble_alias (decl, target)
 
   if (TREE_PUBLIC (decl))
     {
+#ifdef ASM_WEAKEN_LABEL
+      if (DECL_WEAK (decl))
+       ASM_WEAKEN_LABEL (asm_out_file, name);
+      else
+#endif
       if (output_bytecode)
        BC_GLOBALIZE_LABEL (asm_out_file, name);
       else
@@ -4021,6 +4027,7 @@ assemble_alias (decl, target)
     }
 
   ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
+  TREE_ASM_WRITTEN (decl) = 1;
 #else
   warning ("alias definitions not supported in this configuration");
 #endif
This page took 0.089124 seconds and 5 git commands to generate.