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]

[PATCH] Don't emit @local branches to weak symbols on rs6000


After a discussion with Ian Taylor, I agree with him that the current
behavior is incorrect.

--- Begin quote ---
As I noted in an earlier message, I believe that it is simply
incorrect to use @local on weak symbols.  Don't let the linkonce
section here mislead you.  Consider a case like

#pragma weak fn
int fn () { return 1; }
int foo () { return fn (); }

When you compile this code, gcc will presumably use @local in the call
to fn from foo.  Now put this code into a shared library.  Then
arrange to define fn as a strong definition in the main executable.
In this case, foo should actually call fn in the main executable,
which it of course can not do using @local.
--- End quote ---

Here's a patch to change this behavior on powerpc.  Running testsuite
now.


Dan

/--------------------------------\  /--------------------------------\
|       Daniel Jacobowitz        |__|        SCS Class of 2002       |
|   Debian GNU/Linux Developer    __    Carnegie Mellon University   |
|         dan@debian.org         |  |       dmj+@andrew.cmu.edu      |
\--------------------------------/  \--------------------------------/
diff -u gcc-2.95.orig/gcc/config/rs6000/rs6000.c ../gcc-2.95/gcc/config/rs6000/rs6000.c
--- gcc-2.95.orig/gcc/config/rs6000/rs6000.c	Tue Jul 13 19:20:53 1999
+++ ../gcc-2.95/gcc/config/rs6000/rs6000.c	Tue Jul 20 17:20:06 1999
@@ -1109,7 +1114,7 @@
 
 
 /* Return 1 if the operand is a SYMBOL_REF for a function known to be in
-   this file.  */
+   this file and the function is not weakly defined. */
 
 int
 current_file_function_operand (op, mode)
@@ -1118,7 +1123,8 @@
 {
   return (GET_CODE (op) == SYMBOL_REF
 	  && (SYMBOL_REF_FLAG (op)
-	      || op == XEXP (DECL_RTL (current_function_decl), 0)));
+	      || (op == XEXP (DECL_RTL (current_function_decl), 0)
+	          && !DECL_WEAK (current_function_decl))));
 }
 
 
@@ -5637,8 +5702,9 @@
   if (TREE_CODE (decl) == FUNCTION_DECL)
     {
       rtx sym_ref = XEXP (DECL_RTL (decl), 0);
-      if (TREE_ASM_WRITTEN (decl) || ! TREE_PUBLIC (decl))
+      if ((TREE_ASM_WRITTEN (decl) || ! TREE_PUBLIC (decl))
+          && !DECL_WEAK (decl))
 	SYMBOL_REF_FLAG (sym_ref) = 1;
 
       if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT)
 	{
diff -u gcc-2.95.orig/gcc/config/rs6000/rs6000.h ../gcc-2.95/gcc/config/rs6000/rs6000.h
--- gcc-2.95.orig/gcc/config/rs6000/rs6000.h	Thu Jun 24 09:14:47 1999
+++ ../gcc-2.95/gcc/config/rs6000/rs6000.h	Tue Jul 20 15:06:34 1999
@@ -2529,11 +2565,12 @@
 /* If we are referencing a function that is static or is known to be
    in this file, make the SYMBOL_REF special.  We can use this to indicate
    that we can branch to this function without emitting a no-op after the
-   call.  */
+   call.  Do not set this flag if the function is weakly defined. */
 
 #define ENCODE_SECTION_INFO(DECL)  \
   if (TREE_CODE (DECL) == FUNCTION_DECL			\
-      && (TREE_ASM_WRITTEN (DECL) || ! TREE_PUBLIC (DECL))) \
+      && (TREE_ASM_WRITTEN (DECL) || ! TREE_PUBLIC (DECL)) \
+      && !DECL_WEAK (DECL)) \
     SYMBOL_REF_FLAG (XEXP (DECL_RTL (DECL), 0)) = 1;
 
 /* Indicate that jump tables go in the text section.  */

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