From: "H.J. Lu" <hjl.tools@gmail.com>
To: gcc-patches@gcc.gnu.org
Subject: V4 [PATCH 0/3] Switch to a new section if the SECTION_RETAIN bit doesn't match
Date: Tue, 15 Dec 2020 09:30:28 -0800 [thread overview]
Message-ID: <20201215173031.3242097-1-hjl.tools@gmail.com> (raw)
When SECTION_RETAIN is used, definitions marked with used attribute and
unmarked definitions are placed in a section with the same name. Instead
of issue an error:
[hjl@gnu-cfl-2 gcc]$ /usr/gcc-11.0.0-x32/bin/gcc -S c.c -fdiagnostics-plain-output
c.c:2:49: error: ‘foo1’ causes a section type conflict with ‘foo2’
c.c:1:54: note: ‘foo2’ was declared here
[hjl@gnu-cfl-2 gcc]$
the first patch switches to a new section if the SECTION_RETAIN bit
doesn't match. The second optional patch issues a warning:
[hjl@gnu-cfl-2 gcc]$ ./xgcc -B./ -S c.c
c.c:2:49: warning: ‘foo1’ without ‘used’ attribute and ‘foo2’ with ‘used’ attribute are placed in a section with the same name [-Wattributes]
2 | const int __attribute__((section(".data.foo"))) foo1 = 1;
| ^~~~
c.c:1:54: note: ‘foo2’ was declared here
1 | const int __attribute__((used,section(".data.foo"))) foo2 = 2;
|
[hjl@gnu-cfl-2 gcc]$
Changes from V3:
1. Add DECL_P (decl) to switch_to_section ().
2. Update comments for get_section ().
3. Require .init_array/.fini_array support for SHF_GNU_RETAIN.
Changes from V2:
1. Add (new_section->common.flags & SECTION_NAMED) check since
SHF_GNU_RETAIN section must be named.
2. Move c-c++-common/attr-used-9.c to the fist patch since there are
no new warnings.
3. Check new warnings only for R_flag_in_section target.
H.J. Lu (3):
Switch to a new section if the SECTION_RETAIN bit doesn't match
Warn used and not used symbols in section with the same name
Require .init_array/.fini_array support for SHF_GNU_RETAIN
gcc/defaults.h | 11 +++++
gcc/output.h | 2 +-
gcc/testsuite/c-c++-common/attr-used-5.c | 27 ++++++++++++
gcc/testsuite/c-c++-common/attr-used-6.c | 27 ++++++++++++
gcc/testsuite/c-c++-common/attr-used-7.c | 9 ++++
gcc/testsuite/c-c++-common/attr-used-8.c | 9 ++++
gcc/testsuite/c-c++-common/attr-used-9.c | 28 ++++++++++++
gcc/testsuite/lib/target-supports.exp | 2 +-
gcc/varasm.c | 56 ++++++++++++++++++++----
9 files changed, 161 insertions(+), 10 deletions(-)
create mode 100644 gcc/testsuite/c-c++-common/attr-used-5.c
create mode 100644 gcc/testsuite/c-c++-common/attr-used-6.c
create mode 100644 gcc/testsuite/c-c++-common/attr-used-7.c
create mode 100644 gcc/testsuite/c-c++-common/attr-used-8.c
create mode 100644 gcc/testsuite/c-c++-common/attr-used-9.c
--
2.29.2
next reply other threads:[~2020-12-15 17:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-15 17:30 H.J. Lu [this message]
2020-12-15 17:30 ` V4 [PATCH 1/3] " H.J. Lu
2020-12-16 0:44 ` Jeff Law
2020-12-16 13:01 ` H.J. Lu
2020-12-15 17:30 ` V4 [PATCH 2/3] Warn used and not used symbols in section with the same name H.J. Lu
2020-12-16 0:44 ` Jeff Law
2020-12-15 17:30 ` V4 [PATCH 3/3] Require .init_array/.fini_array support for SHF_GNU_RETAIN H.J. Lu
2020-12-16 0:45 ` Jeff Law
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201215173031.3242097-1-hjl.tools@gmail.com \
--to=hjl.tools@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).