From patchwork Wed May 8 11:57:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 242566 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id B0A022C0089 for ; Wed, 8 May 2013 21:57:49 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=jX3yO6ocwSHKxdwc7zsBsAcc83OB36rqe5KXhWbbBDxfTt 9Ua2lbUor5VFsMIyBchSbH9dHnCg4BTtjdSY9625FN2z/yORtUJ9JXpoxAwOom0g 4gM5V01Mu4B5QClpFbWoD/Pxr/mPmMeSNw93KDDq4FH400Beq9GsGAeETAFjs= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=eKcSM7h9Fv5Z2cNuq5X+5y8b5JA=; b=K1pFg1hizODCfgsAHoET u2lXy0fbOK9sS8OIwgkA+qqeUFURjsNBywe4ynatSiKZYIO4TYIK0gxq4RDr8FXn msHbxeIV38qyH+eq/M/toTIiScUOzg71imaRP2YjfoVOPk3JlpowR8usE7pOOJZK JUyWuu637dc0JTZ2BCKzrfo= Received: (qmail 14541 invoked by alias); 8 May 2013 11:57:43 -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 14498 invoked by uid 89); 8 May 2013 11:57:37 -0000 X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, SPF_PASS autolearn=ham version=3.3.1 Received: from mail-ea0-f175.google.com (HELO mail-ea0-f175.google.com) (209.85.215.175) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 08 May 2013 11:57:08 +0000 Received: by mail-ea0-f175.google.com with SMTP id q10so869412eaj.20 for ; Wed, 08 May 2013 04:57:06 -0700 (PDT) X-Received: by 10.14.106.200 with SMTP id m48mr16434382eeg.17.1368014226529; Wed, 08 May 2013 04:57:06 -0700 (PDT) Received: from [192.168.44.100] ([90.204.76.101]) by mx.google.com with ESMTPSA id w52sm44883089eev.12.2013.05.08.04.57.05 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 08 May 2013 04:57:05 -0700 (PDT) Message-ID: <518A3D8E.5020800@acm.org> Date: Wed, 08 May 2013 12:57:02 +0100 From: Nathan Sidwell User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130311 Thunderbird/17.0.4 MIME-Version: 1.0 To: GCC Patches Subject: section anchors and weak hidden symbols X-Virus-Found: No 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 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; +}