bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h
@ 2019-09-06  7:31 Jiri Olsa
  2019-09-06  7:31 ` [PATCH 1/7] libbpf: Use const cast for btf_int_* functions Jiri Olsa
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Jiri Olsa @ 2019-09-06  7:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: netdev, bpf, Andrii Nakryiko, Yonghong Song, Martin KaFai Lau

hi,
when including btf.h in bpftrace, I'm getting -Wcast-qual warnings like:

  bpf/btf.h: In function ‘btf_var_secinfo* btf_var_secinfos(const btf_type*)’:
  bpf/btf.h:302:41: warning: cast from type ‘const btf_type*’ to type
  ‘btf_var_secinfo*’ casts away qualifiers [-Wcast-qual]
    302 |  return (struct btf_var_secinfo *)(t + 1);
        |                                         ^

I changed the btf.h header to comply with -Wcast-qual checks
and used const cast away casting in libbpf objects, where it's
all related to deduplication code, so I believe loosing const
is fine there.

thanks,
jirka


---
Jiri Olsa (7):
      libbpf: Use const cast for btf_int_* functions
      libbpf: Return const btf_array from btf_array inline function
      libbpf: Return const btf_enum from btf_enum inline function
      libbpf: Return const btf_member from btf_members inline function
      libbpf: Return const btf_param from btf_params inline function
      libbpf: Return const btf_var from btf_var inline function
      libbpf: Return const struct btf_var_secinfo from btf_var_secinfos inline function

 tools/lib/bpf/btf.c    | 21 +++++++++++----------
 tools/lib/bpf/btf.h    | 30 +++++++++++++++---------------
 tools/lib/bpf/libbpf.c |  2 +-
 3 files changed, 27 insertions(+), 26 deletions(-)

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

* [PATCH 1/7] libbpf: Use const cast for btf_int_* functions
  2019-09-06  7:31 [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h Jiri Olsa
@ 2019-09-06  7:31 ` Jiri Olsa
  2019-09-06  7:31 ` [PATCH 2/7] libbpf: Return const btf_array from btf_array inline function Jiri Olsa
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Jiri Olsa @ 2019-09-06  7:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: netdev, bpf, Andrii Nakryiko, Yonghong Song, Martin KaFai Lau

I'm getting following errors when compiling with -Wcast-qual:

  bpf/btf.h: In function ‘__u8 btf_int_offset(const btf_type*)’:
  bpf/btf.h:244:40: warning: cast from type ‘const btf_type*’ to type
  ‘__u32*’ {aka ‘unsigned int*’} casts away qualifiers [-Wcast-qual]
    244 |  return BTF_INT_OFFSET(*(__u32 *)(t + 1));
        |                                        ^

The argument is const so the cast to following __u32
pointer should be const as well.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/lib/bpf/btf.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index 9cb44b4fbf60..952e3496467d 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -236,17 +236,17 @@ static inline bool btf_is_datasec(const struct btf_type *t)
 
 static inline __u8 btf_int_encoding(const struct btf_type *t)
 {
-	return BTF_INT_ENCODING(*(__u32 *)(t + 1));
+	return BTF_INT_ENCODING(*(const __u32 *)(t + 1));
 }
 
 static inline __u8 btf_int_offset(const struct btf_type *t)
 {
-	return BTF_INT_OFFSET(*(__u32 *)(t + 1));
+	return BTF_INT_OFFSET(*(const __u32 *)(t + 1));
 }
 
 static inline __u8 btf_int_bits(const struct btf_type *t)
 {
-	return BTF_INT_BITS(*(__u32 *)(t + 1));
+	return BTF_INT_BITS(*(const __u32 *)(t + 1));
 }
 
 static inline struct btf_array *btf_array(const struct btf_type *t)
-- 
2.21.0


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

* [PATCH 2/7] libbpf: Return const btf_array from btf_array inline function
  2019-09-06  7:31 [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h Jiri Olsa
  2019-09-06  7:31 ` [PATCH 1/7] libbpf: Use const cast for btf_int_* functions Jiri Olsa
