2018-03-14 21:20:57

by Laura Abbott

[permalink] [raw]
Subject: New -Werror=restrict error with incremental gcc

Hi,

Fedora picked up a new gcc (8.0.1-0.18.fc29) and it seems to have introduced a new error:

gcc -Wp,-MD,/home/labbott/linux/tools/objtool/.str_error_r.o.d -Wp,-MT,/home/labbott/linux/tools/objtool/str_error_r.o -Wall -Werror -Wbad-function-cast -Wdeclaration-after-statement -Wformat-security -Wformat-y2k -Winit-self -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wno-system-headers -Wold-style-definition -Wpacked -Wredundant-decls -Wshadow -Wstrict-prototypes -Wswitch-default -Wswitch-enum -Wundef -Wwrite-strings -Wformat -Wstrict-aliasing=3 -Wno-switch-default -Wno-switch-enum -Wno-packed -fomit-frame-pointer -O2 -g -I/home/labbott/linux/tools/include -I/home/labbott/linux/tools/arch/x86/include/uapi -I/home/labbott/linux/tools/objtool/arch/x86/include -I/home/labbott/linux/tools/lib -D"BUILD_STR(s)=#s" -c -o /home/labbott/linux/tools/objtool/str_error_r.o ../lib/str_error_r.c
../lib/str_error_r.c: In function ‘str_error_r’:
../lib/str_error_r.c:25:3: error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]
snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);
^~

This looks like gcc is now warning about the aliasing from printing out buf
while printing to the buffer. I can work around this pretty easily but I
know people have strong opinions about gcc warnings. Any thoughts?

Thanks,
Laura


2018-03-15 12:51:47

by Jiri Olsa

[permalink] [raw]
Subject: Re: New -Werror=restrict error with incremental gcc

On Wed, Mar 14, 2018 at 02:19:41PM -0700, Laura Abbott wrote:
> Hi,
>
> Fedora picked up a new gcc (8.0.1-0.18.fc29) and it seems to have introduced a new error:
>
> gcc -Wp,-MD,/home/labbott/linux/tools/objtool/.str_error_r.o.d -Wp,-MT,/home/labbott/linux/tools/objtool/str_error_r.o -Wall -Werror -Wbad-function-cast -Wdeclaration-after-statement -Wformat-security -Wformat-y2k -Winit-self -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wno-system-headers -Wold-style-definition -Wpacked -Wredundant-decls -Wshadow -Wstrict-prototypes -Wswitch-default -Wswitch-enum -Wundef -Wwrite-strings -Wformat -Wstrict-aliasing=3 -Wno-switch-default -Wno-switch-enum -Wno-packed -fomit-frame-pointer -O2 -g -I/home/labbott/linux/tools/include -I/home/labbott/linux/tools/arch/x86/include/uapi -I/home/labbott/linux/tools/objtool/arch/x86/include -I/home/labbott/linux/tools/lib -D"BUILD_STR(s)=#s" -c -o /home/labbott/linux/tools/objtool/str_error_r.o ../lib/str_error_r.c
> ../lib/str_error_r.c: In function ‘str_error_r’:
> ../lib/str_error_r.c:25:3: error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]
> snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);
> ^~
>
> This looks like gcc is now warning about the aliasing from printing out buf
> while printing to the buffer. I can work around this pretty easily but I
> know people have strong opinions about gcc warnings. Any thoughts?

I did not get above warning.. objtool compiled for me properly

but we have some issues with perf there, I have to use
following to get it compile, plus attached patch

make EXTRA_CFLAGS="-Wno-format-truncation -Wno-cast-function-type"

the format-truncation are mostly fine, because we use the
buffer len to be safe and the worst things that will happen
is that we won't open the file, because the path is too long

the cast-function-type seems like a problem, I've bunch
of following errors:

/root/linux/tools/perf/util/python.c:830:15: warning: cast between incompatible function types from ‘PyObject * (*)(struct pyrf_evsel *, PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct pyrf_evsel *, struct _object *, struct _object *)’} to ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *)’} [-Wcast-function-type]
.ml_meth = (PyCFunction)pyrf_evsel__open,
^
/root/linux/tools/perf/util/python.c:1052:15: warning: cast between incompatible function types from ‘PyObject * (*)(struct pyrf_evlist *, PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct pyrf_evlist *, struct _object *, struct _object *)’} to ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *)’} [-Wcast-function-type]
.ml_meth = (PyCFunction)pyrf_evlist__mmap,
^
/root/linux/tools/perf/util/python.c:1058:15: warning: cast between incompatible function types from ‘PyObject * (*)(struct pyrf_evlist *, PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct pyrf_evlist *, struct _object *, struct _object *)’} to ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *)’} [-Wcast-function-type]
.ml_meth = (PyCFunction)pyrf_evlist__open,

