Discussion:
gcc trunk fails to build kernel on PowerPC64 due to oprofile warnings
(too old to reply)
Anton Blanchard
2017-01-25 23:00:44 UTC
Permalink
Raw Message
Hi,

gcc trunk has failed to build PowerPC64 kernels for a month or so. The issue
is in oprofile, which is common code but ends up being sucked into
arch/powerpc and therefore subject to the -Werror applied to arch/powerpc:

linux/arch/powerpc/oprofile/../../../drivers/oprofile/oprofile_stats.c: In function ‘oprofile_create_stats_files’:
linux/arch/powerpc/oprofile/../../../drivers/oprofile/oprofile_stats.c:55:25: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 7 [-Werror=format-truncation=]
snprintf(buf, 10, "cpu%d", i);
^~
linux/arch/powerpc/oprofile/../../../drivers/oprofile/oprofile_stats.c:55:21: note: using the range [1, -2147483648] for directive argument
snprintf(buf, 10, "cpu%d", i);
^~~~~~~
linux/arch/powerpc/oprofile/../../../drivers/oprofile/oprofile_stats.c:55:3: note: format output between 5 and 15 bytes into a destination of size 10
snprintf(buf, 10, "cpu%d", i);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LD crypto/async_tx/built-in.o
CC lib/random32.o
cc1: all warnings being treated as errors

Anton
Arnd Bergmann
2017-01-26 12:57:18 UTC
Permalink
Raw Message
From: Anton Blanchard
Sent: 25 January 2017 23:01
gcc trunk has failed to build PowerPC64 kernels for a month or so. The issue
is in oprofile, which is common code but ends up being sucked into
...
linux/arch/powerpc/oprofile/../../../drivers/oprofile/oprofile_stats.c:55:25: error: %d directive
output may be truncated writing between 1 and 11 bytes into a region of size 7 [-Werror=format-
truncation=]
snprintf(buf, 10, "cpu%d", i);
FFS these warnings are getting OTT.
The compiler needs to be able to track the domain of integers before applying
some of these warnings.
gcc-7 introduces lots of new warnings, some better than others. I'm
trying to categorize
both the new warnings and any others added in the recent years that we
may have missed
to see whether we want to turn them on by default or only in
scripts/Makefile.extrawarn
when building with W=1, W=2 or W=3.

I made a spreadsheet with the warnings that we have available in each version,
and also the number of unique output lines for that warning, see

https://docs.google.com/spreadsheets/d/1QemrLyvzrSDfm_MO3-_pwdfsTp2uqwjOdRBxxj6oo5M/edit?usp=sharing

For this specific warning, an ARM allmodconfig build shows 360
distinct warnings from a
total of 243 files. It's probably a good idea to look over them once
to see if anything sticks
out, but otherwise I think we change it to the W=2 level.

Arnd
William Cohen
2017-01-26 15:46:43 UTC
Permalink
Raw Message
Post by Anton Blanchard
Hi,
gcc trunk has failed to build PowerPC64 kernels for a month or so. The issue
is in oprofile, which is common code but ends up being sucked into
linux/arch/powerpc/oprofile/../../../drivers/oprofile/oprofile_stats.c:55:25: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 7 [-Werror=format-truncation=]
snprintf(buf, 10, "cpu%d", i);
^~
linux/arch/powerpc/oprofile/../../../drivers/oprofile/oprofile_stats.c:55:21: note: using the range [1, -2147483648] for directive argument
snprintf(buf, 10, "cpu%d", i);
^~~~~~~
linux/arch/powerpc/oprofile/../../../drivers/oprofile/oprofile_stats.c:55:3: note: format output between 5 and 15 bytes into a destination of size 10
snprintf(buf, 10, "cpu%d", i);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LD crypto/async_tx/built-in.o
CC lib/random32.o
cc1: all warnings being treated as errors
Anton
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
oprofile-list mailing list
https://lists.sourceforge.net/lists/listinfo/oprofile-list
The attached patch should make the buffer large enough to eliminate the warning.

-Will
Robert Richter
2017-01-26 16:06:25 UTC
Permalink
Raw Message
From 7e46dbd7dc5bc941926a4a63c28ccebf46493e8d Mon Sep 17 00:00:00 2001
Date: Thu, 26 Jan 2017 10:33:59 -0500
Subject: [PATCH] Avoid hypthetical string truncation in oprofile stats buffer
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Increased the size of an internal oprofile driver buffer ensuring that
the string was never truncated for any possible int value to avoid the
Please test gcc7 for other archs first. I don't think this is the only
change needed to avoid this warning in oprofile code.

Thanks,

-Robert
William Cohen
2017-01-30 15:35:09 UTC
Permalink
Raw Message
Post by Robert Richter
From 7e46dbd7dc5bc941926a4a63c28ccebf46493e8d Mon Sep 17 00:00:00 2001
Date: Thu, 26 Jan 2017 10:33:59 -0500
Subject: [PATCH] Avoid hypthetical string truncation in oprofile stats buffer
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Increased the size of an internal oprofile driver buffer ensuring that
the string was never truncated for any possible int value to avoid the
Please test gcc7 for other archs first. I don't think this is the only
change needed to avoid this warning in oprofile code.
Thanks,
-Robert
Hi Robert,

It took me a little while to get a gcc-7 environment set up with Fedora Rawhide on x86_64. I have a kernel building now with gcc-7 and will see what other issues pop up during the compile.

While watching the output of the build I see the gcc-7 error message about truncating output of snprintf output seems to occur for a number of other places besides the oprofile kernel code during the compile.

-Will
William Cohen
2017-02-02 17:21:08 UTC
Permalink
Raw Message
Post by Robert Richter
From 7e46dbd7dc5bc941926a4a63c28ccebf46493e8d Mon Sep 17 00:00:00 2001
Date: Thu, 26 Jan 2017 10:33:59 -0500
Subject: [PATCH] Avoid hypthetical string truncation in oprofile stats buffer
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Increased the size of an internal oprofile driver buffer ensuring that
the string was never truncated for any possible int value to avoid the
Please test gcc7 for other archs first. I don't think this is the only
change needed to avoid this warning in oprofile code.
Thanks,
-Robert
Hi Robert,

I looked through the oprofile arch specific code for other snprintf uses with small character arrays and added those to the patch. Attached is current patch to increase the size of the buffers to make sure that they will not be truncated.

OProfile since 1.0.0 has used the kernels perf infrastructure rather than the oprofile kernel driver. OProfile 1.0 was released September 2014, over two years ago. Would it make sense to deprecate and at some point remove the oprofile driver kernel from the kernel? Recent Fedora distributions already have CONFIG_OPROFILE unset in the kernel configurations.

-Will

Loading...