diff mbox series

[bpf-next,1/7] libbpf: disable -Wswitch-enum compiler warning

Message ID 20200818213356.2629020-2-andriin@fb.com
State Accepted
Delegated to: BPF Maintainers
Headers show
Series libbpf feature probing and sanitization improvements | expand

Commit Message

Andrii Nakryiko Aug. 18, 2020, 9:33 p.m. UTC
That compilation warning is more annoying, than helpful.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
 tools/lib/bpf/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Yonghong Song Aug. 19, 2020, 1:23 a.m. UTC | #1
On 8/18/20 2:33 PM, Andrii Nakryiko wrote:
> That compilation warning is more annoying, than helpful.

Curious which compiler and which version caused this issue?
I did not hit with gcc 8.2 or latest clang in my environment.

> 
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> ---
>   tools/lib/bpf/Makefile | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
> index bf8ed134cb8a..95c946e94ca5 100644
> --- a/tools/lib/bpf/Makefile
> +++ b/tools/lib/bpf/Makefile
> @@ -107,7 +107,7 @@ ifeq ($(feature-reallocarray), 0)
>   endif
>   
>   # Append required CFLAGS
> -override CFLAGS += $(EXTRA_WARNINGS)
> +override CFLAGS += $(EXTRA_WARNINGS) -Wno-switch-enum
>   override CFLAGS += -Werror -Wall
>   override CFLAGS += -fPIC
>   override CFLAGS += $(INCLUDES)
>
Andrii Nakryiko Aug. 19, 2020, 1:39 a.m. UTC | #2
On Tue, Aug 18, 2020 at 6:23 PM Yonghong Song <yhs@fb.com> wrote:
>
>
>
> On 8/18/20 2:33 PM, Andrii Nakryiko wrote:
> > That compilation warning is more annoying, than helpful.
>
> Curious which compiler and which version caused this issue?
> I did not hit with gcc 8.2 or latest clang in my environment.
>

Strange, I just tried on bpf-next, removed -Wno-switch-enum and got
tons of errors:

libbpf.c: In function ‘bpf_object__sanitize_prog’:
libbpf.c:5560:3: error: enumeration value ‘BPF_FUNC_unspec’ not
handled in switch [-Werror=switch-enum]
   switch (func_id) {
   ^~~~~~
libbpf.c:5560:3: error: enumeration value ‘BPF_FUNC_map_lookup_elem’
not handled in switch [-Werror=switch-enum]
libbpf.c:5560:3: error: enumeration value ‘BPF_FUNC_map_update_elem’
not handled in switch [-Werror=switch-enum]
... and many more ...

My compiler:

$ cc --version
cc (GCC) 8.2.1 20180801 (Red Hat 8.2.1-2)


> >
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> > ---
> >   tools/lib/bpf/Makefile | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
> > index bf8ed134cb8a..95c946e94ca5 100644
> > --- a/tools/lib/bpf/Makefile
> > +++ b/tools/lib/bpf/Makefile
> > @@ -107,7 +107,7 @@ ifeq ($(feature-reallocarray), 0)
> >   endif
> >
> >   # Append required CFLAGS
> > -override CFLAGS += $(EXTRA_WARNINGS)
> > +override CFLAGS += $(EXTRA_WARNINGS) -Wno-switch-enum
> >   override CFLAGS += -Werror -Wall
> >   override CFLAGS += -fPIC
> >   override CFLAGS += $(INCLUDES)
> >
Yonghong Song Aug. 19, 2020, 5:44 a.m. UTC | #3
On 8/18/20 6:39 PM, Andrii Nakryiko wrote:
> On Tue, Aug 18, 2020 at 6:23 PM Yonghong Song <yhs@fb.com> wrote:
>>
>>
>>
>> On 8/18/20 2:33 PM, Andrii Nakryiko wrote:
>>> That compilation warning is more annoying, than helpful.
>>
>> Curious which compiler and which version caused this issue?
>> I did not hit with gcc 8.2 or latest clang in my environment.
>>
> 
> Strange, I just tried on bpf-next, removed -Wno-switch-enum and got
> tons of errors:
> 
> libbpf.c: In function ‘bpf_object__sanitize_prog’:
> libbpf.c:5560:3: error: enumeration value ‘BPF_FUNC_unspec’ not
> handled in switch [-Werror=switch-enum]
>     switch (func_id) {
>     ^~~~~~
> libbpf.c:5560:3: error: enumeration value ‘BPF_FUNC_map_lookup_elem’
> not handled in switch [-Werror=switch-enum]
> libbpf.c:5560:3: error: enumeration value ‘BPF_FUNC_map_update_elem’
> not handled in switch [-Werror=switch-enum]
> ... and many more ...

Okay I can reproduce now with latest bpf-next but not bpf.
Now I understand why you introduced this additional option.
The issue is introduced by the above code in Patch #4. To compile
patch #4, you need -Wno-switch-enum.

> 
> My compiler:
> 
> $ cc --version
> cc (GCC) 8.2.1 20180801 (Red Hat 8.2.1-2)
> 
> 
>>>
>>> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
>>> ---
>>>    tools/lib/bpf/Makefile | 2 +-
>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
>>> index bf8ed134cb8a..95c946e94ca5 100644
>>> --- a/tools/lib/bpf/Makefile
>>> +++ b/tools/lib/bpf/Makefile
>>> @@ -107,7 +107,7 @@ ifeq ($(feature-reallocarray), 0)
>>>    endif
>>>
>>>    # Append required CFLAGS
>>> -override CFLAGS += $(EXTRA_WARNINGS)
>>> +override CFLAGS += $(EXTRA_WARNINGS) -Wno-switch-enum
>>>    override CFLAGS += -Werror -Wall
>>>    override CFLAGS += -fPIC
>>>    override CFLAGS += $(INCLUDES)
>>>
diff mbox series

Patch

diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index bf8ed134cb8a..95c946e94ca5 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -107,7 +107,7 @@  ifeq ($(feature-reallocarray), 0)
 endif
 
 # Append required CFLAGS
-override CFLAGS += $(EXTRA_WARNINGS)
+override CFLAGS += $(EXTRA_WARNINGS) -Wno-switch-enum
 override CFLAGS += -Werror -Wall
 override CFLAGS += -fPIC
 override CFLAGS += $(INCLUDES)