we might want to look at it.. there were some python related
changes recently, like v3 support.. Arnaldo?

thanks,
jirka


---
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index cce926aeb0c0..48696fd80ad1 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2721,7 +2721,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
int match, len;
FILE *fp;

- sprintf(filename, "%s/bin/%s-record", dir_name, scriptname);
+ scnprintf(filename, MAXPATHLEN, "%s/bin/%s-record", dir_name, scriptname);

fp = fopen(filename, "r");
if (!fp)

2018-03-15 14:31:50

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: New -Werror=restrict error with incremental gcc

Em Wed, Mar 14, 2018 at 02:19:41PM -0700, Laura Abbott escreveu:
> Hi,
>
> Fedora picked up a new gcc (8.0.1-0.18.fc29) and it seems to have introduced a new error:
>
> gcc -Wp,-MD,/home/labbott/linux/tools/objtool/.str_error_r.o.d -Wp,-MT,/home/labbott/linux/tools/objtool/str_error_r.o -Wall -Werror -Wbad-function-cast -Wdeclaration-after-statement -Wformat-security -Wformat-y2k -Winit-self -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wno-system-headers -Wold-style-definition -Wpacked -Wredundant-decls -Wshadow -Wstrict-prototypes -Wswitch-default -Wswitch-enum -Wundef -Wwrite-strings -Wformat -Wstrict-aliasing=3 -Wno-switch-default -Wno-switch-enum -Wno-packed -fomit-frame-pointer -O2 -g -I/home/labbott/linux/tools/include -I/home/labbott/linux/tools/arch/x86/include/uapi -I/home/labbott/linux/tools/objtool/arch/x86/include -I/home/labbott/linux/tools/lib -D"BUILD_STR(s)=#s" -c -o /home/labbott/linux/tools/objtool/str_error_r.o ../lib/str_error_r.c
> ../lib/str_error_r.c: In function ‘str_error_r’:
> ../lib/str_error_r.c:25:3: error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]
> snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);
> ^~
>
> This looks like gcc is now warning about the aliasing from printing out buf
> while printing to the buffer. I can work around this pretty easily but I
> know people have strong opinions about gcc warnings. Any thoughts?

I couldn't reproduce it here:

[perfbuilder@b34646cdb12b perf]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --with-linker-hash-style=gnu
--enable-plugin --enable-initfini-array --with-isl --enable-libmpx
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686
--build=x86_64-redhat-linux
Thread model: posix
gcc version 8.0.1 20180310 (Red Hat 8.0.1-0.17) (GCC)
[perfbuilder@b34646cdb12b perf]$ rpm -q gcc
gcc-8.0.1-0.17.fc29.x86_64
[perfbuilder@b34646cdb12b perf]$

[perfbuilder@b34646cdb12b perf]$ make O=/tmp/build/kernel/
make[1]: Entering directory '/tmp/build/kernel'
CHK include/config/kernel.release
Using /git/perf as source for kernel
GEN ./Makefile
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
CHK include/generated/bounds.h
CHK include/generated/timeconst.h
CHK include/generated/asm-offsets.h
CALL /git/perf/scripts/checksyscalls.sh
DESCEND objtool
CC /tmp/build/kernel/tools/objtool/str_error_r.o
LD /tmp/build/kernel/tools/objtool/objtool-in.o
LINK /tmp/build/kernel/tools/objtool/objtool
CHK scripts/mod/devicetable-offsets.h
HOSTCC scripts/asn1_compiler


:-\

But I noticed some of those warnings and started action on then for
tools/perf, things like:

"perf annotate: Use asprintf when formatting objdump command line"

https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?id=f22ed8ad2ca0

- Arnaldo

2018-03-15 15:08:55

by Laura Abbott

[permalink] [raw]
Subject: Re: New -Werror=restrict error with incremental gcc

