From patchwork Thu Dec 10 07:21:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 555005 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 892AD140FD7 for ; Thu, 10 Dec 2015 18:22:07 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=F/cST8Pr; dkim-atps=neutral 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:to:subject:mime-version:content-type; q= dns; s=default; b=LAKHg7TjvWqypd14GB3JHCRvKGZRzNp4arsi3rL1LUB2Wf y2qo0I56Madnc9J/Ff/QGcGh4q4dPwoU2P0URZ0HkxUgC0U9jcKFOyf54W3UL/kt qLGgV+xzi2mOYmqgH5dPGl2b8pn5k4Ow51Y9S17cr2s397lqw2mCjBudAYBFY= 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:to:subject:mime-version:content-type; s= default; bh=UufG6wFU7Q0+qVCgTM1XxbFB5lU=; b=F/cST8PrjFnY4JS2nmqI MQ0n9yWQqqu1l/q3XUTuuAs+EIqQ9XxyGRXZ6qG9aHJuWebHS0GZvjJ0dAAUvOgG Q/4fv9VVDqNcLCqyWG1xv8lkJVdy3vjGjhAIHmH3+zygbWk6pLRJO37QdQEosEH7 Cizep3ZeXQtZ+Vg57aqvhms= Received: (qmail 13404 invoked by alias); 10 Dec 2015 07:21:59 -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 11803 invoked by uid 89); 10 Dec 2015 07:21:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: prv-mh.provo.novell.com Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 10 Dec 2015 07:21:57 +0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Thu, 10 Dec 2015 00:21:55 -0700 Message-Id: <5669362402000078000BDE99@prv-mh.provo.novell.com> Date: Thu, 10 Dec 2015 00:21:56 -0700 From: "Jan Beulich" To: Subject: check initializer to be zero in .bss-like sections Mime-Version: 1.0 Just like gas, which has recently learned to reject such initializers, gcc shouldn't accept such either. --- The only question really is whether the new test case should be limited to certain targets - I haven't been able to figure out possible valid qualifiers to use here. gcc/ 2015-12-10 Jan Beulich * varasm.c (get_variable_section): Validate initializer in named .bss-like sections. gcc/testsuite/ 2015-12-10 Jan Beulich * gcc.dg/bss.c: New. check initializer to be zero in .bss-like sections Just like gas, which has recently learned to reject such initializers, gcc shouldn't accept such either. --- The only question really is whether the new test case should be limited to certain targets - I haven't been able to figure out possible valid qualifiers to use here. gcc/ 2015-12-10 Jan Beulich * varasm.c (get_variable_section): Validate initializer in named .bss-like sections. gcc/testsuite/ 2015-12-10 Jan Beulich * gcc.dg/bss.c: New. --- 2015-12-09/gcc/testsuite/gcc.dg/bss.c +++ 2015-12-09/gcc/testsuite/gcc.dg/bss.c @@ -0,0 +1,8 @@ +/* Test non-zero initializers in .bss-like sections get properly refused. */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +int __attribute__((section(".bss.local"))) x = 1; /* { dg-error "" "zero init" } */ +int *__attribute__((section(".bss.local"))) px = &x; /* { dg-error "" "zero init" } */ +int __attribute__((section(".bss.local"))) y = 0; +int *__attribute__((section(".bss.local"))) py = (void*)0; --- 2015-12-09/gcc/varasm.c +++ 2015-12-09/gcc/varasm.c @@ -1150,7 +1150,18 @@ get_variable_section (tree decl, bool pr resolve_unique_section (decl, reloc, flag_data_sections); if (IN_NAMED_SECTION (decl)) - return get_named_section (decl, NULL, reloc); + { + section *sect = get_named_section (decl, NULL, reloc); + + if ((sect->common.flags & SECTION_BSS) && !bss_initializer_p (decl)) + { + error_at (DECL_SOURCE_LOCATION (decl), + "only zero initializers are allowed in section %qs", + sect->named.name); + DECL_INITIAL (decl) = error_mark_node; + } + return sect; + } if (ADDR_SPACE_GENERIC_P (as) && !DECL_THREAD_LOCAL_P (decl) --- 2015-12-09/gcc/testsuite/gcc.dg/bss.c +++ 2015-12-09/gcc/testsuite/gcc.dg/bss.c @@ -0,0 +1,8 @@ +/* Test non-zero initializers in .bss-like sections get properly refused. */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +int __attribute__((section(".bss.local"))) x = 1; /* { dg-error "" "zero init" } */ +int *__attribute__((section(".bss.local"))) px = &x; /* { dg-error "" "zero init" } */ +int __attribute__((section(".bss.local"))) y = 0; +int *__attribute__((section(".bss.local"))) py = (void*)0; --- 2015-12-09/gcc/varasm.c +++ 2015-12-09/gcc/varasm.c @@ -1150,7 +1150,18 @@ get_variable_section (tree decl, bool pr resolve_unique_section (decl, reloc, flag_data_sections); if (IN_NAMED_SECTION (decl)) - return get_named_section (decl, NULL, reloc); + { + section *sect = get_named_section (decl, NULL, reloc); + + if ((sect->common.flags & SECTION_BSS) && !bss_initializer_p (decl)) + { + error_at (DECL_SOURCE_LOCATION (decl), + "only zero initializers are allowed in section %qs", + sect->named.name); + DECL_INITIAL (decl) = error_mark_node; + } + return sect; + } if (ADDR_SPACE_GENERIC_P (as) && !DECL_THREAD_LOCAL_P (decl)