From: "H.J. Lu" <hjl.tools@gmail.com>
To: "Joseph S. Myers" <joseph@codesourcery.com>
Cc: Andi Kleen <andi@firstfloor.org>,
Richard Guenther <richard.guenther@gmail.com>,
gcc-patches@gcc.gnu.org, Andi Kleen <ak@linux.intel.com>
Subject: Re: [PATCH 2/2] Improve reporting of section conflict errors
Date: Thu, 16 Dec 2010 20:37:00 -0000 [thread overview]
Message-ID: <AANLkTikOAwtD2n63r8EO_7MEYUh72gP-FHeR0iVagp=1@mail.gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.64.1012161540060.16840@digraph.polyomino.org.uk>
[-- Attachment #1: Type: text/plain, Size: 1600 bytes --]
On Thu, Dec 16, 2010 at 7:46 AM, Joseph S. Myers
<joseph@codesourcery.com> wrote:
> On Thu, 16 Dec 2010, Andi Kleen wrote:
>
>> +/* Print section flags F into BUF */
>
> End comment with ". */".
>
>> + { "code", SECTION_CODE, 0 },
> [...]
>
>> + if (f)
>> + sprintf (buf, "rest %x", f);
>
> Are these strings meant to be English language or literal programming
> language text? If English, there should be appropriate arrangements for
> translation.
>
>> + char buf[1024];
>> +
>
> I agree a variable size buffer would be better - but the minimum is
> runtime checks to avoid overflow in the case of long translations etc. (so
> don't use sprintf etc. without knowing there is enough space left at
> runtime).
>
> It would be nice to eliminate direct use of sprintf from GCC - even if you
> do know there is enough space, using snprintf is better discipline. (And
> asprintf/vasprintf - in favour of xasprintf/xvasprintf - if someone could
> just approve <http://gcc.gnu.org/ml/gcc-patches/2009-11/msg01448.html and
> <http://gcc.gnu.org/ml/gcc-patches/2009-11/msg01449.html>.)
>
>> + inform (DECL_SOURCE_LOCATION (decl),
>> + "New section declaration differs in: %s",
>> + section_flags_string (buf, flags));
>
> Diagnostics start with lowercase letters.
>
Is this patch OK for trunk?
Thanks.
--
H.J.
---
2010-12-16 Andi Kleen <ak@linux.intel.com>
H.J. Lu <hongjiu.lu@intel.com>
* varasm.c (section_flags_string): New.
(get_section): Print more details on conflicting section flags.
[-- Attachment #2: gcc-section-flag-1.patch --]
[-- Type: text/plain, Size: 2371 bytes --]
2010-12-16 Andi Kleen <ak@linux.intel.com>
H.J. Lu <hongjiu.lu@intel.com>
* varasm.c (section_flags_string): New.
(get_section): Print more details on conflicting section flags.
diff --git a/gcc/varasm.c b/gcc/varasm.c
index ed44610..d91497c 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -268,6 +268,47 @@ get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
return sect;
}
+/* Return a string for section flags F. */
+
+static char *
+section_flags_string (unsigned int f)
+{
+ static const struct section_flag
+ {
+ const char *name;
+ unsigned int flag;
+ }
+ section_flags[] =
+ {
+ { "code", SECTION_CODE },
+ { "write", SECTION_WRITE },
+ { "debug", SECTION_DEBUG },
+ { "linkonce", SECTION_LINKONCE },
+ { "small", SECTION_SMALL },
+ { "bss", SECTION_BSS },
+ { "forget", SECTION_FORGET },
+ { "merge", SECTION_MERGE },
+ { "strings", SECTION_STRINGS },
+ { "override", SECTION_OVERRIDE },
+ { "tls", SECTION_TLS },
+ { "common", SECTION_COMMON },
+ { "unnamed", SECTION_UNNAMED},
+ { "named", SECTION_NAMED },
+ { "noswitch", SECTION_NOSWITCH }
+ };
+ unsigned int i;
+ char *flag = NULL;
+ for (i = 0; i < ARRAY_SIZE (section_flags); i++)
+ if ((f & section_flags[i].flag) != 0)
+ {
+ if (flag)
+ flag = concat (flag, " ", section_flags[i].name, NULL);
+ else
+ flag = concat (section_flags[i].name, NULL);
+ }
+ return flag;
+}
+
/* Return the named section structure associated with NAME. Create
a new section with the given fields if no such structure exists. */
@@ -290,15 +331,24 @@ get_section (const char *name, unsigned int flags, tree decl)
}
else
{
+ unsigned int oflags;
+
sect = *slot;
- if ((sect->common.flags & ~SECTION_DECLARED) != flags
+ oflags = sect->common.flags & ~SECTION_DECLARED;
+ if (oflags != flags
&& ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
{
+ char *str;
/* Sanity check user variables for flag changes. */
if (decl == 0)
decl = sect->named.decl;
gcc_assert (decl);
error ("%+D causes a section type conflict", decl);
+ flags = (oflags ^ flags) & ~SECTION_OVERRIDE;
+ str = section_flags_string (flags);
+ inform (DECL_SOURCE_LOCATION (decl),
+ "new section declaration differs in: %s", str);
+ free (str);
}
}
return sect;
next prev parent reply other threads:[~2010-12-16 20:05 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-16 13:25 [PATCH 1/2] Fix -fno-lto (PR lto/46905) Andi Kleen
2010-12-16 13:26 ` [PATCH 2/2] Improve reporting of section conflict errors Andi Kleen
2010-12-16 13:32 ` Richard Guenther
2010-12-16 15:39 ` Andi Kleen
2010-12-16 15:46 ` Richard Guenther
2010-12-16 15:53 ` Andi Kleen
2010-12-16 16:56 ` Joseph S. Myers
2010-12-16 17:24 ` Andi Kleen
2010-12-16 20:37 ` H.J. Lu [this message]
2010-12-16 14:01 ` Nathan Froyd
2010-12-16 13:29 ` [PATCH 1/2] Fix -fno-lto (PR lto/46905) Richard Guenther
2010-12-16 13:30 ` Andi Kleen
2010-12-16 13:45 ` Richard Guenther
2010-12-16 16:09 ` Jan Hubicka
2010-12-16 16:44 ` Joseph S. Myers
2010-12-16 18:14 ` Andi Kleen
2010-12-18 20:44 ` Richard Guenther
2010-12-20 5:05 ` Andi Kleen
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='AANLkTikOAwtD2n63r8EO_7MEYUh72gP-FHeR0iVagp=1@mail.gmail.com' \
--to=hjl.tools@gmail.com \
--cc=ak@linux.intel.com \
--cc=andi@firstfloor.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=joseph@codesourcery.com \
--cc=richard.guenther@gmail.com \
/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).