[PATCH bpf-next] libbpf: fix clang compilation error in

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When building with clang for ARCH=i386, the following errors are
observed:

  CC      kernel/bpf/btf_relocate.o
./tools/lib/bpf/btf_relocate.c:206:23: error: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion]
  206 |                 info[id].needs_size = true;
      |                                     ^ ~
./tools/lib/bpf/btf_relocate.c:256:25: error: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion]
  256 |                         base_info.needs_size = true;
      |                                              ^ ~
2 errors generated.

The problem is we use 1-bit and 31-bit bitfields in a signed int;
changing to unsigned int resolves the error.  Change associated
assignments from 'true' to 1 also for clarity.

Signed-off-by: Alan Maguire <alan.maguire@xxxxxxxxxx>
---
 tools/lib/bpf/btf_relocate.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/lib/bpf/btf_relocate.c b/tools/lib/bpf/btf_relocate.c
index 2281dbbafa11..1fa11aa4e827 100644
--- a/tools/lib/bpf/btf_relocate.c
+++ b/tools/lib/bpf/btf_relocate.c
@@ -58,8 +58,8 @@ struct btf_relocate {
 struct btf_name_info {
 	const char *name;
 	/* set when search requires a size match */
-	int needs_size:1,
-	    size:31;
+	unsigned int needs_size:1,
+		     size:31;
 	__u32 id;
 };
 
@@ -203,7 +203,7 @@ static int btf_relocate_map_distilled_base(struct btf_relocate *r)
 		info[id].name = btf__name_by_offset(r->dist_base_btf, dist_t->name_off);
 		info[id].id = id;
 		info[id].size = dist_t->size;
-		info[id].needs_size = true;
+		info[id].needs_size = 1;
 	}
 	qsort(info, r->nr_dist_base_types, sizeof(*info), cmp_btf_name_size);
 
@@ -253,7 +253,7 @@ static int btf_relocate_map_distilled_base(struct btf_relocate *r)
 		case BTF_KIND_ENUM:
 		case BTF_KIND_ENUM64:
 			/* These types should match both name and size */
-			base_info.needs_size = true;
+			base_info.needs_size = 1;
 			base_info.size = base_t->size;
 			break;
 		case BTF_KIND_FWD:
-- 
2.31.1





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux