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]
Other format: [Raw text]

[PATCH]: Fix PR42854 so weak linking works again on darwin


  The commit to fix PR c++/42608 (revision 155919) broke the darwin
weak linking support as shown by the failures of gcc.dg/darwin-weakimport-1.c
and gcc.dg/darwin-weakimport-3.c to avoid emitting .weak_definition's
and coalesced entries for .sections in the generated assembly.
The first part of the problem is due to assemble_external no longer
adding decls which have the weak_import attribute. Avoiding the check
for the weak attribute if OBJECT_FORMAT_MACHO addresses this issue. The second
problem is that the change in declare_weak blindly assigns the
weak attribute to both weak and weak_import symbols on darwin. This
can be avoided by checking for the darwin-specific OBJECT_FORMAT_MACHO.
Since darwin never suffered from PR c++/42608, these changes introduce
no regressions and eliminate those from PR42854. Regression checked
on x86_64-apple-darwin10. Okay for gcc trunk and gcc 4.4 branch (as
revision 155919 also made its way into gcc 4.4.3 which suffers this
regression as well)?
                   Jack

2010-02-13  Jack Howarth <howarth@bromo.med.uc.edu>

        PR 42854
        * gcc/varasm.c: (declare_weak): Don't add weak attribute to
        decl if OBJECT_FORMAT_MACHO.
        (assemble_external): Don't restrict adding decls those with weak
	attribute if OBJECT_FORMAT_MACHO.

Index: gcc/varasm.c
===================================================================
--- gcc/varasm.c	(revision 156750)
+++ gcc/varasm.c	(working copy)
@@ -2345,7 +2345,9 @@
 	 for declarations that can be weak, it happens to be
 	 match.  */
       && !TREE_STATIC (decl)
+#ifndef OBJECT_FORMAT_MACHO
       && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
+#endif
       && value_member (decl, weak_decls) == NULL_TREE)
     weak_decls = tree_cons (NULL, decl, weak_decls);
 
@@ -5290,9 +5292,11 @@
     warning (0, "weak declaration of %q+D not supported", decl);
 
   mark_weak (decl);
+#ifndef OBJECT_FORMAT_MACHO
   if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl)))
     DECL_ATTRIBUTES (decl)
       = tree_cons (get_identifier ("weak"), NULL, DECL_ATTRIBUTES (decl));
+#endif
 }
 
 static void


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