diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2020-12-03 15:39:59 -0800 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2020-12-16 05:40:57 -0800 |
commit | 2a976020603589e897fcfa3276590ef50b489d34 (patch) | |
tree | 909ff9b5f5bd0e29304015e097ad0b6d79144c8c /gcc/varasm.c | |
parent | 6175383249143309fdc780a02bea484f4450def7 (diff) | |
download | gcc-2a976020603589e897fcfa3276590ef50b489d34.zip gcc-2a976020603589e897fcfa3276590ef50b489d34.tar.gz gcc-2a976020603589e897fcfa3276590ef50b489d34.tar.bz2 |
Warn used and not used symbols in section with the same name
When SECTION_RETAIN is used, issue a warning when a symbol without used
attribute and a symbol with used attribute are placed in the section with
the same name, like
int __attribute__((used,section(".data.foo"))) foo2 = 2;
int __attribute__((section(".data.foo"))) foo1 = 1;
since assembler will put them in different sections with the same section
name.
gcc/
PR target/98146
* varasm.c (switch_to_section): Warn when a symbol without used
attribute and a symbol with used attribute are placed in the
section with the same name.
gcc/testsuite/
PR target/98146
* c-c++-common/attr-used-5.c: Updated.
* c-c++-common/attr-used-6.c: Likewise.
* c-c++-common/attr-used-7.c: Likewise.
* c-c++-common/attr-used-8.c: Likewise.
Diffstat (limited to 'gcc/varasm.c')
-rw-r--r-- | gcc/varasm.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/gcc/varasm.c b/gcc/varasm.c index cfec870..a1a8d3b 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -7765,11 +7765,27 @@ switch_to_section (section *new_section, tree decl) { /* If the SECTION_RETAIN bit doesn't match, switch to a new section. */ + tree used_decl, no_used_decl; + if (DECL_PRESERVE_P (decl)) - new_section->common.flags |= SECTION_RETAIN; + { + new_section->common.flags |= SECTION_RETAIN; + used_decl = decl; + no_used_decl = new_section->named.decl; + } else - new_section->common.flags &= ~(SECTION_RETAIN - | SECTION_DECLARED); + { + new_section->common.flags &= ~(SECTION_RETAIN + | SECTION_DECLARED); + used_decl = new_section->named.decl; + no_used_decl = decl; + } + warning (OPT_Wattributes, + "%+qD without %<used%> attribute and %qD with " + "%<used%> attribute are placed in a section with " + "the same name", no_used_decl, used_decl); + inform (DECL_SOURCE_LOCATION (used_decl), + "%qD was declared here", used_decl); } else return; |