On 23.01.17 11:07, Richard Earnshaw (lists) wrote:
On 21/01/17 20:15, Andreas Tobler wrote:
On 21.01.17 00:42, Jakub Jelinek wrote:
On Fri, Jan 20, 2017 at 01:37:13PM -0700, Jeff Law wrote:
Which is best will depend on what the front/mid ends might have
done to
apply the documented limit.

Here I know not enough to give a decision. In tree the priority_type is
unsigned short. In varasm priority is an int.

Similar functions, like arm_elf_asm_cdtor, do use the sprintf
instead of
snprintf. They theoretically have the same issue.

So, either:
2.) use %.5hu in snprintf
or
3.) cast priority in snprintf to (unsigned short)
I'd go with #2.  I think #3 still requires range propagation to avoid
the
false positive.

I actually think 1.) is best work-around, after 18 bytes there will be
some
padding so 23 bytes will almost always eat the same amount of stack
space,
and we avoid actually adding some instruction to cast it or hoping all
the
libcs we run on support %.5hu properly.

Richard, what do you think about this suggestion?

Thanks,
Andreas



I'm happy to go with that, but please add a comment as well, or some
well meaning individual may accidentally reverse the change after
counting the bytes...

Something like below?

If ok, I can commit, right?

Thanks,

Andreas

2017-01-23  Andreas Tobler  <andre...@gcc.gnu.org>

        * config/aarch64/aarch64.c (aarch64_elf_asm_constructor): Increase
        size of buf.
        (aarch64_elf_asm_destructor): Likewise.


Index: config/aarch64/aarch64.c
===================================================================
--- config/aarch64/aarch64.c    (revision 244819)
+++ config/aarch64/aarch64.c    (working copy)
@@ -5787,7 +5787,11 @@
   else
     {
       section *s;
-      char buf[18];
+      /* The size of the buf must be big enough to hold the string and the
+         full integer size of priority. Otherwise we will get a warning
+         about format-truncation.
+      */
+      char buf[23];
       snprintf (buf, sizeof (buf), ".init_array.%.5u", priority);
       s = get_section (buf, SECTION_WRITE, NULL);
       switch_to_section (s);
@@ -5804,7 +5808,11 @@
   else
     {
       section *s;
-      char buf[18];
+      /* The size of the buf must be big enough to hold the string and the
+         full integer size of priority. Otherwise we will get a warning
+         about format-truncation.
+      */
+      char buf[23];
       snprintf (buf, sizeof (buf), ".fini_array.%.5u", priority);
       s = get_section (buf, SECTION_WRITE, NULL);
       switch_to_section (s);

Reply via email to