BPF Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] bpf: bpftool: convert ‘const char *’ type into 'char *' in assignment
@ 2019-03-28 14:16 Bo YU
  2019-03-28 14:30 ` Quentin Monnet
  2019-03-28 14:36 ` Mukesh Ojha
  0 siblings, 2 replies; 6+ messages in thread
From: Bo YU @ 2019-03-28 14:16 UTC (permalink / raw)
  To: ast, daniel, kafai, songliubraving, yhs, jakub.kicinski, df
  Cc: tsu.yubo, quentin.monnet, netdev, bpf, linux-kernel

When compiling with check flag: make -C tools/bpf/bpftool/
gcc will warning:

jit_disasm.c:119:29: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
   info.disassembler_options = disassembler_options;

So convert 'const char *' type into 'char *' to fix the warning.

Fixes:3ddeac6705aba(tools: bpftool: use 4 context mode for the NFP disasm)
Signed-off-by: Bo YU <tsu.yubo@gmail.com>
---
 tools/bpf/bpftool/jit_disasm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/bpf/bpftool/jit_disasm.c b/tools/bpf/bpftool/jit_disasm.c
index 3ef3093560ba..40b46e46454a 100644
--- a/tools/bpf/bpftool/jit_disasm.c
+++ b/tools/bpf/bpftool/jit_disasm.c
@@ -116,7 +116,7 @@ void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes,
 	info.arch = bfd_get_arch(bfdf);
 	info.mach = bfd_get_mach(bfdf);
 	if (disassembler_options)
-		info.disassembler_options = disassembler_options;
+		info.disassembler_options = (char *)disassembler_options;
 	info.buffer = image;
 	info.buffer_length = len;
 
-- 
2.11.0


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

* Re: [PATCH] bpf: bpftool: convert ‘const char *’ type into 'char *' in assignment
  2019-03-28 14:16 [PATCH] bpf: bpftool: convert ‘const char *’ type into 'char *' in assignment Bo YU
@ 2019-03-28 14:30 ` Quentin Monnet
  2019-03-28 14:38   ` Bo YU
  2019-03-28 15:08   ` David Laight
  2019-03-28 14:36 ` Mukesh Ojha
  1 sibling, 2 replies; 6+ messages in thread
From: Quentin Monnet @ 2019-03-28 14:30 UTC (permalink / raw)
  To: ast, daniel, kafai, songliubraving, yhs, jakub.kicinski, df,
	netdev, bpf, linux-kernel

