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
Quoted 10 lines · Laura Abbott
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);
^~
Quoted 3 lines
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
---
tools/perf/builtin-script.c +1 -1
@@ -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)
Em Wed, Mar 14, 2018 at 02:19:41PM -0700, Laura Abbott escreveu:
Quoted 10 lines
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);
^~
Quoted 3 lines
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
Quoted 63 lines · Arnaldo Carvalho de Melo
Em Wed, Mar 14, 2018 at 02:19:41PM -0700, Laura Abbott escreveu:
Quoted 7 lines
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]Quoted 6 lines
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'
CHKinclude/config/kernel.release
Using /git/perf as source for kernelGEN ./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/objtoolCHK
scripts/mod/devicetable-offsets.h
HOSTCCscripts/asn1_compiler:-\
Quoted 9 lines
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
Quoted 3 lines · Laura Abbott
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.
--- tools/lib/str_error_r.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/str_error_r.c +1 -1
@@ -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; }
Signature · 1 line
2.14.3
Laura Abbott
Tested-byQuoted 9 lines · Josh Poimboeuf
Quoted 3 lines · Laura Abbott
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=40I 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
Quoted 34 lines
----
From: Josh Poimboeuf <[email protected]>
Subject: [PATCH] objtool, perf: Fix GCC 8 -Wrestrict errorStarting 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(-)tools/lib/str_error_r.c +1
-1@@ -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; }
tip-bot for Josh Poimboeuf
merge bot[tip:perf/core] objtool, perf: Fix GCC 8 -Wrestrict error
In reply to Josh Poimboeufobjtool, 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.
--- tools/lib/str_error_r.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/str_error_r.c +1 -1
@@ -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; }