aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2022-08-07 10:53:09 -0700
committerArnaldo Carvalho de Melo <acme@redhat.com>2022-08-10 15:59:27 -0300
commitd6c952893b1bbea9000b5fe2ba374fd56bf272d8 (patch)
tree368dadd302e365ab9d691983755580bc7ec9b6e5
parent23342fef5e5f607031d18a12be0e4b8d60428be5 (diff)
downloadpahole-d6c952893b1bbea9000b5fe2ba374fd56bf272d8.tar.gz
dwarf_loader: Encode char type as signed
Currently, the pahole treats 'char' or 'signed char' type as unsigned in BTF generation. The following is an example, $ cat t.c signed char a; char b; $ clang -O2 -g -c t.c $ pahole -JV t.o ... [1] INT signed char size=1 nr_bits=8 encoding=(none) [2] INT char size=1 nr_bits=8 encoding=(none) In the above encoding '(none)' implies unsigned type. But if the same program is compiled with bpf target, $ clang -target bpf -O2 -g -c t.c $ bpftool btf dump file t.o [1] INT 'signed char' size=1 bits_offset=0 nr_bits=8 encoding=SIGNED [2] VAR 'a' type_id=1, linkage=global [3] INT 'char' size=1 bits_offset=0 nr_bits=8 encoding=SIGNED [4] VAR 'b' type_id=3, linkage=global [5] DATASEC '.bss' size=0 vlen=2 type_id=2 offset=0 size=1 (VAR 'a') type_id=4 offset=0 size=1 (VAR 'b') the 'char' and 'signed char' are encoded as SIGNED integers. Encode 'char' and 'signed char' as SIGNED should be a right to do and it will be consistent with bpf implementation. With this patch, $ pahole -JV t.o ... [1] INT signed char size=1 nr_bits=8 encoding=SIGNED [2] INT char size=1 nr_bits=8 encoding=SIGNED Signed-off-by: Yonghong Song <yhs@fb.com> Acked-by: Andrii Nakryiko <andrii@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: bpf@vger.kernel.org Cc: dwarves@vger.kernel.org Cc: kernel-team@fb.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--dwarf_loader.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/dwarf_loader.c b/dwarf_loader.c
index d892bc37..c2ad2a03 100644
--- a/dwarf_loader.c
+++ b/dwarf_loader.c
@@ -560,7 +560,7 @@ static struct base_type *base_type__new(Dwarf_Die *die, struct cu *cu, struct co
bt->bit_size = attr_numeric(die, DW_AT_byte_size) * 8;
uint64_t encoding = attr_numeric(die, DW_AT_encoding);
bt->is_bool = encoding == DW_ATE_boolean;
- bt->is_signed = encoding == DW_ATE_signed;
+ bt->is_signed = (encoding == DW_ATE_signed) || (encoding == DW_ATE_signed_char);
bt->is_varargs = false;
bt->name_has_encoding = true;
bt->float_type = encoding_to_float_type(encoding);