pahole -J .tmp_linux.btf during Linux build process always crashes
on my system.
Problem is that when gobuffer is initialized via gobuffer__init(),
it is in state where 'index' (AKA its size) is set to 1, but
'entries' is NULL.
State corrects itself if 'gobuffer__add()' is invoked, as that
will allocate buffer (even if added len == 0). But if __add()
is never invoked because only anonymous symbols are present,
one ends up with gobuffer that crashes gobuffer__copy.
Instead of allocating single-byte buffer always I opted for
checking if gobuffer entries is NULL before use in copy and
compress - gobuffer__init() would need prototype change to
report malloc failures, and it seems unnecessary to allocate
memory always - even if file does not have any symbols after
all.
(gdb) bt
#0 __memmove_sse2_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:287
#1 0x00007f2f2c1ec2ee in btf_elf__encode (btfe=0x5654e31e2e30, flags=flags@entry=0 '\000') at libbtf.c:750
#2 0x00007f2f2c1e9af0 in btf_encoder__encode () at btf_encoder.c:164
#3 0x00005654e2407599 in main (argc=3, argv=0x7ffcd8783f18) at pahole.c:1344
(gdb) frame 1
#1 0x00007f2f2c1ec2ee in btf_elf__encode (btfe=0x5654e31e2e30, flags=flags@entry=0 '\000') at libbtf.c:750
750 gobuffer__copy(btfe->strings, btf_elf__nohdr_data(btfe) + hdr->str_off);
(gdb) print btfe->strings
$1 = (struct gobuffer *) 0x5654e31db2c8
(gdb) print *btfe->strings
$2 = {entries = 0x0, nr_entries = 0, index = 1, allocated_size = 0}
(gdb) print btfe->types
$3 = {entries = 0x5654e31e2ef0 "", nr_entries = 1, index = 16, allocated_size = 8192}
(gdb) x /16bx btfe->types.entries
0x5654e31e2ef0: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01
0x5654e31e2ef8: 0x04 0x00 0x00 0x00 0x20 0x00 0x00 0x00
Signed-off-by: Petr Vandrovec <petr@vmware.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
As Thomas Gleixner wisely pointed out, using 'self' is stupid, it
doesn't convey useful information, so use sensible names.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Kinda brown paper bag one, and the thanks goes to C++ and the boost
library for providing such beautiful test cases as:
virtual int undefine(class
grammar_helper<boost::spirit::grammar<boost::detail::graph::dot_skipper,
boost::spirit::parser_context<boost::spirit::nil, class
grammar<boost::detail::graph::dot_skipper,
boost::spirit::parser_context<boost::spirit::nil_t> > *); /*
linkage=_ZN5boost6spirit4impl14grammar_helperINS0_7grammarINS_6detail5graph11dot_skipperENS0_14parser_contextINS0_5nil_tEEEEES6_NS0_7scannerINS0_10multi_passISt16istream_iteratorIccSt11char_traitsIcElENS0_19multi_pass_policies14input_iteratorENSH_11ref_countedENSH_12buf_id_checkENSH_9std_dequeEEENS0_16scanner_policiesINS0_27no_skipper_iteration_policyINS0_29inhibit_case_iteration_policyINS0_28skip_parser_iteration_policyIS6_NS0_16iteration_policyEEEEEEENS0_12match_policyENS0_13action_policyEEEEEE8undefineEPSA_
*/
;-)
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
So that we can also reserve space for things that will be added in
several steps, such as CTF structs, where we first add a struct for the
name, size, nr_members, then several ones for the members.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>