This patch fixes a problem with section anchors. Found on powerpc, but also
appears on MIPS and ARM targets.
Section anchors can only be used for definitions known to bind in the current
object file. The default predicate uses the bind_local_p hook to determine
this. Unfortunately that hook determines whether the decl's binding is
determined at static link time (i.e. within the dynamic object this object is
linked). That's very nearly the same, except for symbols that have a weak
hidden definition in this object file. For such symbols, binds_local_p returns
true, because the binding must be within the dynamic object. But we shouldn't
use a section anchor as a definition in a different object file could win at
static link time. (I'm not 100% sure there aren't other cases where
module-binding and object-binding differ for a definition.)
It surprised me that binds_local_p has the semantics it does -- perhaps its
meaning has changed, or it is simply poorly named. I would have thought
binds_module_p would be a better name.
Anyway, rather than go on a renaming exercise, I chose to adjust
default_use_anchors_for_symbol_p to reject any weak symbol.
tested on powerpc-linux-gnu, ok?
nathan
2013-05-08 Nathan Sidwell <nat...@codesourcery.com>
gcc/
* varasm.c (default_use_anchors_for_symbol_p): Reject WEAK.
gcc/testsuite/
* gcc.dg/visibility-21.c: New.
Index: gcc/varasm.c
===================================================================
--- gcc/varasm.c (revision 410150)
+++ gcc/varasm.c (working copy)
@@ -6871,6 +6871,11 @@ default_use_anchors_for_symbol_p (const_
if (!targetm.binds_local_p (decl))
return false;
+ /* Weak decls might be overridden, but could still be local to
+ the module. */
+ if (DECL_WEAK (decl))
+ return false;
+
/* Don't use section anchors for decls that will be placed in a
small data section. */
/* ??? Ideally, this check would be redundant with the SECTION_SMALL
Index: gcc/testsuite/gcc.dg/visibility-21.c
===================================================================
--- gcc/testsuite/gcc.dg/visibility-21.c (revision 0)
+++ gcc/testsuite/gcc.dg/visibility-21.c (revision 0)
@@ -0,0 +1,13 @@
+/* Test visibility attribute on function definition. */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fsection-anchors" } */
+/* { dg-require-visibility "" } */
+/* { dg-require-weak "" } */
+/* { dg-final { scan-assembler-not "ANCHOR" } } */
+
+int __attribute__((weak, visibility("hidden"))) weak_hidden[3];
+
+int *f_weak_hidden ()
+{
+ return weak_hidden;
+}