public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools: Fix str_error_r() Werror=restrict build
@ 2018-03-19  5:55 Sergey Senozhatsky
  2018-03-19  7:18 ` Jiri Olsa
  2018-03-19 14:16 ` Arnaldo Carvalho de Melo
  0 siblings, 2 replies; 5+ messages in thread
From: Sergey Senozhatsky @ 2018-03-19  5:55 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Namhyung Kim, Jiri Olsa, Shuah Khan, linux-kernel,
	Sergey Senozhatsky

Commit c8b5f2c96d1bf6c ("tools: Introduce str_error_r()") added
an str_error_r() wrapper which makes gcc8 unhappy due to
restrict-qualified parameter aliasing violation:

../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);
   ^~~~~~~~
cc1: all warnings being treated as errors

Workaround that aliasing error by creating an additional stack
variable which holds the buf pointer value we passed to strerror_r().

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
 tools/lib/str_error_r.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/lib/str_error_r.c b/tools/lib/str_error_r.c
index d6d65537b0d9..11c3425f272b 100644
--- a/tools/lib/str_error_r.c
+++ b/tools/lib/str_error_r.c
@@ -21,7 +21,12 @@
 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);
+	if (err) {
+		char *err_buf = buf;
+
+		snprintf(err_buf, buflen,
+			 "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d",
+			 errnum, buf, buflen, err);
+	}
 	return buf;
 }
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools: Fix str_error_r() Werror=restrict build
  2018-03-19  5:55 [PATCH] tools: Fix str_error_r() Werror=restrict build Sergey Senozhatsky
@ 2018-03-19  7:18 ` Jiri Olsa
  2018-03-19  7:44   ` Sergey Senozhatsky
  2018-03-19 14:16 ` Arnaldo Carvalho de Melo
  1 sibling, 1 reply; 5+ messages in thread
From: Jiri Olsa @ 2018-03-19  7:18 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Shuah Khan,
	linux-kernel, Sergey Senozhatsky, Josh Poimboeuf

On Mon, Mar 19, 2018 at 02:55:04PM +0900, Sergey Senozhatsky wrote:
> Commit c8b5f2c96d1bf6c ("tools: Introduce str_error_r()") added
> an str_error_r() wrapper which makes gcc8 unhappy due to
> restrict-qualified parameter aliasing violation:
> 
> ../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);
>    ^~~~~~~~
> cc1: all warnings being treated as errors
> 
> Workaround that aliasing error by creating an additional stack
> variable which holds the buf pointer value we passed to strerror_r().
> 
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>

Josh posted another way to fix it:
https://marc.info/?l=linux-kernel&m=152116992412107&w=2

your patch keeps the same output, I dont mind either way ;-)

jirka


> ---
>  tools/lib/str_error_r.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/lib/str_error_r.c b/tools/lib/str_error_r.c
> index d6d65537b0d9..11c3425f272b 100644
> --- a/tools/lib/str_error_r.c
> +++ b/tools/lib/str_error_r.c
> @@ -21,7 +21,12 @@
>  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);
> +	if (err) {
> +		char *err_buf = buf;
> +
> +		snprintf(err_buf, buflen,
> +			 "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d",
> +			 errnum, buf, buflen, err);
> +	}
>  	return buf;
>  }
> -- 
> 2.16.2
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools: Fix str_error_r() Werror=restrict build
  2018-03-19  7:18 ` Jiri Olsa