On 03/15/2018 07:30 AM, Arnaldo Carvalho de Melo wrote:
> Em Wed, Mar 14, 2018 at 02:19:41PM -0700, Laura Abbott escreveu:
>> Hi,
>>
>> Fedora picked up a new gcc (8.0.1-0.18.fc29) and it seems to have introduced a new error:
>>
>> gcc -Wp,-MD,/home/labbott/linux/tools/objtool/.str_error_r.o.d -Wp,-MT,/home/labbott/linux/tools/objtool/str_error_r.o -Wall -Werror -Wbad-function-cast -Wdeclaration-after-statement -Wformat-security -Wformat-y2k -Winit-self -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wno-system-headers -Wold-style-definition -Wpacked -Wredundant-decls -Wshadow -Wstrict-prototypes -Wswitch-default -Wswitch-enum -Wundef -Wwrite-strings -Wformat -Wstrict-aliasing=3 -Wno-switch-default -Wno-switch-enum -Wno-packed -fomit-frame-pointer -O2 -g -I/home/labbott/linux/tools/include -I/home/labbott/linux/tools/arch/x86/include/uapi -I/home/labbott/linux/tools/objtool/arch/x86/include -I/home/labbott/linux/tools/lib -D"BUILD_STR(s)=#s" -c -o /home/labbott/linux/tools/objtool/str_error_r.o ../lib/str_error_r.c
>> ../lib/str_error_r.c: In function ‘str_error_r’:
>> ../lib/str_error_r.c:25:3: error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]
>> snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);
>> ^~
>>
>> This looks like gcc is now warning about the aliasing from printing out buf
>> while printing to the buffer. I can work around this pretty easily but I
>> know people have strong opinions about gcc warnings. Any thoughts?
>
> I couldn't reproduce it here:
>
> [perfbuilder@b34646cdb12b perf]$ gcc -v
> Using built-in specs.
> COLLECT_GCC=gcc
> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
> OFFLOAD_TARGET_NAMES=nvptx-none
> OFFLOAD_TARGET_DEFAULT=1
> Target: x86_64-redhat-linux
> Configured with: ../configure --enable-bootstrap
> --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr
> --mandir=/usr/share/man --infodir=/usr/share/info
> --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
> --enable-threads=posix --enable-checking=release --enable-multilib
> --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
> --enable-gnu-unique-object --enable-linker-build-id
> --with-gcc-major-version-only --with-linker-hash-style=gnu
> --enable-plugin --enable-initfini-array --with-isl --enable-libmpx
> --enable-offload-targets=nvptx-none --without-cuda-driver
> --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686
> --build=x86_64-redhat-linux
> Thread model: posix
> gcc version 8.0.1 20180310 (Red Hat 8.0.1-0.17) (GCC)
> [perfbuilder@b34646cdb12b perf]$ rpm -q gcc
> gcc-8.0.1-0.17.fc29.x86_64
> [perfbuilder@b34646cdb12b perf]$
>
> [perfbuilder@b34646cdb12b perf]$ make O=/tmp/build/kernel/
> make[1]: Entering directory '/tmp/build/kernel'
> CHK include/config/kernel.release
> Using /git/perf as source for kernel
> GEN ./Makefile
> CHK include/generated/uapi/linux/version.h
> CHK include/generated/utsrelease.h
> CHK include/generated/bounds.h
> CHK include/generated/timeconst.h
> CHK include/generated/asm-offsets.h
> CALL /git/perf/scripts/checksyscalls.sh
> DESCEND objtool
> CC /tmp/build/kernel/tools/objtool/str_error_r.o
> LD /tmp/build/kernel/tools/objtool/objtool-in.o
> LINK /tmp/build/kernel/tools/objtool/objtool
> CHK scripts/mod/devicetable-offsets.h
> HOSTCC scripts/asn1_compiler
>
>
> :-\
>
> But I noticed some of those warnings and started action on then for
> tools/perf, things like:
>
> "perf annotate: Use asprintf when formatting objdump command line"
>
> https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/commit/?id=f22ed8ad2ca0
>
> - Arnaldo
>

This only showed up with the very latest rawhide snapshot, .17 worked and
.18 started failing. I had to download .18 manually to test locally
https://koji.fedoraproject.org/koji/packageinfo?packageID=40

Thanks,
Laura

2018-03-16 03:34:30

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: New -Werror=restrict error with incremental gcc

On Thu, Mar 15, 2018 at 08:06:26AM -0700, Laura Abbott wrote:
> This only showed up with the very latest rawhide snapshot, .17 worked and
> .18 started failing. I had to download .18 manually to test locally
> https://koji.fedoraproject.org/koji/packageinfo?packageID=40

I also see the error with the latest gcc master branch. The code is
harmless, but maybe the warning is useful in other places, so here's one
way to fix it.

----

From: Josh Poimboeuf <[email protected]>
Subject: [PATCH] objtool, perf: Fix GCC 8 -Wrestrict error

Starting with recent GCC 8 builds, objtool and perf fail to build with
the following error:

../str_error_r.c: In function ‘str_error_r’:
../str_error_r.c:25:3: error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]
snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);

The code seems harmless, but there's probably no benefit in printing the
'buf' pointer in this situation anyway, so just remove it to make GCC
happy.

Signed-off-by: Josh Poimboeuf <[email protected]>
---
tools/lib/str_error_r.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/str_error_r.c b/tools/lib/str_error_r.c
index d6d65537b0d9..6aad8308a0ac 100644
--- a/tools/lib/str_error_r.c
+++ b/tools/lib/str_error_r.c
@@ -22,6 +22,6 @@ char *str_error_r(int errnum, char *buf, size_t buflen)
{
int err = strerror_r(errnum, buf, buflen);
if (err)
- snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);
+ snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, [buf], %zd)=%d", errnum, buflen, err);
return buf;
}
--
2.14.3


2018-03-17 00:57:47

by Laura Abbott

[permalink] [raw]
Subject: Re: New -Werror=restrict error with incremental gcc

On 03/15/2018 08:11 PM, Josh Poimboeuf wrote:
> On Thu, Mar 15, 2018 at 08:06:26AM -0700, Laura Abbott wrote:
>> This only showed up with the very latest rawhide snapshot, .17 worked and
>> .18 started failing. I had to download .18 manually to test locally
>> https://koji.fedoraproject.org/koji/packageinfo?packageID=40
>
> I also see the error with the latest gcc master branch. The code is
> harmless, but maybe the warning is useful in other places, so here's one
> way to fix it.
>

Works for me, you can add

Tested-by: Laura Abbott <[email protected]>

> ----
>
> From: Josh Poimboeuf <[email protected]>
> Subject: [PATCH] objtool, perf: Fix GCC 8 -Wrestrict error
>
> Starting with recent GCC 8 builds, objtool and perf fail to build with
> the following error:
>
> ../str_error_r.c: In function ‘str_error_r’:
> ../str_error_r.c:25:3: error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]
> snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);
>
> The code seems harmless, but there's probably no benefit in printing the
> 'buf' pointer in this situation anyway, so just remove it to make GCC
> happy.
>
> Signed-off-by: Josh Poimboeuf <[email protected]>
> ---
> tools/lib/str_error_r.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/lib/str_error_r.c b/tools/lib/str_error_r.c
> index d6d65537b0d9..6aad8308a0ac 100644
> --- a/tools/lib/str_error_r.c
> +++ b/tools/lib/str_error_r.c
> @@ -22,6 +22,6 @@ char *str_error_r(int errnum, char *buf, size_t buflen)
> {
> int err = strerror_r(errnum, buf, buflen);
> if (err)
> - snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);
> + snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, [buf], %zd)=%d", errnum, buflen, err);
> return buf;
> }
>


Subject: [tip:perf/core] objtool, perf: Fix GCC 8 -Wrestrict error

Commit-ID: 854e55ad289ef8888e7991f0ada85d5846f5afb9
Gitweb: https://git.kernel.org/tip/854e55ad289ef8888e7991f0ada85d5846f5afb9
Author: Josh Poimboeuf <[email protected]>
AuthorDate: Thu, 15 Mar 2018 22:11:54 -0500
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 19 Mar 2018 13:51:54 -0300

objtool, perf: Fix GCC 8 -Wrestrict error

Starting with recent GCC 8 builds, objtool and perf fail to build with
the following error:

../str_error_r.c: In function ‘str_error_r’:
../str_error_r.c:25:3: error: passing argument 1 to restrict-qualified parameter aliases with argument 5 [-Werror=restrict]
snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);

The code seems harmless, but there's probably no benefit in printing the
'buf' pointer in this situation anyway, so just remove it to make GCC
happy.

Reported-by: Laura Abbott <[email protected]>
Signed-off-by: Josh Poimboeuf <[email protected]>
Tested-by: Laura Abbott <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/r/20180316031154.juk2uncs7baffctp@treble
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/lib/str_error_r.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/str_error_r.c b/tools/lib/str_error_r.c
index d6d65537b0d9..6aad8308a0ac 100644
--- a/tools/lib/str_error_r.c
+++ b/tools/lib/str_error_r.c
@@ -22,6 +22,6 @@ char *str_error_r(int errnum, char *buf, size_t buflen)
{
int err = strerror_r(errnum, buf, buflen);
if (err)
- snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);
+ snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, [buf], %zd)=%d", errnum, buflen, err);
return buf;
}