On Mon, Jun 24, 2024 at 6:05 AM Alan Maguire <alan.maguire@xxxxxxxxxx> wrote: > > 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; while you are at it, please declare them as: unsigned int needs_size: 1; unsigned int size: 31; This multi-line fields declaration is unusual for libbpf code base and looks out of place (I didn't want to nitpick on that initially, but it caught my eye immediately back then) also, I believe if you did bool needs_size: 1; unsigned size: 31; it would work fine as well and would let you use true/false (please double check with pahole if compiler co-locates all the bits into a single 32-bit backing integer) pw-bot: cr > __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 >