From patchwork Sat Feb 7 12:27:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 437547 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C428114017B for ; Sat, 7 Feb 2015 23:28:20 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=J3u7Mq1LDf8vgjbSw gflUOqPPf9m6W6lSnCn969Hsey7P0zCSd81iPK5K5zce8Qd3+0200Hg3DKd53FhN 0qZkuD6D+Ac8Ac6J9OThtXM28XjLLWUJKnXAK5gFwDDIiT6HDf0/p7FNm+gI2B+D Ft4r3c4w61cS329WiZpJlExZhE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=h0dO3NtRXVMj76JQ/NUWBlY aIhA=; b=mXXAV0mj3AJDmkEP8Len3/7kMi7tVjnAlqonFcQYHln4UKb9bhDuNa6 7KAN9jCu4Z6Vs1W9+TlpcvhuL3apC/9FtAsV3VXFvr7sfQRRfIk3z52MuLPobxhp N15w1sErVMygL3KsXo7p/26Jp90lbadltIYBNpznB/QEGBAZarAw= Received: (qmail 31335 invoked by alias); 7 Feb 2015 12:27:46 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 31326 invoked by uid 89); 7 Feb 2015 12:27:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-pd0-f170.google.com Received: from mail-pd0-f170.google.com (HELO mail-pd0-f170.google.com) (209.85.192.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sat, 07 Feb 2015 12:27:43 +0000 Received: by pdbfp1 with SMTP id fp1so20487561pdb.2 for ; Sat, 07 Feb 2015 04:27:41 -0800 (PST) X-Received: by 10.70.100.105 with SMTP id ex9mr13332292pdb.159.1423312061657; Sat, 07 Feb 2015 04:27:41 -0800 (PST) Received: from gnu-tools-1.localdomain (c-24-7-26-57.hsd1.ca.comcast.net. [24.7.26.57]) by mx.google.com with ESMTPSA id r1sm10882877pdp.83.2015.02.07.04.27.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Feb 2015 04:27:41 -0800 (PST) Received: by gnu-tools-1.localdomain (Postfix, from userid 1000) id 0097E2008E; Sat, 7 Feb 2015 04:27:39 -0800 (PST) Date: Sat, 7 Feb 2015 04:27:39 -0800 From: "H.J. Lu" To: Jack Howarth Cc: GCC Patches Subject: Re: [PATCH] PR rtl-optimization/32219: optimizer causes wrong code in pic/hidden/weak symbol checking Message-ID: <20150207122739.GA25185@gmail.com> References: <20150206162314.GA12597@intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes On Sat, Feb 07, 2015 at 03:28:38AM -0500, Jack Howarth wrote: > H.J., > The new patch bootstraps okay on x86_64-apple-darwin14 but I Does it cause any regressions on x86_64-apple-darwin14? > discovered that you need a small adjustment in the deja-gnu > statements... > > --- /Users/howarth/gcc-5-20150206/gcc/testsuite/gcc.dg/visibility-22.c > 2015-02-06 21:45:04.000000000 -0500 > +++ /sw/src/fink.build/gcc50-5.0.0-1000/gcc-5-20150206/gcc/testsuite/gcc.dg/visibility-22.c > 2015-02-07 03:24:42.000000000 -0500 > @@ -8,9 +8,9 @@ > /* For kernel modules and static RTPs, the loader treats undefined weak > symbols in the same way as undefined strong symbols. The test > therefore fails to load, so skip it. */ > +/* { dg-options "-fPIC" { target fpic } } */ > /* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target > *-*-darwin* } } */ > /* { dg-additional-options "-Wl,-flat_namespace" { target > *-*-darwin[89]* } } */ > -/* { dg-options "-fPIC" { target fpic } } */ > > extern void foo () __attribute__((weak,visibility("hidden"))); > int > > If you don't define a dg-options line first, the dg-additional-options > lines have no effect. > Jack Here is the updated patch. H.J. --- From 8e61705db8177d41fac45dbeffa4faf6163d4c94 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 5 Feb 2015 14:28:58 -0800 Subject: [PATCH] Handle symbol visibility/locality for PIE/PIC If a hidden weak symbol isn't defined in the TU, we can't assume it will be defined in another TU at link time. It makes a difference in code generation when compiling for PIC. If we assume that a hidden weak undefined symbol is local, the address checking may be optimized out and leads to the wrong code. This means that a symbol with user specified visibility is local only if it is locally resolved or defined, not weak or not compiling for PIC. When symbol visibility is specified in the source, we should always output symbol visibility even if symbol isn't local to the TU. If a global data symbol is defined in the TU, it is always local to the executable, regardless if it is a common symbol or not. If we aren't compiling for shared library, locally defined global data symbol binds locally. gcc/ PR rtl-optimization/32219 * cgraphunit.c (varpool_node::finalize_decl): Set definition first before calling notice_global_symbol so that it is available to notice_global_symbol. * varasm.c (default_binds_local_p_1): Resolve defined data symbol locally if not building shared library. Resolve symbol with user specified visibility locally only if it is locally resolved or defined, not weak or not compiling for PIC. (default_elf_asm_output_external): Always output visibility specified in the source. * config/darwin-protos.h (darwin_output_external): New. * config/darwin.c (darwin_output_external): Likewise. * config/darwin.h (ASM_OUTPUT_EXTERNAL): Likewise. gcc/testsuite/ PR rtl-optimization/32219 * gcc.dg/visibility-22.c: New test. * gcc.dg/visibility-23.c: Likewise. * gcc.target/i386/pr32219-1.c: Likewise. * gcc.target/i386/pr32219-2.c: Likewise. * gcc.target/i386/pr32219-3.c: Likewise. * gcc.target/i386/pr32219-4.c: Likewise. * gcc.target/i386/pr32219-5.c: Likewise. * gcc.target/i386/pr32219-6.c: Likewise. * gcc.target/i386/pr32219-7.c: Likewise. * gcc.target/i386/pr32219-8.c: Likewise. * gcc.target/i386/pr64317.c: Expect GOTOFF relocation instead of GOT relocation. --- gcc/cgraphunit.c | 4 +++- gcc/config/darwin-protos.h | 1 + gcc/config/darwin.c | 15 +++++++++++++ gcc/config/darwin.h | 9 ++++++++ gcc/testsuite/gcc.dg/visibility-22.c | 22 +++++++++++++++++++ gcc/testsuite/gcc.dg/visibility-23.c | 14 +++++++++++++ gcc/testsuite/gcc.target/i386/pr32219-1.c | 16 ++++++++++++++ gcc/testsuite/gcc.target/i386/pr32219-2.c | 16 ++++++++++++++ gcc/testsuite/gcc.target/i386/pr32219-3.c | 17 +++++++++++++++ gcc/testsuite/gcc.target/i386/pr32219-4.c | 17 +++++++++++++++ gcc/testsuite/gcc.target/i386/pr32219-5.c | 16 ++++++++++++++ gcc/testsuite/gcc.target/i386/pr32219-6.c | 16 ++++++++++++++ gcc/testsuite/gcc.target/i386/pr32219-7.c | 17 +++++++++++++++ gcc/testsuite/gcc.target/i386/pr32219-8.c | 17 +++++++++++++++ gcc/testsuite/gcc.target/i386/pr64317.c | 2 +- gcc/varasm.c | 35 ++++++++++++++++++------------- 16 files changed, 217 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/visibility-22.c create mode 100644 gcc/testsuite/gcc.dg/visibility-23.c create mode 100644 gcc/testsuite/gcc.target/i386/pr32219-1.c create mode 100644 gcc/testsuite/gcc.target/i386/pr32219-2.c create mode 100644 gcc/testsuite/gcc.target/i386/pr32219-3.c create mode 100644 gcc/testsuite/gcc.target/i386/pr32219-4.c create mode 100644 gcc/testsuite/gcc.target/i386/pr32219-5.c create mode 100644 gcc/testsuite/gcc.target/i386/pr32219-6.c create mode 100644 gcc/testsuite/gcc.target/i386/pr32219-7.c create mode 100644 gcc/testsuite/gcc.target/i386/pr32219-8.c diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index 35b244e..71367a3 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -792,8 +792,10 @@ varpool_node::finalize_decl (tree decl) if (node->definition) return; - notice_global_symbol (decl); + /* Set definition first before calling notice_global_symbol so that + it is available to notice_global_symbol. */ node->definition = true; + notice_global_symbol (decl); if (TREE_THIS_VOLATILE (decl) || DECL_PRESERVE_P (decl) /* Traditionally we do not eliminate static variables when not optimizing and when not doing toplevel reoder. */ diff --git a/gcc/config/darwin-protos.h b/gcc/config/darwin-protos.h index 249b9c1..10a77fc 100644 --- a/gcc/config/darwin-protos.h +++ b/gcc/config/darwin-protos.h @@ -89,6 +89,7 @@ extern tree darwin_handle_weak_import_attribute (tree *node, tree name, extern void machopic_output_stub (FILE *, const char *, const char *); extern void darwin_globalize_label (FILE *, const char *); extern void darwin_assemble_visibility (tree, int); +extern void darwin_output_external (FILE *, tree, const char *name); extern void darwin_asm_output_dwarf_delta (FILE *, int, const char *, const char *); diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index 40804b8..5025ef7 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -2762,6 +2762,21 @@ darwin_assemble_visibility (tree decl, int vis) "not supported in this configuration; ignored"); } +/* Emit text to declare externally defined symbols. Used to support + undefined hidden visibility with Darwin's private extern feature. */ + +void +darwin_output_external (FILE *file ATTRIBUTE_UNUSED, tree decl, + const char *name ATTRIBUTE_UNUSED) +{ + /* We output the name if and only if TREE_SYMBOL_REFERENCED is set and + visibility is specified in the source in order to avoid putting out + names that are never really used. */ + if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) + && DECL_VISIBILITY_SPECIFIED (decl)) + darwin_assemble_visibility (decl, DECL_VISIBILITY (decl)); +} + /* vec used by darwin_asm_dwarf_section. Maybe a hash tab would be better here - but the intention is that this is a very short list (fewer than 16 items) and each entry should (ideally, diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index b61dbb5..c9a1b34 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -700,6 +700,15 @@ extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS]; #undef TARGET_ASM_ASSEMBLE_VISIBILITY #define TARGET_ASM_ASSEMBLE_VISIBILITY darwin_assemble_visibility +/* A C statement (sans semicolon) to output to the stdio stream STREAM + any text necessary for declaring the name of an external symbol + named NAME which is referenced in this compilation but not defined. + Used to support undefined hidden visibility with Darwin's private + extern feature. */ + +#undef ASM_OUTPUT_EXTERNAL +#define ASM_OUTPUT_EXTERNAL darwin_output_external + /* Extra attributes for Darwin. */ #define SUBTARGET_ATTRIBUTE_TABLE \ /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler, \ diff --git a/gcc/testsuite/gcc.dg/visibility-22.c b/gcc/testsuite/gcc.dg/visibility-22.c new file mode 100644 index 0000000..a118a6e --- /dev/null +++ b/gcc/testsuite/gcc.dg/visibility-22.c @@ -0,0 +1,22 @@ +/* PR target/32219 */ +/* { dg-do run } */ +/* { dg-require-visibility "" } */ +/* { dg-options "-O2 -fPIC" { target fpic } } */ +/* This test requires support for undefined weak symbols. This support + is not available on hppa*-*-hpux*. The test is skipped rather than + xfailed to suppress the warning that would otherwise arise. */ +/* { dg-skip-if "" { "hppa*-*-hpux*" "*-*-aix*" } "*" { "" } } */ +/* For kernel modules and static RTPs, the loader treats undefined weak + symbols in the same way as undefined strong symbols. The test + therefore fails to load, so skip it. */ +/* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */ +/* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */ + +extern void foo () __attribute__((weak,visibility("hidden"))); +int +main() +{ + if (foo) + foo (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/visibility-23.c b/gcc/testsuite/gcc.dg/visibility-23.c new file mode 100644 index 0000000..347578e --- /dev/null +++ b/gcc/testsuite/gcc.dg/visibility-23.c @@ -0,0 +1,14 @@ +/* PR target/32219 */ +/* { dg-do compile } */ +/* { dg-require-visibility "" } */ +/* { dg-final { scan-hidden "foo" } } */ +/* { dg-options "-O2 -fPIC" { target fpic } } */ + +extern void foo () __attribute__((weak,visibility("hidden"))); +int +main() +{ + if (foo) + foo (); + return 0; +} diff --git a/gcc/testsuite/gcc.target/i386/pr32219-1.c b/gcc/testsuite/gcc.target/i386/pr32219-1.c new file mode 100644 index 0000000..5bd80a0 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr32219-1.c @@ -0,0 +1,16 @@ +/* { dg-do compile { target *-*-linux* } } */ +/* { dg-options "-O2 -fpie" } */ + +/* Common symbol with -fpie. */ +int xxx; + +int +foo () +{ + return xxx; +} + +/* { dg-final { scan-assembler "movl\[ \t\]xxx\\(%rip\\), %eax" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-not "xxx@GOTPCREL" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler "movl\[ \t\]xxx@GOTOFF\\(%\[^,\]*\\), %eax" { target ia32 } } } */ +/* { dg-final { scan-assembler-not "movl\[ \t\]xxx@GOT\\(%\[^,\]*\\), %eax" { target ia32 } } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr32219-2.c b/gcc/testsuite/gcc.target/i386/pr32219-2.c new file mode 100644 index 0000000..0cf2eb5 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr32219-2.c @@ -0,0 +1,16 @@ +/* { dg-do compile { target *-*-linux* } } */ +/* { dg-options "-O2 -fpic" } */ + +/* Common symbol with -fpic. */ +int xxx; + +int +foo () +{ + return xxx; +} + +/* { dg-final { scan-assembler-not "movl\[ \t\]xxx\\(%rip\\), %eax" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler "xxx@GOTPCREL" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-not "movl\[ \t\]xxx@GOTOFF\\(%\[^,\]*\\), %eax" { target ia32 } } } */ +/* { dg-final { scan-assembler "movl\[ \t\]xxx@GOT\\(%\[^,\]*\\), %eax" { target ia32 } } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr32219-3.c b/gcc/testsuite/gcc.target/i386/pr32219-3.c new file mode 100644 index 0000000..911f2a5 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr32219-3.c @@ -0,0 +1,17 @@ +/* { dg-do compile { target *-*-linux* } } */ +/* { dg-options "-O2 -fpie" } */ + +/* Weak common symbol with -fpie. */ +__attribute__((weak)) +int xxx; + +int +foo () +{ + return xxx; +} + +/* { dg-final { scan-assembler "movl\[ \t\]xxx\\(%rip\\), %eax" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-not "xxx@GOTPCREL" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler "movl\[ \t\]xxx@GOTOFF\\(%\[^,\]*\\), %eax" { target ia32 } } } */ +/* { dg-final { scan-assembler-not "movl\[ \t\]xxx@GOT\\(%\[^,\]*\\), %eax" { target ia32 } } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr32219-4.c b/gcc/testsuite/gcc.target/i386/pr32219-4.c new file mode 100644 index 0000000..3d43439 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr32219-4.c @@ -0,0 +1,17 @@ +/* { dg-do compile { target *-*-linux* } } */ +/* { dg-options "-O2 -fpic" } */ + +/* Weak common symbol with -fpic. */ +__attribute__((weak)) +int xxx; + +int +foo () +{ + return xxx; +} + +/* { dg-final { scan-assembler-not "movl\[ \t\]xxx\\(%rip\\), %eax" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler "xxx@GOTPCREL" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-not "movl\[ \t\]xxx@GOTOFF\\(%\[^,\]*\\), %eax" { target ia32 } } } */ +/* { dg-final { scan-assembler "movl\[ \t\]xxx@GOT\\(%\[^,\]*\\), %eax" { target ia32 } } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr32219-5.c b/gcc/testsuite/gcc.target/i386/pr32219-5.c new file mode 100644 index 0000000..ee7442e --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr32219-5.c @@ -0,0 +1,16 @@ +/* { dg-do compile { target *-*-linux* } } */ +/* { dg-options "-O2 -fpie" } */ + +/* Initialized symbol with -fpie. */ +int xxx = -1; + +int +foo () +{ + return xxx; +} + +/* { dg-final { scan-assembler "movl\[ \t\]xxx\\(%rip\\), %eax" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-not "xxx@GOTPCREL" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler "movl\[ \t\]xxx@GOTOFF\\(%\[^,\]*\\), %eax" { target ia32 } } } */ +/* { dg-final { scan-assembler-not "movl\[ \t\]xxx@GOT\\(%\[^,\]*\\), %eax" { target ia32 } } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr32219-6.c b/gcc/testsuite/gcc.target/i386/pr32219-6.c new file mode 100644 index 0000000..f261433 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr32219-6.c @@ -0,0 +1,16 @@ +/* { dg-do compile { target *-*-linux* } } */ +/* { dg-options "-O2 -fpic" } */ + +/* Initialized symbol with -fpic. */ +int xxx = -1; + +int +foo () +{ + return xxx; +} + +/* { dg-final { scan-assembler-not "movl\[ \t\]xxx\\(%rip\\), %eax" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler "xxx@GOTPCREL" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-not "movl\[ \t\]xxx@GOTOFF\\(%\[^,\]*\\), %eax" { target ia32 } } } */ +/* { dg-final { scan-assembler "movl\[ \t\]xxx@GOT\\(%\[^,\]*\\), %eax" { target ia32 } } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr32219-7.c b/gcc/testsuite/gcc.target/i386/pr32219-7.c new file mode 100644 index 0000000..12aaf72 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr32219-7.c @@ -0,0 +1,17 @@ +/* { dg-do compile { target *-*-linux* } } */ +/* { dg-options "-O2 -fpie" } */ + +/* Weak initialized symbol with -fpie. */ +__attribute__((weak)) +int xxx = -1; + +int +foo () +{ + return xxx; +} + +/* { dg-final { scan-assembler "movl\[ \t\]xxx\\(%rip\\), %eax" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-not "xxx@GOTPCREL" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler "movl\[ \t\]xxx@GOTOFF\\(%\[^,\]*\\), %eax" { target ia32 } } } */ +/* { dg-final { scan-assembler-not "movl\[ \t\]xxx@GOT\\(%\[^,\]*\\), %eax" { target ia32 } } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr32219-8.c b/gcc/testsuite/gcc.target/i386/pr32219-8.c new file mode 100644 index 0000000..2e4fba0 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr32219-8.c @@ -0,0 +1,17 @@ +/* { dg-do compile { target *-*-linux* } } */ +/* { dg-options "-O2 -fpic" } */ + +/* Weak initialized symbol with -fpic. */ +__attribute__((weak)) +int xxx = -1; + +int +foo () +{ + return xxx; +} + +/* { dg-final { scan-assembler-not "movl\[ \t\]xxx\\(%rip\\), %eax" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler "xxx@GOTPCREL" { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-not "movl\[ \t\]xxx@GOTOFF\\(%\[^,\]*\\), %eax" { target ia32 } } } */ +/* { dg-final { scan-assembler "movl\[ \t\]xxx@GOT\\(%\[^,\]*\\), %eax" { target ia32 } } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr64317.c b/gcc/testsuite/gcc.target/i386/pr64317.c index 33f5b5d..32969fc 100644 --- a/gcc/testsuite/gcc.target/i386/pr64317.c +++ b/gcc/testsuite/gcc.target/i386/pr64317.c @@ -1,7 +1,7 @@ /* { dg-do compile { target { *-*-linux* && ia32 } } } */ /* { dg-options "-O2 -fpie" } */ /* { dg-final { scan-assembler "addl\[ \\t\]+\[$\]_GLOBAL_OFFSET_TABLE_, %ebx" } } */ -/* { dg-final { scan-assembler "movl\[ \\t\]+c@GOT\[(\]%ebx\[)\]" } } */ +/* { dg-final { scan-assembler "movl\[ \\t\]+c@GOTOFF\[(\]%ebx\[)\]" } } */ /* { dg-final { scan-assembler-not "movl\[ \\t\]+\[0-9]+\[(\]%esp\[)\], %ebx" } } */ long c; diff --git a/gcc/varasm.c b/gcc/varasm.c index eb65b1f..f7c13af 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -6826,11 +6826,17 @@ default_binds_local_p_1 (const_tree exp, int shlib) && (TREE_STATIC (exp) || DECL_EXTERNAL (exp))) { varpool_node *vnode = varpool_node::get (exp); - if (vnode && (resolution_local_p (vnode->resolution) || vnode->in_other_partition)) - resolved_locally = true; - if (vnode - && resolution_to_local_definition_p (vnode->resolution)) - resolved_to_local_def = true; + /* If not building shared library, common or initialized symbols + are also resolved locally, regardless they are weak or not. */ + if (vnode) + { + if ((!shlib && vnode->definition) + || vnode->in_other_partition + || resolution_local_p (vnode->resolution)) + resolved_locally = true; + if (resolution_to_local_definition_p (vnode->resolution)) + resolved_to_local_def = true; + } } else if (TREE_CODE (exp) == FUNCTION_DECL && TREE_PUBLIC (exp)) { @@ -6859,9 +6865,14 @@ default_binds_local_p_1 (const_tree exp, int shlib) else if (! TREE_PUBLIC (exp)) local_p = true; /* A variable is local if the user has said explicitly that it will - be. */ + be and it is resolved or defined locally, not compiling for PIC or + not weak. */ else if ((DECL_VISIBILITY_SPECIFIED (exp) || resolved_to_local_def) + && (resolved_locally + || !flag_pic + || !DECL_EXTERNAL (exp) + || !DECL_WEAK (exp)) && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT) local_p = true; /* Variables defined outside this object might not be local. */ @@ -6880,13 +6891,6 @@ default_binds_local_p_1 (const_tree exp, int shlib) symbols resolved from other modules. */ else if (shlib) local_p = false; - /* Uninitialized COMMON variable may be unified with symbols - resolved from other modules. */ - else if (DECL_COMMON (exp) - && !resolved_locally - && (DECL_INITIAL (exp) == NULL - || (!in_lto_p && DECL_INITIAL (exp) == error_mark_node))) - local_p = false; /* Otherwise we're left with initialized (or non-common) global data which is of necessity defined locally. */ else @@ -7445,9 +7449,10 @@ default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED, { /* We output the name if and only if TREE_SYMBOL_REFERENCED is set in order to avoid putting out names that are never really - used. */ + used. Always output visibility specified in the source. */ if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) - && targetm.binds_local_p (decl)) + && (DECL_VISIBILITY_SPECIFIED (decl) + || targetm.binds_local_p (decl))) maybe_assemble_visibility (decl); }