@ 2019-09-06  7:31 ` Jiri Olsa
  2019-09-06  7:31 ` [PATCH 3/7] libbpf: Return const btf_enum from btf_enum " Jiri Olsa
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Jiri Olsa @ 2019-09-06  7:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: netdev, bpf, Andrii Nakryiko, Yonghong Song, Martin KaFai Lau

I'm getting following errors when compiling with -Wcast-qual:

  bpf/btf.h: In function ‘btf_array* btf_array(const btf_type*)’:
  bpf/btf.h:254:35: warning: cast from type ‘const btf_type*’ to type
  ‘btf_array*’ casts away qualifiers [-Wcast-qual]
    254 |  return (struct btf_array *)(t + 1);
        |                                   ^

The argument is const so the cast to following struct btf_array
pointer should be const as well. Casting the const away in btf.c
calls where it's correctly used without const in deduplication
code.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/lib/bpf/btf.c | 4 ++--
 tools/lib/bpf/btf.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 1aa189a9112a..d6327bcc713a 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -2587,7 +2587,7 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id)
 		break;
 
 	case BTF_KIND_ARRAY: {
-		struct btf_array *info = btf_array(t);
+		struct btf_array *info = (struct btf_array *) btf_array(t);
 
 		ref_type_id = btf_dedup_ref_type(d, info->type);
 		if (ref_type_id < 0)
@@ -2782,7 +2782,7 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id)
 		break;
 
 	case BTF_KIND_ARRAY: {
-		struct btf_array *arr_info = btf_array(t);
+		struct btf_array *arr_info = (struct btf_array *) btf_array(t);
 
 		r = btf_dedup_remap_type_id(d, arr_info->type);
 		if (r < 0)
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index 952e3496467d..6bbf5772aa61 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -249,9 +249,9 @@ static inline __u8 btf_int_bits(const struct btf_type *t)
 	return BTF_INT_BITS(*(const __u32 *)(t + 1));
 }
 
-static inline struct btf_array *btf_array(const struct btf_type *t)
+static inline const struct btf_array *btf_array(const struct btf_type *t)
 {
-	return (struct btf_array *)(t + 1);
+	return (const struct btf_array *)(t + 1);
 }
 
 static inline struct btf_enum *btf_enum(const struct btf_type *t)
-- 
2.21.0


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

