From patchwork Sun Nov 15 22:02:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jozef Lawrynowicz X-Patchwork-Id: 1400575 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mittosystems.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=mittosystems.com header.i=@mittosystems.com header.a=rsa-sha256 header.s=google header.b=PxzjXD9s; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CZ5mq1d5gz9s0b for ; Mon, 16 Nov 2020 09:03:03 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A00C73858C2B; Sun, 15 Nov 2020 22:03:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by sourceware.org (Postfix) with ESMTPS id 2465A3858C27 for ; Sun, 15 Nov 2020 22:02:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2465A3858C27 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=mittosystems.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=jozef.l@mittosystems.com Received: by mail-wm1-x344.google.com with SMTP id a65so22017276wme.1 for ; Sun, 15 Nov 2020 14:02:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mittosystems.com; s=google; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition; bh=wrcUbQF09NUZN1rCeu2UQRl0fNySfOHKxEdNPePJUkw=; b=PxzjXD9sFYHaK8VIlWQoncyYw9A2XFeFd/imOfwg+Ck6GQbNMO5EKFnmY+telEgJUS amn2lwjf4Wf7MAIUM0xT1NLdyQAYgMb5BIrIVtKzukOxwiA9SjtGYbU2WfDbUzNMzz+K bIMGVuAxjzkGvFoHp4bGvnd1zykan9ox6hHMlOk6s6xv/74X4kJTouU7073A2VvNf85m lp09ROdDSVoMQb7XFOY6UONOwnYAK6J++se+UUM6dH6iM5ezYJ94FUNmwZPHWPpmI48J FPuW2xF/JVznrPzSef7sHSHA1vR0hv9JqKgzYNwRZFjR3jBAAXkW8cSj63qOyHpO3xjo UhkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :mime-version:content-disposition; bh=wrcUbQF09NUZN1rCeu2UQRl0fNySfOHKxEdNPePJUkw=; b=snu442au/GgCidy65Qnw4VmJOftspjRsP7B3DRSDX8T6kv2B7JSP9MmCVEQOoGPjyJ 1DOyFBuCdDDSp6WllR3OnXQK1wJlS0cjP7m17fBkU6ZMpBgx4M1YwHamjdsBpmTFIlj1 AEXoIfCBZNwl+TTbNUBmpoTg+Q3xIKIqmgx0cQniUQsjYhqjbZ/IikvediJccyT1lTbb iVqiN3/8B5/rUZsYU2iniWbpQ12CzxBUQ+nBgV0Meg5eljJ2tZ7N6r5vENavQ5MIl3XE Gz1QjIuiTyUmwG0JI07+jeT9FisR3KIjiqt/9Phh9wzKjtoIpu3Qg8qXQpIDTmTH+3C2 nqYQ== X-Gm-Message-State: AOAM5337zI/E7heEKUaiVK+TqHkDoZDXESB3QQ0TWUwFZm6eDSpJZmL+ 9S9SWH+DiSMTl1pqTwIdveo97X+83adN0A== X-Google-Smtp-Source: ABdhPJzzdY3t5mKtglBq+uPQhQXmopUY3Er8QMEyIFF61HWt+OJJQhzAleZYROcY9pgtAGMpBavERA== X-Received: by 2002:a1c:bd0b:: with SMTP id n11mr12711426wmf.111.1605477774760; Sun, 15 Nov 2020 14:02:54 -0800 (PST) Received: from jozef-acer-manjaro ([2a01:4b00:87fd:900:5e1d:5c99:56da:76e8]) by smtp.gmail.com with ESMTPSA id t11sm17465596wmf.35.2020.11.15.14.02.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Nov 2020 14:02:53 -0800 (PST) Date: Sun, 15 Nov 2020 22:02:52 +0000 From: Jozef Lawrynowicz To: gcc-patches@gcc.gnu.org Subject: [PATCH V2 0/3] Fix "noinit" attr, implement "persistent" attr Message-ID: <20201115220252.52ps4tgdsejnzh4w@jozef-acer-manjaro> Mail-Followup-To: gcc-patches@gcc.gnu.org MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This patch series is version 2 of https://gcc.gnu.org/pipermail/gcc-patches/2020-October/557184.html The implementation is now simplified so as to not use a symtab flag for "noinit" variables, instead we just check whether the decl has the attribute set. This patch series fixes behavior related to the "noinit" attribute, and makes the MSP430 "persistent" attribute generic, so it can be used for ARM. These attributes are related because they are both used to mark variables that should not be initialized by the target's runtime startup code. The "noinit" attribute is used for variables that are not initialized to any value by the program loader, or the runtime startup code. This attribute was made generic for GCC 10, whilst previously it was only supported for MSP430. There are a couple of issues when using it for arm-eabi: - It does not work at -O0. The test for it is in the torture directory but only runs at -O2, which is why this bug was undetected. - It does not work with -fdata-sections. Patch 1 fixes these issues. The "persistent" attribute is used for variables that *are* initialized by the program loader, but are not initialized by the runtime startup code. "persistent" variables are placed in a non-volatile area of memory, which allows their value to "persist" between processor resets. The "persistent" attribute is already implemented for msp430-elf, but patch 3 makes it generic so it can be leveraged by ARM targets. The ".persistent" section is pervasive in linker scripts distributed for ARM devices by manufacturers such as ST and TI. Patch 2 enables validation of the "persistent" attribute for when compiling C++ programs. I've attached a Binutils patch that adds the ".persistent" section to the default ARM linker script. I'll apply it alongside this GCC patch. Side note: There is handling of a ".persistent.bss" section, however this is Ada-specific and unrelated to the "noinit" and "persistent" attributes. The handling of the "noinit" and "persistent" attributes does not interfere with it. msp430-elf "persistent" attribute behaviour needs changing if this patch is approved, I have a patch ready to do that. Successfully regtested for arm-none-eabi. Ok for trunk? Jozef Lawrynowicz (3): Fix "noinit" attribute being ignored for -O0 and -fdata-sections cp/decl.c: Set DECL_INITIAL before attribute processing Implement the "persistent" attribute gcc/c-family/c-attribs.c | 141 ++++++++++++------ gcc/cp/decl.c | 13 ++ gcc/doc/extend.texi | 20 ++- .../c-c++-common/torture/attr-noinit-1.c | 7 + .../c-c++-common/torture/attr-noinit-2.c | 8 + .../c-c++-common/torture/attr-noinit-3.c | 11 ++ .../torture/attr-noinit-invalid.c | 12 ++ .../torture/attr-noinit-main.inc} | 37 ++--- .../c-c++-common/torture/attr-persistent-1.c | 8 + .../c-c++-common/torture/attr-persistent-2.c | 8 + .../c-c++-common/torture/attr-persistent-3.c | 10 ++ .../torture/attr-persistent-invalid.c | 11 ++ .../torture/attr-persistent-main.inc | 58 +++++++ .../g++.target/msp430/data-attributes.C | 52 +++++++ gcc/testsuite/g++.target/msp430/msp430.exp | 44 ++++++ .../gcc.target/msp430/data-attributes-2.c | 1 + gcc/testsuite/lib/target-supports.exp | 15 +- gcc/tree.h | 14 ++ gcc/varasm.c | 29 +++- 19 files changed, 426 insertions(+), 73 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/torture/attr-noinit-1.c create mode 100644 gcc/testsuite/c-c++-common/torture/attr-noinit-2.c create mode 100644 gcc/testsuite/c-c++-common/torture/attr-noinit-3.c create mode 100644 gcc/testsuite/c-c++-common/torture/attr-noinit-invalid.c rename gcc/testsuite/{gcc.c-torture/execute/noinit-attribute.c => c-c++-common/torture/attr-noinit-main.inc} (56%) create mode 100644 gcc/testsuite/c-c++-common/torture/attr-persistent-1.c create mode 100644 gcc/testsuite/c-c++-common/torture/attr-persistent-2.c create mode 100644 gcc/testsuite/c-c++-common/torture/attr-persistent-3.c create mode 100644 gcc/testsuite/c-c++-common/torture/attr-persistent-invalid.c create mode 100644 gcc/testsuite/c-c++-common/torture/attr-persistent-main.inc create mode 100644 gcc/testsuite/g++.target/msp430/data-attributes.C create mode 100644 gcc/testsuite/g++.target/msp430/msp430.exp diff --git a/ld/emulparams/armelf.sh b/ld/emulparams/armelf.sh index 24ca8ed59d..f9ccc499cc 100644 --- a/ld/emulparams/armelf.sh +++ b/ld/emulparams/armelf.sh @@ -10,7 +10,7 @@ OTHER_TEXT_SECTIONS='*(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx)' OTHER_BSS_SYMBOLS="${CREATE_SHLIB+PROVIDE (}__bss_start__ = .${CREATE_SHLIB+)};" OTHER_BSS_END_SYMBOLS="${CREATE_SHLIB+PROVIDE (}_bss_end__ = .${CREATE_SHLIB+)}; ${CREATE_SHLIB+PROVIDE (}__bss_end__ = .${CREATE_SHLIB+)};" OTHER_END_SYMBOLS="${CREATE_SHLIB+PROVIDE (}__end__ = .${CREATE_SHLIB+)};" -OTHER_SECTIONS=' +OTHER_SECTIONS=" .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) } /* This section contains data that is not initialised during load *or* application reset. */ @@ -18,11 +18,21 @@ OTHER_SECTIONS=' { . = ALIGN(2); PROVIDE (__noinit_start = .); - *(.noinit) + *(.noinit${RELOCATING+ .noinit.* .gnu.linkonce.n.*}) . = ALIGN(2); PROVIDE (__noinit_end = .); } -' +/* This section contains data that *is* initialized during load, + but *not* during application reset. */ + .persistent : + { + . = ALIGN(2); + PROVIDE (__persistent_start = .); + *(.persistent${RELOCATING+ .persistent.* .gnu.linkonce.p.*}) + . = ALIGN(2); + PROVIDE (__persistent_end = .); + } +" ATTRS_SECTIONS='.ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }' OTHER_READONLY_SECTIONS=" .ARM.extab ${RELOCATING-0} : { *(.ARM.extab${RELOCATING+* .gnu.linkonce.armextab.*}) } diff --git a/ld/testsuite/ld-elf/noinit-sections-1.d b/ld/testsuite/ld-elf/noinit-sections-1.d new file mode 100644 index 0000000000..7e35cd2a82 --- /dev/null +++ b/ld/testsuite/ld-elf/noinit-sections-1.d @@ -0,0 +1,11 @@ +#name: .noinit and .persistent sections +#ld: --orphan-handling=warn -e _start +#source: noinit-sections.s +#target: arm-*-* msp430-*-elf +#readelf: -SW + +#... + +\[ *[0-9]+\] \.noinit +NOBITS +[0-9a-f]+ +[0-9a-f]+ [0-9a-f]+ +00 +WA .* +#... + +\[ *[0-9]+\] \.persistent +PROGBITS +[0-9a-f]+ +[0-9a-f]+ [0-9a-f]+ +00 +WA .* +#pass diff --git a/ld/testsuite/ld-elf/noinit-sections-2.d b/ld/testsuite/ld-elf/noinit-sections-2.d new file mode 100644 index 0000000000..190c46fcf3 --- /dev/null +++ b/ld/testsuite/ld-elf/noinit-sections-2.d @@ -0,0 +1,12 @@ +#name: .noinit and .persistent sections (ld -r) +#ld: --orphan-handling=warn -e _start -r +#source: noinit-sections.s +#target: arm-*-* msp430-*-elf +#readelf: -SW +#warning_output: noinit-sections-2.l + +#... + +\[ *[0-9]+\] \.noinit +NOBITS +[0-9a-f]+ +[0-9a-f]+ [0-9a-f]+ +00 +WA .* +#... + +\[ *[0-9]+\] \.persistent +PROGBITS +[0-9a-f]+ +[0-9a-f]+ [0-9a-f]+ +00 +WA .* +#pass diff --git a/ld/testsuite/ld-elf/noinit-sections-2.l b/ld/testsuite/ld-elf/noinit-sections-2.l new file mode 100644 index 0000000000..41ce6de01c --- /dev/null +++ b/ld/testsuite/ld-elf/noinit-sections-2.l @@ -0,0 +1,5 @@ +#... +[^:]*: warning: orphan section `.noinit.var_noinit' from \S+ being placed in section `.noinit.var_noinit' +#... +[^:]*: warning: orphan section `.persistent.var_persistent' from \S+ being placed in section `.persistent.var_persistent' +#pass diff --git a/ld/testsuite/ld-elf/noinit-sections.s b/ld/testsuite/ld-elf/noinit-sections.s new file mode 100644 index 0000000000..793f71769e --- /dev/null +++ b/ld/testsuite/ld-elf/noinit-sections.s @@ -0,0 +1,16 @@ +.section .noinit,"aw",%nobits +.word 0 + +.section .noinit.var_noinit,"aw",%nobits +.word 0 + +.section .persistent,"aw" +.word 1 + +.section .persistent.var_persistent,"aw" +.word 2 + +.text +.global _start +_start: +.word 0