From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 78651 invoked by alias); 17 Jul 2017 14:36:05 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 76833 invoked by uid 89); 17 Jul 2017 14:36:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=bss, sk:categor, H*r:2003 X-HELO: relay2-d.mail.gandi.net Received: from relay2-d.mail.gandi.net (HELO relay2-d.mail.gandi.net) (217.70.183.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 17 Jul 2017 14:36:02 +0000 Received: from britannica.bec.de (p200300D2ABD1A5104639C4FFFE599710.dip0.t-ipconnect.de [IPv6:2003:d2:abd1:a510:4639:c4ff:fe59:9710]) (Authenticated sender: joerg@bec.de) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id AA65FC5A53 for ; Mon, 17 Jul 2017 16:35:59 +0200 (CEST) Date: Mon, 17 Jul 2017 14:36:00 -0000 From: Joerg Sonnenberger To: gcc-patches@gcc.gnu.org Subject: Fix inconsistent section flags Message-ID: <20170717143547.GA23668@britannica.bec.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="BOKacYhQ+x31HxR3" Content-Disposition: inline User-Agent: Mutt/1.8.3 (2017-05-23) X-SW-Source: 2017-07/txt/msg00980.txt.bz2 --BOKacYhQ+x31HxR3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 492 Hello, attached patch fixes inconsistent handling of section flags when using the section attribute, i.e.: __attribute__((section("writable1"))) int foo1; __attribute__((section("readonly1"))) const int foo1c; __attribute__((section("writable2"))) int foo2 = 42; __attribute__((section("readonly2"))) const int foo2c = 42; should give section attributes of "aw", "a", "aw", "a" in that order. Currently, "foo1c" is classified as BSS though and therefore put into a writable section. Joerg --BOKacYhQ+x31HxR3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="varasm.c.diff" Content-length: 1497 diff --git a/gcc/varasm.c b/gcc/varasm.c index 45611a9a858..eaf78b28bc1 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -969,11 +969,17 @@ decode_reg_name (const char *name) } -/* Return true if DECL's initializer is suitable for a BSS section. */ +/* + * Return true if DECL's initializer is suitable for a BSS section. + * If there is an explicit section name attribute, assume that it is not + * for a BSS section, independent of the name. + */ bool bss_initializer_p (const_tree decl) { + if (DECL_SECTION_NAME (decl) != NULL) + return false; return (DECL_INITIAL (decl) == NULL /* In LTO we have no errors in program; error_mark_node is used to mark offlined constructors. */ @@ -6460,7 +6466,7 @@ categorize_decl_for_section (const_tree decl, int reloc) ret = SECCAT_BSS; else if (! TREE_READONLY (decl) || TREE_SIDE_EFFECTS (decl) - || ! TREE_CONSTANT (DECL_INITIAL (decl))) + || (DECL_INITIAL(decl) != NULL && ! TREE_CONSTANT (DECL_INITIAL (decl)))) { /* Here the reloc_rw_mask is not testing whether the section should be read-only or not, but whether the dynamic link will have to @@ -6504,6 +6510,7 @@ categorize_decl_for_section (const_tree decl, int reloc) no concept of a read-only thread-local-data section. */ if (ret == SECCAT_BSS || (flag_zero_initialized_in_bss + && DECL_INITIAL(decl) != NULL && initializer_zerop (DECL_INITIAL (decl)))) ret = SECCAT_TBSS; else --BOKacYhQ+x31HxR3--