* [PATCH 3/7] libbpf: Return const btf_enum from btf_enum inline function
  2019-09-06  7:31 [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h Jiri Olsa
  2019-09-06  7:31 ` [PATCH 1/7] libbpf: Use const cast for btf_int_* functions Jiri Olsa
  2019-09-06  7:31 ` [PATCH 2/7] libbpf: Return const btf_array from btf_array inline function Jiri Olsa
@ 2019-09-06  7:31 ` Jiri Olsa
  2019-09-06  7:31 ` [PATCH 4/7] libbpf: Return const btf_member from btf_members " Jiri Olsa
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Jiri Olsa @ 2019-09-06  7:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: netdev, bpf, Andrii Nakryiko, Yonghong Song, Martin KaFai Lau

I'm getting following errors when compiling with -Wcast-qual:

  bpf/btf.h: In function ‘btf_enum* btf_enum(const btf_type*)’:
  bpf/btf.h:259:34: warning: cast from type ‘const btf_type*’ to type
  ‘btf_enum*’ casts away qualifier
    259 |  return (struct btf_enum *)(t + 1);
        |                                  ^

The argument is const so the cast to following struct btf_enum
pointer should be const as well. Casting the const away in btf.c
call where it's correctly used without const in deduplication
code.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/lib/bpf/btf.c | 2 +-
 tools/lib/bpf/btf.h | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index d6327bcc713a..5a39e9506760 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -1475,7 +1475,7 @@ static int btf_for_each_str_off(struct btf_dedup *d, str_off_fn_t fn, void *ctx)
 			break;
 		}
 		case BTF_KIND_ENUM: {
-			struct btf_enum *m = btf_enum(t);
+			struct btf_enum *m = (struct btf_enum *) btf_enum(t);
 			__u16 vlen = btf_vlen(t);
 
 			for (j = 0; j < vlen; j++) {
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index 6bbf5772aa61..3b3216fa348f 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -254,9 +254,9 @@ static inline const struct btf_array *btf_array(const struct btf_type *t)
 	return (const struct btf_array *)(t + 1);
 }
 
-static inline struct btf_enum *btf_enum(const struct btf_type *t)
+static inline const struct btf_enum *btf_enum(const struct btf_type *t)
 {
-	return (struct btf_enum *)(t + 1);
+	return (const struct btf_enum *)(t + 1);
 }
 
 static inline struct btf_member *btf_members(const struct btf_type *t)
-- 
2.21.0


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

* [PATCH 4/7] libbpf: Return const btf_member from btf_members inline function
  2019-09-06  7:31 [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h Jiri Olsa
                   ` (2 preceding siblings ...)
  2019-09-06  7:31 ` [PATCH 3/7] libbpf: Return const btf_enum from btf_enum " Jiri Olsa
@ 2019-09-06  7:31 ` Jiri Olsa
  2019-09-06  7:31 ` [PATCH 5/7] libbpf: Return const btf_param from btf_params " Jiri Olsa
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Jiri Olsa @ 2019-09-06  7:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: netdev, bpf, Andrii Nakryiko, Yonghong Song, Martin KaFai Lau

I'm getting following errors when compiling with -Wcast-qual:

  bpf/btf.h: In function ‘btf_member* btf_members(const btf_type*)’:
  bpf/btf.h:264:36: warning: cast from type ‘const btf_type*’ to type
  ‘btf_member*’ casts away qualifiers [-Wcast-qual]
    264 |  return (struct btf_member *)(t + 1);
        |                                    ^

The argument is const so the cast to following struct btf_member
pointer should be const as well. Casting the const away in btf.c
call where it's correctly used without const in deduplication
code.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/lib/bpf/btf.c    | 4 ++--
 tools/lib/bpf/btf.h    | 4 ++--
 tools/lib/bpf/libbpf.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 5a39e9506760..560d1ae33675 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -1463,7 +1463,7 @@ static int btf_for_each_str_off(struct btf_dedup *d, str_off_fn_t fn, void *ctx)
 		switch (btf_kind(t)) {
 		case BTF_KIND_STRUCT:
 		case BTF_KIND_UNION: {
-			struct btf_member *m = btf_members(t);
+			struct btf_member *m = (struct btf_member *) btf_members(t);
 			__u16 vlen = btf_vlen(t);
 
 			for (j = 0; j < vlen; j++) {
@@ -2797,7 +2797,7 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id)
 
 	case BTF_KIND_STRUCT:
 	case BTF_KIND_UNION: {
-		struct btf_member *member = btf_members(t);
+		struct btf_member *member = (struct btf_member *) btf_members(t);
 		__u16 vlen = btf_vlen(t);
 
 		for (i = 0; i < vlen; i++) {
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index 3b3216fa348f..cd1bd018ba8b 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -259,9 +259,9 @@ static inline const struct btf_enum *btf_enum(const struct btf_type *t)
 	return (const struct btf_enum *)(t + 1);
 }
 
-static inline struct btf_member *btf_members(const struct btf_type *t)
+static inline const struct btf_member *btf_members(const struct btf_type *t)
 {
-	return (struct btf_member *)(t + 1);
+	return (const struct btf_member *)(t + 1);
 }
 
 /* Get bit offset of a member with specified index. */
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 2233f919dd88..7d3d6284dd2e 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1389,7 +1389,7 @@ static void bpf_object__sanitize_btf(struct bpf_object *obj)
 		} else if (!has_datasec && btf_is_datasec(t)) {
 			/* replace DATASEC with STRUCT */
 			const struct btf_var_secinfo *v = btf_var_secinfos(t);
-			struct btf_member *m = btf_members(t);
+			struct btf_member *m = (struct btf_member *) btf_members(t);
 			struct btf_type *vt;
 			char *name;
 
-- 
2.21.0


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

* [PATCH 5/7] libbpf: Return const btf_param from btf_params inline function
  2019-09-06  7:31 [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h Jiri Olsa
                   ` (3 preceding siblings ...)
  2019-09-06  7:31 ` [PATCH 4/7] libbpf: Return const btf_member from btf_members " Jiri Olsa
@ 2019-09-06  7:31 ` Jiri Olsa
  2019-09-06  7:31 ` [PATCH 6/7] libbpf: Return const btf_var from btf_var " Jiri Olsa
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Jiri Olsa @ 2019-09-06  7:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: netdev, bpf, Andrii Nakryiko, Yonghong Song, Martin KaFai Lau

I'm getting following errors when compiling with -Wcast-qual:

  bpf/btf.h: In function ‘btf_param* btf_params(const btf_type*)’:
  bpf/btf.h:291:35: warning: cast from type ‘const btf_type*’ to type
  ‘btf_param*’ casts away qualifiers [-Wcast-qual]
    291 |  return (struct btf_param *)(t + 1);
        |                                   ^

The argument is const so the cast to following struct btf_param
pointer should be const as well. Casting the const away in btf.c
call where it's correctly used without const in deduplication
code.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/lib/bpf/btf.c | 6 +++---
 tools/lib/bpf/btf.h | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 560d1ae33675..b5121c79fd9f 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -1487,7 +1487,7 @@ static int btf_for_each_str_off(struct btf_dedup *d, str_off_fn_t fn, void *ctx)
 			break;
 		}
 		case BTF_KIND_FUNC_PROTO: {
-			struct btf_param *m = btf_params(t);
+			struct btf_param *m = (struct btf_param *) btf_params(t);
 			__u16 vlen = btf_vlen(t);
 
 			for (j = 0; j < vlen; j++) {
@@ -2622,7 +2622,7 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id)
 		t->type = ref_type_id;
 
 		vlen = btf_vlen(t);
-		param = btf_params(t);
+		param = (struct btf_param *) btf_params(t);
 		for (i = 0; i < vlen; i++) {
 			ref_type_id = btf_dedup_ref_type(d, param->type);
 			if (ref_type_id < 0)
@@ -2811,7 +2811,7 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id)
 	}
 
 	case BTF_KIND_FUNC_PROTO: {
-		struct btf_param *param = btf_params(t);
+		struct btf_param *param = (struct btf_param *) btf_params(t);
 		__u16 vlen = btf_vlen(t);
 
 		r = btf_dedup_remap_type_id(d, t->type);
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index cd1bd018ba8b..2817cf7ce2ee 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -286,9 +286,9 @@ static inline __u32 btf_member_bitfield_size(const struct btf_type *t,
 	return kflag ? BTF_MEMBER_BITFIELD_SIZE(m->offset) : 0;
 }
 
-static inline struct btf_param *btf_params(const struct btf_type *t)
+static inline const struct btf_param *btf_params(const struct btf_type *t)
 {
-	return (struct btf_param *)(t + 1);
+	return (const struct btf_param *)(t + 1);
 }
 
 static inline struct btf_var *btf_var(const struct btf_type *t)
-- 
2.21.0


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

* [PATCH 6/7] libbpf: Return const btf_var from btf_var inline function
  2019-09-06  7:31 [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h Jiri Olsa
                   ` (4 preceding siblings ...)
  2019-09-06  7:31 ` [PATCH 5/7] libbpf: Return const btf_param from btf_params " Jiri Olsa
@ 2019-09-06  7:31 ` Jiri Olsa
  2019-09-06  7:31 ` [PATCH 7/7] libbpf: Return const struct btf_var_secinfo from btf_var_secinfos " Jiri Olsa
  2019-09-06  9:09 ` [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h Andrii Nakryiko
  7 siblings, 0 replies; 11+ messages in thread
From: Jiri Olsa @ 2019-09-06  7:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: netdev, bpf, Andrii Nakryiko, Yonghong Song, Martin KaFai Lau

I'm getting following errors when compiling with -Wcast-qual:

  bpf/btf.h: In function ‘btf_var* btf_var(const btf_type*)’:
  bpf/btf.h:296:33: warning: cast from type ‘const btf_type*’ to type
  ‘btf_var*’ casts away qualifiers [-Wcast-qual]
    296 |  return (struct btf_var *)(t + 1);
        |                                 ^

The argument is const so the cast to following struct btf_var
pointer should be const as well.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/lib/bpf/btf.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index 2817cf7ce2ee..480dbe780fa7 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -291,9 +291,9 @@ static inline const struct btf_param *btf_params(const struct btf_type *t)
 	return (const struct btf_param *)(t + 1);
 }
 
-static inline struct btf_var *btf_var(const struct btf_type *t)
+static inline const struct btf_var *btf_var(const struct btf_type *t)
 {
-	return (struct btf_var *)(t + 1);
+	return (const struct btf_var *)(t + 1);
 }
 
 static inline struct btf_var_secinfo *
-- 
2.21.0


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

* [PATCH 7/7] libbpf: Return const struct btf_var_secinfo from btf_var_secinfos inline function
  2019-09-06  7:31 [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h Jiri Olsa
                   ` (5 preceding siblings ...)
  2019-09-06  7:31 ` [PATCH 6/7] libbpf: Return const btf_var from btf_var " Jiri Olsa
@ 2019-09-06  7:31 ` Jiri Olsa
  2019-09-06  9:09 ` [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h Andrii Nakryiko
  7 siblings, 0 replies; 11+ messages in thread
From: Jiri Olsa @ 2019-09-06  7:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: netdev, bpf, Andrii Nakryiko, Yonghong Song, Martin KaFai Lau

I'm getting following errors when compiling with -Wcast-qual:

  bpf/btf.h: In function ‘btf_var_secinfo* btf_var_secinfos(const btf_type*)’:
  bpf/btf.h:302:41: warning: cast from type ‘const btf_type*’ to type
  ‘btf_var_secinfo*’ casts away qualifiers [-Wcast-qual]
    302 |  return (struct btf_var_secinfo *)(t + 1);
        |                                         ^

The argument is const so the cast to following struct btf_var_secinfo
pointer should be const as well. Casting the const away in btf.c call
where it's correctly used without const in deduplication code.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/lib/bpf/btf.c | 5 +++--
 tools/lib/bpf/btf.h | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index b5121c79fd9f..32527622792d 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -526,7 +526,8 @@ static int btf_fixup_datasec(struct bpf_object *obj, struct btf *btf,
 
 	t->size = size;
 
-	for (i = 0, vsi = btf_var_secinfos(t); i < vars; i++, vsi++) {
+	for (i = 0, vsi = (struct btf_var_secinfo *) btf_var_secinfos(t);
+	     i < vars; i++, vsi++) {
 		t_var = btf__type_by_id(btf, vsi->type);
 		var = btf_var(t_var);
 
@@ -2830,7 +2831,7 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id)
 	}
 
 	case BTF_KIND_DATASEC: {
-		struct btf_var_secinfo *var = btf_var_secinfos(t);
+		struct btf_var_secinfo *var = (struct btf_var_secinfo *) btf_var_secinfos(t);
 		__u16 vlen = btf_vlen(t);
 
 		for (i = 0; i < vlen; i++) {
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index 480dbe780fa7..ecccde0988b1 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -296,10 +296,10 @@ static inline const struct btf_var *btf_var(const struct btf_type *t)
 	return (const struct btf_var *)(t + 1);
 }
 
-static inline struct btf_var_secinfo *
+static inline const struct btf_var_secinfo *
 btf_var_secinfos(const struct btf_type *t)
 {
-	return (struct btf_var_secinfo *)(t + 1);
+	return (const struct btf_var_secinfo *)(t + 1);
 }
 
 #ifdef __cplusplus
-- 
2.21.0


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

* Re: [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h
  2019-09-06  7:31 [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h Jiri Olsa
                   ` (6 preceding siblings ...)
  2019-09-06  7:31 ` [PATCH 7/7] libbpf: Return const struct btf_var_secinfo from btf_var_secinfos " Jiri Olsa
@ 2019-09-06  9:09 ` Andrii Nakryiko
  2019-09-06 17:03   ` Alexei Starovoitov
  2019-09-07  6:54   ` Jiri Olsa
  7 siblings, 2 replies; 11+ messages in thread
From: Andrii Nakryiko @ 2019-09-06  9:09 UTC (permalink / raw)
  To: Jiri Olsa, Alexei Starovoitov, Daniel Borkmann
  Cc: netdev, bpf, Yonghong Song, Martin Lau

On 9/6/19 8:31 AM, Jiri Olsa wrote:
> hi,
> when including btf.h in bpftrace, I'm getting -Wcast-qual warnings like:
> 
>    bpf/btf.h: In function ‘btf_var_secinfo* btf_var_secinfos(const btf_type*)’:
>    bpf/btf.h:302:41: warning: cast from type ‘const btf_type*’ to type
>    ‘btf_var_secinfo*’ casts away qualifiers [-Wcast-qual]
>      302 |  return (struct btf_var_secinfo *)(t + 1);
>          |                                         ^
> 
> I changed the btf.h header to comply with -Wcast-qual checks
> and used const cast away casting in libbpf objects, where it's

Hey Jiri,

We made all those helper funcs return non-const structs intentionally to 
improve their usability and avoid all those casts that you added back.

Also, those helpers are now part of public API, so we can't just change 
them to const, as it can break existing users easily.

If there is a need to run with -Wcast-qual, we should probably disable 
those checks where appropriate in libbpf code.

So this will be a NACK from me, sorry.

> all related to deduplication code, so I believe loosing const
> is fine there.
> 
> thanks,
> jirka
> 
> 
> ---
> Jiri Olsa (7):
>        libbpf: Use const cast for btf_int_* functions
>        libbpf: Return const btf_array from btf_array inline function
>        libbpf: Return const btf_enum from btf_enum inline function
>        libbpf: Return const btf_member from btf_members inline function
>        libbpf: Return const btf_param from btf_params inline function
>        libbpf: Return const btf_var from btf_var inline function
>        libbpf: Return const struct btf_var_secinfo from btf_var_secinfos inline function
> 
>   tools/lib/bpf/btf.c    | 21 +++++++++++----------
>   tools/lib/bpf/btf.h    | 30 +++++++++++++++---------------
>   tools/lib/bpf/libbpf.c |  2 +-
>   3 files changed, 27 insertions(+), 26 deletions(-)
> 


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

* Re: [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h
  2019-09-06  9:09 ` [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h Andrii Nakryiko
@ 2019-09-06 17:03   ` Alexei Starovoitov
  2019-09-07  6:54   ` Jiri Olsa
  1 sibling, 0 replies; 11+ messages in thread
From: Alexei Starovoitov @ 2019-09-06 17:03 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Jiri Olsa, Alexei Starovoitov, Daniel Borkmann, netdev, bpf,
	Yonghong Song, Martin Lau

On Fri, Sep 6, 2019 at 2:09 AM Andrii Nakryiko <andriin@fb.com> wrote:
>
> On 9/6/19 8:31 AM, Jiri Olsa wrote:
> > hi,
> > when including btf.h in bpftrace, I'm getting -Wcast-qual warnings like:
> >
> >    bpf/btf.h: In function ‘btf_var_secinfo* btf_var_secinfos(const btf_type*)’:
> >    bpf/btf.h:302:41: warning: cast from type ‘const btf_type*’ to type
> >    ‘btf_var_secinfo*’ casts away qualifiers [-Wcast-qual]
> >      302 |  return (struct btf_var_secinfo *)(t + 1);
> >          |                                         ^
> >
> > I changed the btf.h header to comply with -Wcast-qual checks
> > and used const cast away casting in libbpf objects, where it's
>
> Hey Jiri,
>
> We made all those helper funcs return non-const structs intentionally to
> improve their usability and avoid all those casts that you added back.
>
> Also, those helpers are now part of public API, so we can't just change
> them to const, as it can break existing users easily.
>
> If there is a need to run with -Wcast-qual, we should probably disable
> those checks where appropriate in libbpf code.
>
> So this will be a NACK from me, sorry.

Same opinion. This gcc warning is bogus.

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

* Re: [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h
  2019-09-06  9:09 ` [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h Andrii Nakryiko
  2019-09-06 17:03   ` Alexei Starovoitov
@ 2019-09-07  6:54   ` Jiri Olsa
  1 sibling, 0 replies; 11+ messages in thread
From: Jiri Olsa @ 2019-09-07  6:54 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Jiri Olsa, Alexei Starovoitov, Daniel Borkmann, netdev, bpf,
	Yonghong Song, Martin Lau

On Fri, Sep 06, 2019 at 09:09:17AM +0000, Andrii Nakryiko wrote:
> On 9/6/19 8:31 AM, Jiri Olsa wrote:
> > hi,
> > when including btf.h in bpftrace, I'm getting -Wcast-qual warnings like:
> > 
> >    bpf/btf.h: In function ‘btf_var_secinfo* btf_var_secinfos(const btf_type*)’:
> >    bpf/btf.h:302:41: warning: cast from type ‘const btf_type*’ to type
> >    ‘btf_var_secinfo*’ casts away qualifiers [-Wcast-qual]
> >      302 |  return (struct btf_var_secinfo *)(t + 1);
> >          |                                         ^
> > 
> > I changed the btf.h header to comply with -Wcast-qual checks
> > and used const cast away casting in libbpf objects, where it's
> 
> Hey Jiri,
> 
> We made all those helper funcs return non-const structs intentionally to 
> improve their usability and avoid all those casts that you added back.
> 
> Also, those helpers are now part of public API, so we can't just change 
> them to const, as it can break existing users easily.
> 
> If there is a need to run with -Wcast-qual, we should probably disable 
> those checks where appropriate in libbpf code.
> 
> So this will be a NACK from me, sorry.

ok, I'll disable disable it in bpftrace code then

thanks,
jirka

> 
> > all related to deduplication code, so I believe loosing const
> > is fine there.
> > 
> > thanks,
> > jirka
> > 
> > 
> > ---
> > Jiri Olsa (7):
> >        libbpf: Use const cast for btf_int_* functions
> >        libbpf: Return const btf_array from btf_array inline function
> >        libbpf: Return const btf_enum from btf_enum inline function
> >        libbpf: Return const btf_member from btf_members inline function
> >        libbpf: Return const btf_param from btf_params inline function
> >        libbpf: Return const btf_var from btf_var inline function
> >        libbpf: Return const struct btf_var_secinfo from btf_var_secinfos inline function
> > 
> >   tools/lib/bpf/btf.c    | 21 +++++++++++----------
> >   tools/lib/bpf/btf.h    | 30 +++++++++++++++---------------
> >   tools/lib/bpf/libbpf.c |  2 +-
> >   3 files changed, 27 insertions(+), 26 deletions(-)
> > 
> 

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

end of thread, other threads:[~2019-09-07  6:54 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-06  7:31 [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h Jiri Olsa
2019-09-06  7:31 ` [PATCH 1/7] libbpf: Use const cast for btf_int_* functions Jiri Olsa
2019-09-06  7:31 ` [PATCH 2/7] libbpf: Return const btf_array from btf_array inline function Jiri Olsa
2019-09-06  7:31 ` [PATCH 3/7] libbpf: Return const btf_enum from btf_enum " Jiri Olsa
2019-09-06  7:31 ` [PATCH 4/7] libbpf: Return const btf_member from btf_members " Jiri Olsa
2019-09-06  7:31 ` [PATCH 5/7] libbpf: Return const btf_param from btf_params " Jiri Olsa
2019-09-06  7:31 ` [PATCH 6/7] libbpf: Return const btf_var from btf_var " Jiri Olsa
2019-09-06  7:31 ` [PATCH 7/7] libbpf: Return const struct btf_var_secinfo from btf_var_secinfos " Jiri Olsa
2019-09-06  9:09 ` [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h Andrii Nakryiko
2019-09-06 17:03   ` Alexei Starovoitov
2019-09-07  6:54   ` Jiri Olsa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).