This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Handle weak symbols
On Friday 11 May 2001 20:37, Mark Mitchell wrote:
> >>>>> "Franz" == Franz Sirl <Franz.Sirl-kernel@lauterbach.com> writes:
>
> Franz> OK to commit to mainline and branch?
>
> Yes -- but you need rtl.texi documentation for SYMBOL_REF_WEAK.
>
> Also, gcc.texi says:
>
> This section lists changes that people frequently request, but which
> we do not make because we think GCC is better without them.
>
> And then goes on to list:
>
> @item
> Assuming (for optimization) that the address of an external symbol is
> never zero.
>
> This assumption is false on certain systems when @samp{#pragma weak} is
> used.
>
> Obviously, the documentation has been lying here for ages -- we *do*
> make this optimization, and have at least since GCC 2.95.2.
>
> Please remove this bullet as well.
Done. OK to commit?
Franz.
* rtl.h (SYMBOL_REF_WEAK): New macro.
* rtlanal.h (rtx_addr_can_trap): Use it, a weak SYMBOL_REF can trap.
* varasm.c (make_decl_rtl): Mark SYMBOL_REF weak if necessary.
* rtl.texi (SYMBOL_REF_WEAK): Document it.
* gcc.texi: Remove wrong description.
Index: gcc/gcc.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.texi,v
retrieving revision 1.85
diff -u -p -r1.85 gcc.texi
--- gcc/gcc.texi 2001/05/09 14:16:46 1.85
+++ gcc/gcc.texi 2001/05/13 20:13:14
@@ -2008,13 +2008,6 @@ clutter the program with a cast to @code
useful.
@item
-Assuming (for optimization) that the address of an external symbol is
-never zero.
-
-This assumption is false on certain systems when @samp{#pragma weak} is
-used.
-
-@item
Making @samp{-fshort-enums} the default.
This would cause storage layout to be incompatible with most other C
Index: gcc/rtl.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/rtl.h,v
retrieving revision 1.257
diff -u -p -r1.257 rtl.h
--- gcc/rtl.h 2001/04/28 19:16:29 1.257
+++ gcc/rtl.h 2001/05/13 20:13:16
@@ -162,7 +162,8 @@ typedef struct rtx_def
unsigned int used : 1;
/* Nonzero if this rtx came from procedure integration.
In a REG, nonzero means this reg refers to the return value
- of the current function. */
+ of the current function.
+ 1 in a SYMBOL_REF if the symbol is weak. */
unsigned integrated : 1;
/* 1 in an INSN or a SET if this rtx is related to the call frame,
either changing how we compute the frame address or saving and
@@ -933,6 +934,9 @@ extern unsigned int subreg_regno PARAMS
/* 1 means a SYMBOL_REF has been the library function in emit_library_call. */
#define SYMBOL_REF_USED(RTX) ((RTX)->used)
+
+/* 1 means a SYMBOL_REF is weak. */
+#define SYMBOL_REF_WEAK(RTX) ((RTX)->integrated)
/* Define a macro to look for REG_INC notes,
but save time on machines where they never exist. */
Index: gcc/rtl.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/rtl.texi,v
retrieving revision 1.38
diff -u -p -r1.38 rtl.texi
--- gcc/rtl.texi 2001/04/19 19:44:12 1.38
+++ gcc/rtl.texi 2001/05/13 20:13:19
@@ -496,6 +496,13 @@ once. Stored in the @code{used} field.
In a @code{symbol_ref}, this is used as a flag for machine-specific purposes.
Stored in the @code{volatil} field and printed as @samp{/v}.
+@findex SYMBOL_REF_WEAK
+@cindex @code{symbol_ref} and @samp{/i}
+@cindex @code{integrated}, in @code{symbol_ref}
+@item SYMBOL_REF_WEAK (@var{x})
+In a @code{symbol_ref}, indicates that @var{x} has been declared weak.
+Stored in the @code{integrated} field and printed as @samp{/i}.
+
@findex LABEL_OUTSIDE_LOOP_P
@cindex @code{label_ref} and @samp{/s}
@cindex @code{in_struct}, in @code{label_ref}
Index: gcc/rtlanal.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/rtlanal.c,v
retrieving revision 1.94
diff -u -p -r1.94 rtlanal.c
--- gcc/rtlanal.c 2001/05/02 14:31:45 1.94
+++ gcc/rtlanal.c 2001/05/13 20:13:20
@@ -207,11 +207,9 @@ rtx_addr_can_trap_p (x)
switch (code)
{
case SYMBOL_REF:
+ return SYMBOL_REF_WEAK (x);
+
case LABEL_REF:
- /* SYMBOL_REF is problematic due to the possible presence of
- a #pragma weak, but to say that loads from symbols can trap is
- *very* costly. It's not at all clear what's best here. For
- now, we ignore the impact of #pragma weak. */
return 0;
case REG:
Index: gcc/varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.173
diff -u -p -r1.173 varasm.c
--- gcc/varasm.c 2001/05/01 12:11:34 1.173
+++ gcc/varasm.c 2001/05/13 20:13:22
@@ -747,6 +747,7 @@ make_decl_rtl (decl, asmspec)
SET_DECL_RTL (decl, gen_rtx_MEM (DECL_MODE (decl),
gen_rtx_SYMBOL_REF (Pmode, name)));
+ SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = DECL_WEAK (decl);
if (TREE_CODE (decl) != FUNCTION_DECL)
set_mem_attributes (DECL_RTL (decl), decl, 1);