2019-03-28 10:16 UTC-0400 ~ Bo YU <tsu.yubo@gmail.com>
> When compiling with check flag: make -C tools/bpf/bpftool/
> gcc will warning:
> 
> jit_disasm.c:119:29: warning: assignment discards ‘const’ qualifier from
> pointer target type [-Wdiscarded-qualifiers]
>   info.disassembler_options = disassembler_options;
> 
> So convert 'const char *' type into 'char *' to fix the warning.
> 
> Fixes:3ddeac6705aba(tools: bpftool: use 4 context mode for the NFP disasm)
> Signed-off-by: Bo YU <tsu.yubo@gmail.com>
> ---
> tools/bpf/bpftool/jit_disasm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/bpf/bpftool/jit_disasm.c
> b/tools/bpf/bpftool/jit_disasm.c
> index 3ef3093560ba..40b46e46454a 100644
> --- a/tools/bpf/bpftool/jit_disasm.c
> +++ b/tools/bpf/bpftool/jit_disasm.c
> @@ -116,7 +116,7 @@ void disasm_print_insn(unsigned char *image, ssize_t
> len, int opcodes,
>     info.arch = bfd_get_arch(bfdf);
>     info.mach = bfd_get_mach(bfdf);
>     if (disassembler_options)
> -        info.disassembler_options = disassembler_options;
> +        info.disassembler_options = (char *)disassembler_options;
>     info.buffer = image;
>     info.buffer_length = len;
> 


Hi, the warning does not show with latest versions of binutils, it was
fixed with this (binutils) commit:

    commit f995bbe8e62fdb5607acb1ee127240cfe50d2b8f
    Author: Pedro Alves <palves@redhat.com>
    Date:   Wed Apr 5 19:21:33 2017 +0100

        -Wwrite-strings: Constify struct disassemble_info's
		disassembler_options field

Distributions with recent binutils (Ubuntu 18.04, Fedora 29 at least)
should not have this message. I thought about sending the same patch
some time ago, but in the end Jakub and I decided that it may not be
worth casting the const away to silence the warning just for older
distributions. Daniel also shared the same opinion at the time (but that
was off the mailing-list).

Quentin

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

* Re: [PATCH] bpf: bpftool: convert ‘const char *’ type into 'char *' in assignment
  2019-03-28 14:16 [PATCH] bpf: bpftool: convert ‘const char *’ type into 'char *' in assignment Bo YU
  2019-03-28 14:30 ` Quentin Monnet
@ 2019-03-28 14:36 ` Mukesh Ojha
  1 sibling, 0 replies; 6+ messages in thread
From: Mukesh Ojha @ 2019-03-28 14:36 UTC (permalink / raw)
  To: ast, daniel, kafai, songliubraving, yhs, jakub.kicinski, df,
	quentin.monnet, netdev, bpf, linux-kernel


On 3/28/2019 7:46 PM, Bo YU wrote:
> When compiling with check flag: make -C tools/bpf/bpftool/
> gcc will warning:
>
> jit_disasm.c:119:29: warning: assignment discards ‘const’ qualifier 
> from pointer target type [-Wdiscarded-qualifiers]
>   info.disassembler_options = disassembler_options;
>
> So convert 'const char *' type into 'char *' to fix the warning.
>
> Fixes:3ddeac6705aba(tools: bpftool: use 4 context mode for the NFP 
> disasm)
> Signed-off-by: Bo YU <tsu.yubo@gmail.com>


Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>

-Mukesh

> ---
> tools/bpf/bpftool/jit_disasm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/bpf/bpftool/jit_disasm.c 
> b/tools/bpf/bpftool/jit_disasm.c
> index 3ef3093560ba..40b46e46454a 100644
> --- a/tools/bpf/bpftool/jit_disasm.c
> +++ b/tools/bpf/bpftool/jit_disasm.c
> @@ -116,7 +116,7 @@ void disasm_print_insn(unsigned char *image, 
> ssize_t len, int opcodes,
>     info.arch = bfd_get_arch(bfdf);
>     info.mach = bfd_get_mach(bfdf);
>     if (disassembler_options)
> -        info.disassembler_options = disassembler_options;
> +        info.disassembler_options = (char *)disassembler_options;
>     info.buffer = image;
>     info.buffer_length = len;
>

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

* Re: [PATCH] bpf: bpftool: convert ‘const char *’ type into 'char *' in assignment
  2019-03-28 14:30 ` Quentin Monnet
@ 2019-03-28 14:38   ` Bo YU
  2019-03-28 15:08   ` David Laight
  1 sibling, 0 replies; 6+ messages in thread
From: Bo YU @ 2019-03-28 14:38 UTC (permalink / raw)
  To: Quentin Monnet
  Cc: Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau,
	songliubraving, Yonghong Song, jakub.kicinski, df, Netdev, bpf,
	open list

On Thu, Mar 28, 2019 at 10:33 PM Quentin Monnet
<quentin.monnet@netronome.com> wrote:
>
> 2019-03-28 10:16 UTC-0400 ~ Bo YU <tsu.yubo@gmail.com>
> > When compiling with check flag: make -C tools/bpf/bpftool/
> > gcc will warning:
> >
> > jit_disasm.c:119:29: warning: assignment discards ‘const’ qualifier from
> > pointer target type [-Wdiscarded-qualifiers]
> >   info.disassembler_options = disassembler_options;
> >
> > So convert 'const char *' type into 'char *' to fix the warning.
> >
> > Fixes:3ddeac6705aba(tools: bpftool: use 4 context mode for the NFP disasm)
> > Signed-off-by: Bo YU <tsu.yubo@gmail.com>
> > ---
> > tools/bpf/bpftool/jit_disasm.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/bpf/bpftool/jit_disasm.c
> > b/tools/bpf/bpftool/jit_disasm.c
> > index 3ef3093560ba..40b46e46454a 100644
> > --- a/tools/bpf/bpftool/jit_disasm.c
> > +++ b/tools/bpf/bpftool/jit_disasm.c
> > @@ -116,7 +116,7 @@ void disasm_print_insn(unsigned char *image, ssize_t
> > len, int opcodes,
> >     info.arch = bfd_get_arch(bfdf);
> >     info.mach = bfd_get_mach(bfdf);
> >     if (disassembler_options)
> > -        info.disassembler_options = disassembler_options;
> > +        info.disassembler_options = (char *)disassembler_options;
> >     info.buffer = image;
> >     info.buffer_length = len;
> >
>
>
> Hi, the warning does not show with latest versions of binutils, it was
> fixed with this (binutils) commit:
>
>     commit f995bbe8e62fdb5607acb1ee127240cfe50d2b8f
>     Author: Pedro Alves <palves@redhat.com>
>     Date:   Wed Apr 5 19:21:33 2017 +0100
>
>         -Wwrite-strings: Constify struct disassemble_info's
>                 disassembler_options field
>
> Distributions with recent binutils (Ubuntu 18.04, Fedora 29 at least)
> should not have this message. I thought about sending the same patch
> some time ago, but in the end Jakub and I decided that it may not be
> worth casting the const away to silence the warning just for older
> distributions. Daniel also shared the same opinion at the time (but that
> was off the mailing-list).
Ok, good to know it.
Thanks,
>
> Quentin

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

* RE: [PATCH] bpf: bpftool: convert ‘const char *’ type into 'char *' in assignment
  2019-03-28 14:30 ` Quentin Monnet
  2019-03-28 14:38   ` Bo YU
@ 2019-03-28 15:08   ` David Laight
  2019-03-28 15:58     ` Quentin Monnet
  1 sibling, 1 reply; 6+ messages in thread
From: David Laight @ 2019-03-28 15:08 UTC (permalink / raw)
  To: 'Quentin Monnet',
	ast, daniel, kafai, songliubraving, yhs, jakub.kicinski, df,
	netdev, bpf, linux-kernel

From: Quentin Monnet
> Sent: 28 March 2019 14:31
> 2019-03-28 10:16 UTC-0400 ~ Bo YU <tsu.yubo@gmail.com>
> > When compiling with check flag: make -C tools/bpf/bpftool/
> > gcc will warning:
> >
> > jit_disasm.c:119:29: warning: assignment discards ‘const’ qualifier from
> > pointer target type [-Wdiscarded-qualifiers]
> >   info.disassembler_options = disassembler_options;
> >
> > So convert 'const char *' type into 'char *' to fix the warning.
> >
...
> > --- a/tools/bpf/bpftool/jit_disasm.c
> > +++ b/tools/bpf/bpftool/jit_disasm.c
> > @@ -116,7 +116,7 @@ void disasm_print_insn(unsigned char *image, ssize_t
> > len, int opcodes,
> >     info.arch = bfd_get_arch(bfdf);
> >     info.mach = bfd_get_mach(bfdf);
> >     if (disassembler_options)
> > -        info.disassembler_options = disassembler_options;
> > +        info.disassembler_options = (char *)disassembler_options;
> >     info.buffer = image;
> >     info.buffer_length = len;

At some point someone may decide to build with -Wcast-const
at which point you've just generated a different error.

The (probably) correct fix is to make info.disassempler_options 'const char *'.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

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

* Re: [PATCH] bpf: bpftool: convert ‘const char *’ type into 'char *' in assignment
  2019-03-28 15:08   ` David Laight
@ 2019-03-28 15:58     ` Quentin Monnet
  0 siblings, 0 replies; 6+ messages in thread
From: Quentin Monnet @ 2019-03-28 15:58 UTC (permalink / raw)
  To: David Laight, ast, daniel, kafai, songliubraving, yhs,
	jakub.kicinski, df, netdev, bpf, linux-kernel

2019-03-28 15:08 UTC+0000 ~ David Laight <David.Laight@ACULAB.COM>
> From: Quentin Monnet
>> Sent: 28 March 2019 14:31
>> 2019-03-28 10:16 UTC-0400 ~ Bo YU <tsu.yubo@gmail.com>
>>> When compiling with check flag: make -C tools/bpf/bpftool/
>>> gcc will warning:
>>>
>>> jit_disasm.c:119:29: warning: assignment discards ‘const’ qualifier from
>>> pointer target type [-Wdiscarded-qualifiers]
>>>   info.disassembler_options = disassembler_options;
>>>
>>> So convert 'const char *' type into 'char *' to fix the warning.
>>>
> ...
>>> --- a/tools/bpf/bpftool/jit_disasm.c
>>> +++ b/tools/bpf/bpftool/jit_disasm.c
>>> @@ -116,7 +116,7 @@ void disasm_print_insn(unsigned char *image, ssize_t
>>> len, int opcodes,
>>>     info.arch = bfd_get_arch(bfdf);
>>>     info.mach = bfd_get_mach(bfdf);
>>>     if (disassembler_options)
>>> -        info.disassembler_options = disassembler_options;
>>> +        info.disassembler_options = (char *)disassembler_options;
>>>     info.buffer = image;
>>>     info.buffer_length = len;
> 
> At some point someone may decide to build with -Wcast-const
> at which point you've just generated a different error.
> 
> The (probably) correct fix is to make info.disassempler_options 'const char *'.
> 
> 	David
> 

Which is what this binutils commit I cited does :)

Quentin

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

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-28 14:16 [PATCH] bpf: bpftool: convert ‘const char *’ type into 'char *' in assignment Bo YU
2019-03-28 14:30 ` Quentin Monnet
2019-03-28 14:38   ` Bo YU
2019-03-28 15:08   ` David Laight
2019-03-28 15:58     ` Quentin Monnet
2019-03-28 14:36 ` Mukesh Ojha

BPF Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/bpf/0 bpf/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 bpf bpf/ https://lore.kernel.org/bpf \
		bpf@vger.kernel.org
	public-inbox-index bpf

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.bpf


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git