@ 2018-03-19  7:44   ` Sergey Senozhatsky
  0 siblings, 0 replies; 5+ messages in thread
From: Sergey Senozhatsky @ 2018-03-19  7:44 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Sergey Senozhatsky, Arnaldo Carvalho de Melo, Namhyung Kim,
	Jiri Olsa, Shuah Khan, linux-kernel, Sergey Senozhatsky,
	Josh Poimboeuf

On (03/19/18 08:18), Jiri Olsa wrote:
> On Mon, Mar 19, 2018 at 02:55:04PM +0900, Sergey Senozhatsky wrote:
> > Commit c8b5f2c96d1bf6c ("tools: Introduce str_error_r()") added
> > an str_error_r() wrapper which makes gcc8 unhappy due to
> > restrict-qualified parameter aliasing violation:
> > 
> > ../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);
> >    ^~~~~~~~
> > cc1: all warnings being treated as errors
> > 
> > Workaround that aliasing error by creating an additional stack
> > variable which holds the buf pointer value we passed to strerror_r().
> > 
> > Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> 
> Josh posted another way to fix it:
> https://marc.info/?l=linux-kernel&m=152116992412107&w=2

Oh, thanks for the pointers.

> your patch keeps the same output, I dont mind either way ;-)

Thanks. No strong opinion, either way is OK :) Can't tell for sure if
snprintf(... "%p", buf) is significantly better than snprintf(... "[buf]"),
but Arnaldo wanted to have the first version.

	-ss

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools: Fix str_error_r() Werror=restrict build
  2018-03-19  5:55 [PATCH] tools: Fix str_error_r() Werror=restrict build Sergey Senozhatsky
  2018-03-19  7:18 ` Jiri Olsa
@ 2018-03-19 14:16 ` Arnaldo Carvalho de Melo
  2018-03-19 14:23   ` Sergey Senozhatsky
  1 sibling, 1 reply; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-03-19 14:16 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Namhyung Kim, Jiri Olsa, Shuah Khan, linux-kernel,
	Sergey Senozhatsky

Em Mon, Mar 19, 2018 at 02:55:04PM +0900, Sergey Senozhatsky escreveu:
> Commit c8b5f2c96d1bf6c ("tools: Introduce str_error_r()") added
> an str_error_r() wrapper which makes gcc8 unhappy due to
> restrict-qualified parameter aliasing violation:
> 
> ../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);
>    ^~~~~~~~
> cc1: all warnings being treated as errors

I applied Josh's patch, just printing '[buf]', that is good enough, I
think.

- Arnaldo
 
> Workaround that aliasing error by creating an additional stack
> variable which holds the buf pointer value we passed to strerror_r().
> 
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> ---
>  tools/lib/str_error_r.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/lib/str_error_r.c b/tools/lib/str_error_r.c
> index d6d65537b0d9..11c3425f272b 100644
> --- a/tools/lib/str_error_r.c
> +++ b/tools/lib/str_error_r.c
> @@ -21,7 +21,12 @@
>  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);
> +	if (err) {
> +		char *err_buf = buf;
> +
> +		snprintf(err_buf, buflen,
> +			 "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d",
> +			 errnum, buf, buflen, err);
> +	}
>  	return buf;
>  }
> -- 
> 2.16.2

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools: Fix str_error_r() Werror=restrict build
  2018-03-19 14:16 ` Arnaldo Carvalho de Melo
@ 2018-03-19 14:23   ` Sergey Senozhatsky
  0 siblings, 0 replies; 5+ messages in thread
From: Sergey Senozhatsky @ 2018-03-19 14:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Sergey Senozhatsky, Namhyung Kim, Jiri Olsa, Shuah Khan,
	linux-kernel, Sergey Senozhatsky

On (03/19/18 11:16), Arnaldo Carvalho de Melo wrote:
> Em Mon, Mar 19, 2018 at 02:55:04PM +0900, Sergey Senozhatsky escreveu:
> > Commit c8b5f2c96d1bf6c ("tools: Introduce str_error_r()") added
> > an str_error_r() wrapper which makes gcc8 unhappy due to
> > restrict-qualified parameter aliasing violation:
> > 
> > ../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);
> >    ^~~~~~~~
> > cc1: all warnings being treated as errors
> 
> I applied Josh's patch, just printing '[buf]', that is good enough, I
> think.

Sure. Do you need the whole "strerror_r(%d, %p, %zd)" in this case?
Seems that printing out just `errnum' should be good enough.

	-ss

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-03-19 14:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-19  5:55 [PATCH] tools: Fix str_error_r() Werror=restrict build Sergey Senozhatsky
2018-03-19  7:18 ` Jiri Olsa
2018-03-19  7:44   ` Sergey Senozhatsky
2018-03-19 14:16 ` Arnaldo Carvalho de Melo
2018-03-19 14:23   ` Sergey Senozhatsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox