From 96fbe9dde2cd3dc9e6e5cea6905f8f98fdda1b4d Mon Sep 17 00:00:00 2001 From: rsandifo Date: Sat, 10 Jul 2010 08:35:58 +0000 Subject: [PATCH] gcc/ * tree.h (DECL_REPLACEABLE_P): Strengthen check for weak symbols. gcc/testsuite/ * gcc.dg/attr-weak-hidden-1.c, gcc.dg/attr-weak-hidden-1a.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@162031 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 4 ++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/attr-weak-hidden-1.c | 6 ++++++ gcc/testsuite/gcc.dg/attr-weak-hidden-1a.c | 9 +++++++++ gcc/tree.h | 7 ++++++- 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/attr-weak-hidden-1.c create mode 100644 gcc/testsuite/gcc.dg/attr-weak-hidden-1a.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 45f780a..8349373 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2010-07-10 Richard Sandiford + + * tree.h (DECL_REPLACEABLE_P): Strengthen check for weak symbols. + 2010-07-10 Iain Sandoe PR objc/44140 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6d0de14..f18f7b7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2010-07-10 Richard Sandiford + + * gcc.dg/attr-weak-hidden-1.c, gcc.dg/attr-weak-hidden-1a.c: New test. + 2010-07-10 Iain Sandoe PR objc/44140 diff --git a/gcc/testsuite/gcc.dg/attr-weak-hidden-1.c b/gcc/testsuite/gcc.dg/attr-weak-hidden-1.c new file mode 100644 index 0000000..968bab7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/attr-weak-hidden-1.c @@ -0,0 +1,6 @@ +/* { dg-do run } */ +/* { dg-require-weak "" } */ +/* { dg-require-visibility "" } */ +/* { dg-options "-O2" } */ +/* { dg-additional-sources "attr-weak-hidden-1a.c" } */ +int __attribute__((weak, visibility("hidden"))) foo (void) { return 0; } diff --git a/gcc/testsuite/gcc.dg/attr-weak-hidden-1a.c b/gcc/testsuite/gcc.dg/attr-weak-hidden-1a.c new file mode 100644 index 0000000..b04d8d2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/attr-weak-hidden-1a.c @@ -0,0 +1,9 @@ +void abort (void); +int __attribute__((weak, visibility("hidden"))) foo (void) { return 1; } +int +main (void) +{ + if (foo ()) + abort (); + return 0; +} diff --git a/gcc/tree.h b/gcc/tree.h index 59f6b3a..e749d69 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -3012,6 +3012,11 @@ struct GTY(()) tree_parm_decl { not be treated as replaceable so that use of C++ template instantiations is not penalized. + In other respects, the condition is usually equivalent to whether + the function binds to the current module (shared library or executable). + However, weak functions can always be overridden by earlier TUs + in the same module, even if they bind locally to that module. + For example, DECL_REPLACEABLE is used to determine whether or not a function (including a template instantiation) which is not explicitly declared "inline" can be inlined. If the function is @@ -3020,7 +3025,7 @@ struct GTY(()) tree_parm_decl { function that is not DECL_REPLACEABLE can be inlined, since all versions of the function will be functionally identical. */ #define DECL_REPLACEABLE_P(NODE) \ - (!DECL_COMDAT (NODE) && !targetm.binds_local_p (NODE)) + (!DECL_COMDAT (NODE) && (DECL_WEAK (NODE) || !targetm.binds_local_p (NODE))) /* The name of the object as the assembler will see it (but before any translations made by ASM_OUTPUT_LABELREF). Often this is the same -- 2.7.4