From 16515e5c198127bd9d9c4e313b6e061f29c3e3d5 Mon Sep 17 00:00:00 2001 From: Andrew Pinski Date: Fri, 17 Dec 2004 00:25:16 +0000 Subject: [PATCH] re PR target/19041 (-fvisibility=hidden causes bad codegen for common symbols) 2004-12-16 Andrew Pinski PR target/19041 * config/darwin.c (machopic_symbol_defined_p): Return false if the binds local and is a common symbol. 2004-12-16 Andrew Pinski PR target/19041 * gcc.dg/visibility-c.c: New test. From-SVN: r92292 --- gcc/ChangeLog | 6 ++++++ gcc/config/darwin.c | 28 +++++++++++++++++++++------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/visibility-c.c | 11 +++++++++++ 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/visibility-c.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b288e70dd95e..c323cbf4626d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2004-12-16 Andrew Pinski + + PR target/19041 + * config/darwin.c (machopic_symbol_defined_p): Return false + if the binds local and is a common symbol. + 2004-12-16 Richard Henderson * config/i386/i386.md (extv, extzv, insv): Revalidate the diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index e4a399781591..7b4943b5a159 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -90,16 +90,30 @@ name_needs_quotes (const char *name) return 0; } -/* - * flag_pic = 1 ... generate only indirections - * flag_pic = 2 ... generate indirections and pure code - */ - +/* Return true if SYM_REF can be used without an indirection. */ static int machopic_symbol_defined_p (rtx sym_ref) { - return (SYMBOL_REF_FLAGS (sym_ref) & MACHO_SYMBOL_FLAG_DEFINED) - || (SYMBOL_REF_LOCAL_P (sym_ref) && ! SYMBOL_REF_EXTERNAL_P (sym_ref)); + if (SYMBOL_REF_FLAGS (sym_ref) & MACHO_SYMBOL_FLAG_DEFINED) + return true; + + /* If a symbol references local and is not an extern to this + file, then the symbol might be able to declared as defined. */ + if (SYMBOL_REF_LOCAL_P (sym_ref) && ! SYMBOL_REF_EXTERNAL_P (sym_ref)) + { + /* If the symbol references a variable and the variable is a + common symbol, then this symbol is not defined. */ + if (SYMBOL_REF_FLAGS (sym_ref) & MACHO_SYMBOL_FLAG_VARIABLE) + { + tree decl = SYMBOL_REF_DECL (sym_ref); + if (!decl) + return true; + if (DECL_COMMON (decl)) + return false; + } + return true; + } + return false; } /* This module assumes that (const (symbol_ref "foo")) is a legal pic diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a92fedc4dc04..c5530fad3a48 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-12-16 Andrew Pinski + + PR target/19041 + * gcc.dg/visibility-c.c: New test. + 2004-12-16 Roger Sayle PR middle-end/18493 diff --git a/gcc/testsuite/gcc.dg/visibility-c.c b/gcc/testsuite/gcc.dg/visibility-c.c new file mode 100644 index 000000000000..66b4d2547c63 --- /dev/null +++ b/gcc/testsuite/gcc.dg/visibility-c.c @@ -0,0 +1,11 @@ +/* Test that visibility works on common symbols also. */ +/* { dg-do compile } */ +/* { dg-require-visibility "" } */ +/* { dg-final { scan-hidden "options" } } */ + +int options __attribute__((__visibility__("hidden"))); + +void f(void) +{ + options = 0; +} -- 2.47.2