public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* V3 [PATCH 0/2] Switch to a new section if the SECTION_RETAIN bit doesn't match
@ 2020-12-08 12:51 H.J. Lu
  2020-12-08 12:51 ` V3 [PATCH 1/2] " H.J. Lu
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: H.J. Lu @ 2020-12-08 12:51 UTC (permalink / raw)
  To: gcc-patches

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 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 (2):
  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

 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/varasm.c                             | 46 +++++++++++++++++++++---
 7 files changed, 143 insertions(+), 5 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.28.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-12-15  2:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-08 12:51 V3 [PATCH 0/2] Switch to a new section if the SECTION_RETAIN bit doesn't match H.J. Lu
2020-12-08 12:51 ` V3 [PATCH 1/2] " H.J. Lu
2020-12-14 11:17   ` Vaseeharan Vinayagamoorthy
2020-12-15  1:06   ` Jeff Law
2020-12-15  2:07     ` H.J. Lu
2020-12-08 12:51 ` V3 [PATCH 2/2] Warn used and not used symbols in section with the same name H.J. Lu
2020-12-10  2:08 ` V3 [PATCH 0/2] Switch to a new section if the SECTION_RETAIN bit doesn't match Jim Wilson
2020-12-10  2:14   ` H.J. Lu
2020-12-10  3:12     ` Jim Wilson
2020-12-13 16:03 ` PING^1: " H.J. Lu

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).