Commit daefd78b by Jason Merrill

Update weak symbol support

From-SVN: r9697
parent 27a2e668
...@@ -1791,6 +1791,7 @@ duplicate_decls (newdecl, olddecl) ...@@ -1791,6 +1791,7 @@ duplicate_decls (newdecl, olddecl)
} }
/* Merge the storage class information. */ /* Merge the storage class information. */
DECL_WEAK (newdecl) |= DECL_WEAK (olddecl);
/* For functions, static overrides non-static. */ /* For functions, static overrides non-static. */
if (TREE_CODE (newdecl) == FUNCTION_DECL) if (TREE_CODE (newdecl) == FUNCTION_DECL)
{ {
......
...@@ -17,10 +17,10 @@ You should have received a copy of the GNU General Public License ...@@ -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 along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Support #pragma weak by default if WEAK_ASM_OP and ASM_OUTPUT_DEF /* Support #pragma weak iff ASM_WEAKEN_LABEL and ASM_OUTPUT_DEF are
are defined. */ defined. */
#if !defined (HANDLE_PRAGMA_WEAK) && defined (WEAK_ASM_OP) && defined (ASM_OUTPUT_DEF) #if defined (ASM_WEAKEN_LABEL) && defined (ASM_OUTPUT_DEF)
#define HANDLE_PRAGMA_WEAK 1 #define HANDLE_PRAGMA_WEAK SUPPORTS_WEAK
#endif #endif
enum pragma_state enum pragma_state
......
...@@ -85,18 +85,3 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ ...@@ -85,18 +85,3 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
fputc ('\n', FILE); \ fputc ('\n', FILE); \
} \ } \
} while (0) } 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)
...@@ -118,7 +118,12 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ ...@@ -118,7 +118,12 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#define TYPE_ASM_OP ".type" #define TYPE_ASM_OP ".type"
#define SIZE_ASM_OP ".size" #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 /* The following macro defines the format used to output the second
operand of the .type assembler directive. Different svr4 assemblers operand of the .type assembler directive. Different svr4 assemblers
......
...@@ -94,7 +94,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ ...@@ -94,7 +94,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Handle #pragma weak and #pragma pack. */ /* Handle #pragma weak and #pragma pack. */
#define HANDLE_SYSV_PRAGMA #define HANDLE_SYSV_PRAGMA
#define HANDLE_PRAGMA_WEAK TARGET_ELF #define SUPPORTS_WEAK TARGET_ELF
/* Change default predefines. */ /* Change default predefines. */
#undef CPP_PREDEFINES #undef CPP_PREDEFINES
...@@ -617,9 +617,14 @@ while (0) ...@@ -617,9 +617,14 @@ while (0)
#define TYPE_ASM_OP ".type" #define TYPE_ASM_OP ".type"
#define SIZE_ASM_OP ".size" #define SIZE_ASM_OP ".size"
#define WEAK_ASM_OP ".weak"
#define SET_ASM_OP ".set" #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 /* The following macro defines the format used to output the second
operand of the .type assembler directive. Different svr4 assemblers operand of the .type assembler directive. Different svr4 assemblers
expect various different forms for this operand. The one given here expect various different forms for this operand. The one given here
......
...@@ -198,13 +198,13 @@ extern char * reg_names[]; ...@@ -198,13 +198,13 @@ extern char * reg_names[];
Redefined in sysv4.h, and luna.h. */ Redefined in sysv4.h, and luna.h. */
#define VERSION_INFO1 "88open OCS/BCS, " #define VERSION_INFO1 "88open OCS/BCS, "
#ifndef VERSION_INFO2 #ifndef VERSION_INFO2
#define VERSION_INFO2 "$Revision: 1.1.1.2.2.2 $" #define VERSION_INFO2 "$Revision: 1.63 $"
#endif #endif
#ifndef VERSION_STRING #ifndef VERSION_STRING
#define VERSION_STRING version_string #define VERSION_STRING version_string
#ifdef __STDC__ #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 #else
#define TM_RCS_ID "$What: <@(#) m88k.h,v 1.1.1.2.2.2> $" #define TM_RCS_ID "$What: <@(#) m88k.h,v 1.1.1.2.2.2> $"
#endif /* __STDC__ */ #endif /* __STDC__ */
...@@ -1542,7 +1542,7 @@ enum reg_class { NO_REGS, AP_REG, XRF_REGS, GENERAL_REGS, AGRF_REGS, ...@@ -1542,7 +1542,7 @@ enum reg_class { NO_REGS, AP_REG, XRF_REGS, GENERAL_REGS, AGRF_REGS,
#define HANDLE_SYSV_PRAGMA #define HANDLE_SYSV_PRAGMA
/* Tell when to handle #pragma weak. This is only done for V.4. */ /* 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 /* Max number of bytes we can move from memory to memory
in one reasonably fast instruction. */ in one reasonably fast instruction. */
...@@ -1725,7 +1725,6 @@ enum reg_class { NO_REGS, AP_REG, XRF_REGS, GENERAL_REGS, AGRF_REGS, ...@@ -1725,7 +1725,6 @@ enum reg_class { NO_REGS, AP_REG, XRF_REGS, GENERAL_REGS, AGRF_REGS,
#undef FINI_SECTION_ASM_OP #undef FINI_SECTION_ASM_OP
#undef TYPE_ASM_OP #undef TYPE_ASM_OP
#undef SIZE_ASM_OP #undef SIZE_ASM_OP
#undef WEAK_ASM_OP
#undef SET_ASM_OP #undef SET_ASM_OP
#undef SKIP_ASM_OP #undef SKIP_ASM_OP
#undef COMMON_ASM_OP #undef COMMON_ASM_OP
...@@ -1776,12 +1775,18 @@ enum reg_class { NO_REGS, AP_REG, XRF_REGS, GENERAL_REGS, AGRF_REGS, ...@@ -1776,12 +1775,18 @@ enum reg_class { NO_REGS, AP_REG, XRF_REGS, GENERAL_REGS, AGRF_REGS,
/* These are specific to PIC. */ /* These are specific to PIC. */
#define TYPE_ASM_OP "type" #define TYPE_ASM_OP "type"
#define SIZE_ASM_OP "size" #define SIZE_ASM_OP "size"
#define WEAK_ASM_OP "weak"
#ifndef AS_BUG_POUND_TYPE /* Faulty assemblers require @ rather than #. */ #ifndef AS_BUG_POUND_TYPE /* Faulty assemblers require @ rather than #. */
#undef TYPE_OPERAND_FMT #undef TYPE_OPERAND_FMT
#define TYPE_OPERAND_FMT "#%s" #define TYPE_OPERAND_FMT "#%s"
#endif #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. */ /* These are specific to version 03.00 assembler syntax. */
#define INTERNAL_ASM_OP "local" #define INTERNAL_ASM_OP "local"
#define VERSION_ASM_OP "version" #define VERSION_ASM_OP "version"
......
...@@ -82,10 +82,15 @@ ...@@ -82,10 +82,15 @@
#undef TYPE_ASM_OP #undef TYPE_ASM_OP
#undef SIZE_ASM_OP #undef SIZE_ASM_OP
#undef WEAK_ASM_OP
#define TYPE_ASM_OP ".type" #define TYPE_ASM_OP ".type"
#define SIZE_ASM_OP ".size" #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 /* The following macro defines the format used to output the second
operand of the .type assembler directive. Different svr4 assemblers operand of the .type assembler directive. Different svr4 assemblers
......
...@@ -20,18 +20,3 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ ...@@ -20,18 +20,3 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#define SUNOS4_SHARED_LIBRARIES 1 #define SUNOS4_SHARED_LIBRARIES 1
#include "sparc/sparc.h" #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)
...@@ -648,7 +648,12 @@ dtors_section () \ ...@@ -648,7 +648,12 @@ dtors_section () \
#define TYPE_ASM_OP ".type" #define TYPE_ASM_OP ".type"
#define SIZE_ASM_OP ".size" #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 /* The following macro defines the format used to output the second
operand of the .type assembler directive. Different svr4 assemblers operand of the .type assembler directive. Different svr4 assemblers
......
...@@ -131,3 +131,12 @@ do { fprintf (FILE, "\t%s\t", ASM_SHORT); \ ...@@ -131,3 +131,12 @@ do { fprintf (FILE, "\t%s\t", ASM_SHORT); \
} while (0) } while (0)
#endif #endif
#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
...@@ -31,6 +31,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ ...@@ -31,6 +31,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "tconfig.h" #include "tconfig.h"
#include "machmode.h" #include "machmode.h"
#include "defaults.h"
#ifndef L_trampoline #ifndef L_trampoline
#include <stddef.h> #include <stddef.h>
#endif #endif
...@@ -40,6 +41,10 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ ...@@ -40,6 +41,10 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#undef abort #undef abort
#endif #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 /* 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 file. This is used when the endianness is determined when the
compiler is run. */ compiler is run. */
...@@ -1606,9 +1611,15 @@ typedef void (*vfp)(void); ...@@ -1606,9 +1611,15 @@ typedef void (*vfp)(void);
extern vfp __new_handler; extern vfp __new_handler;
extern void __default_new_handler (void); 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 * void *
__builtin_new (size_t sz) __builtin_new (size_t sz)
#endif
{ {
void *p; void *p;
vfp handler = (__new_handler) ? __new_handler : __default_new_handler; vfp handler = (__new_handler) ? __new_handler : __default_new_handler;
...@@ -1633,9 +1644,15 @@ __builtin_new (size_t sz) ...@@ -1633,9 +1644,15 @@ __builtin_new (size_t sz)
extern void * __builtin_new (size_t); 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 * void *
__builtin_vec_new (size_t sz) __builtin_vec_new (size_t sz)
#endif
{ {
return __builtin_new (sz); return __builtin_new (sz);
} }
...@@ -1696,9 +1713,15 @@ __default_new_handler () ...@@ -1696,9 +1713,15 @@ __default_new_handler ()
by C++ programs to return to the free store a block of memory allocated by C++ programs to return to the free store a block of memory allocated
as a single object. */ 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 void
__builtin_delete (void *ptr) __builtin_delete (void *ptr)
#endif
{ {
if (ptr) if (ptr)
free (ptr); free (ptr);
...@@ -1712,9 +1735,15 @@ __builtin_delete (void *ptr) ...@@ -1712,9 +1735,15 @@ __builtin_delete (void *ptr)
extern void __builtin_delete (void *); 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 void
__builtin_vec_delete (void *ptr) __builtin_vec_delete (void *ptr)
#endif
{ {
__builtin_delete (ptr); __builtin_delete (ptr);
} }
......
...@@ -958,6 +958,9 @@ struct tree_type ...@@ -958,6 +958,9 @@ struct tree_type
/* Used to indicate that this DECL represents a compiler-generated entity. */ /* Used to indicate that this DECL represents a compiler-generated entity. */
#define DECL_ARTIFICIAL(NODE) ((NODE)->decl.artificial_flag) #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. */ /* Additional flags for language-specific uses. */
#define DECL_LANG_FLAG_0(NODE) ((NODE)->decl.lang_flag_0) #define DECL_LANG_FLAG_0(NODE) ((NODE)->decl.lang_flag_0)
#define DECL_LANG_FLAG_1(NODE) ((NODE)->decl.lang_flag_1) #define DECL_LANG_FLAG_1(NODE) ((NODE)->decl.lang_flag_1)
...@@ -997,7 +1000,8 @@ struct tree_decl ...@@ -997,7 +1000,8 @@ struct tree_decl
unsigned static_ctor_flag : 1; unsigned static_ctor_flag : 1;
unsigned static_dtor_flag : 1; unsigned static_dtor_flag : 1;
unsigned artificial_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_0 : 1;
unsigned lang_flag_1 : 1; unsigned lang_flag_1 : 1;
......
...@@ -802,6 +802,11 @@ assemble_start_function (decl, fnname) ...@@ -802,6 +802,11 @@ assemble_start_function (decl, fnname)
{ {
if (!first_global_object_name) if (!first_global_object_name)
STRIP_NAME_ENCODING (first_global_object_name, fnname); 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) if (output_bytecode)
BC_GLOBALIZE_LABEL (asm_out_file, fnname); BC_GLOBALIZE_LABEL (asm_out_file, fnname);
else else
...@@ -1172,6 +1177,11 @@ assemble_variable (decl, top_level, at_end, dont_output_data) ...@@ -1172,6 +1177,11 @@ assemble_variable (decl, top_level, at_end, dont_output_data)
{ {
if (!first_global_object_name) if (!first_global_object_name)
STRIP_NAME_ENCODING(first_global_object_name, 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); ASM_GLOBALIZE_LABEL (asm_out_file, name);
} }
#if 0 #if 0
...@@ -3964,14 +3974,12 @@ void ...@@ -3964,14 +3974,12 @@ void
declare_weak (decl) declare_weak (decl)
tree decl; tree decl;
{ {
#ifdef HANDLE_PRAGMA_WEAK
if (! TREE_PUBLIC (decl)) if (! TREE_PUBLIC (decl))
error_with_decl (decl, "weak declaration of `%s' must be public"); error_with_decl (decl, "weak declaration of `%s' must be public");
else else if (TREE_ASM_WRITTEN (decl))
handle_pragma_weak (ps_name, error_with_decl (decl, "weak declaration of `%s' must precede definition");
IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), else if (SUPPORTS_WEAK)
NULL_PTR); DECL_WEAK (decl) = 1;
#endif
} }
/* Emit any pending weak declarations. */ /* Emit any pending weak declarations. */
...@@ -3985,14 +3993,7 @@ weak_finish () ...@@ -3985,14 +3993,7 @@ weak_finish ()
struct weak_syms *t; struct weak_syms *t;
for (t = weak_decls; t; t = t->next) for (t = weak_decls; t; t = t->next)
{ {
fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP); ASM_WEAKEN_LABEL (asm_out_file, t->name);
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);
if (t->value) if (t->value)
ASM_OUTPUT_DEF (asm_out_file, t->name, t->value); ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
} }
...@@ -4014,6 +4015,11 @@ assemble_alias (decl, target) ...@@ -4014,6 +4015,11 @@ assemble_alias (decl, target)
if (TREE_PUBLIC (decl)) if (TREE_PUBLIC (decl))
{ {
#ifdef ASM_WEAKEN_LABEL
if (DECL_WEAK (decl))
ASM_WEAKEN_LABEL (asm_out_file, name);
else
#endif
if (output_bytecode) if (output_bytecode)
BC_GLOBALIZE_LABEL (asm_out_file, name); BC_GLOBALIZE_LABEL (asm_out_file, name);
else else
...@@ -4021,6 +4027,7 @@ assemble_alias (decl, target) ...@@ -4021,6 +4027,7 @@ assemble_alias (decl, target)
} }
ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target)); ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
TREE_ASM_WRITTEN (decl) = 1;
#else #else
warning ("alias definitions not supported in this configuration"); warning ("alias definitions not supported in this configuration");
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment