Go to file
Petr Vandrovec 88674f0395 gobuffer: Do not crash on object without any public symbols
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>
2020-01-17 13:54:15 -03:00
cmake/modules cmake: Add comments explaining build_id and fedora/rh detection 2009-06-27 13:32:20 -03:00
lib libbpf: Get latest libbpf 2019-10-21 17:31:15 -03:00
man-pages man-pages: Add section about --hex + -E to locate offsets deep into sub structs 2020-01-16 12:10:54 -03:00
ostra ostra: Initial python3 conversion 2019-04-23 12:02:22 -03:00
rpm/SPECS pahole: Fix changelog date in dwarves.spec 2020-01-17 13:34:33 -03:00
.gitignore pahole: Add build dir, config.h to .gitignore 2019-02-11 12:55:46 -03:00
.gitmodules pahole: add libbpf as submodule under lib/bpf 2019-02-11 12:56:40 -03:00
CMakeLists.txt dwarves: Prep v1.16 2019-12-16 11:43:53 -03:00
COPYING [LICENSE]: Add COPYING file and add missing license info on some files 2007-12-17 14:15:42 -02:00
MANIFEST Add changes-v1.16 to the MANIFEST file 2020-01-17 13:34:37 -03:00
NEWS dwarves: Prep v1.16 2019-12-16 11:43:53 -03:00
README [CMAKE]: Make the default install prefix be /usr/local 2007-04-19 18:01:47 -03:00
README.DEBUG README.DEBUG: Add an extra step to make the instructions cut'n'exec 2017-12-14 14:15:54 -03:00
README.btf v1.13: New release 2019-04-16 16:13:19 -03:00
README.ctracer ctracer: update README.ctracer, f9 has the dwarves 2008-10-29 08:54:53 -02:00
btf_encoder.c btf_encoder: Preserve and encode exported functions as BTF_KIND_FUNC 2019-11-05 09:27:58 -03:00
btf_encoder.h Fixup copyright notices for BTF files authored by Facebook engineers 2019-01-18 20:34:05 -03:00
btf_loader.c btf_loader: Add support for BTF_KIND_FUNC 2019-11-05 12:04:23 -03:00
btfdiff v1.13: New release 2019-04-16 16:13:19 -03:00
changes-v1.13 v1.13: New release 2019-04-16 16:13:19 -03:00
changes-v1.16 dwarves: Prep v1.16 2019-12-16 11:43:53 -03:00
codiff.c codiff: Remove unused filenames variable 2019-07-01 16:41:02 -03:00
config.h.cmake [DWARVES] Fixes a FIXME relating to a missing elf (libdw) symbol check. 2008-02-12 21:08:49 -02:00
ctf.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
ctf_encoder.c libctf: The type_ids returned are uint32_t fixup where it was uint16_t 2019-03-11 11:44:53 -03:00
ctf_encoder.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
ctf_loader.c ctf_loader: Plug leak when bailing out due to unknown tag 2019-07-01 21:43:46 -03:00
ctfdwdiff ctfdwdiff: Don't ask for variables and inline expansions in pfunct 2009-03-31 19:21:46 -03:00
ctracer.c tag: Introduce tag__is_pointer_to() 2019-04-05 15:28:55 -03:00
dtagnames.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
dutil.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
dutil.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
dwarf_loader.c btf_encoder: Preserve and encode exported functions as BTF_KIND_FUNC 2019-11-05 09:27:58 -03:00
dwarves.c dwarves: Introduce cu__find_type_by_name 2020-01-15 13:45:47 -03:00
dwarves.h dwarves: Introduce cu__find_type_by_name 2020-01-15 13:45:47 -03:00
dwarves_emit.c emit: Remove unused 'is_pointer' variable 2019-07-02 10:27:16 -03:00
dwarves_emit.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
dwarves_fprintf.c fprintf: Fixup truncation possibility pointed out by gcc -O2 2019-12-16 11:19:47 -03:00
dwarves_reorganize.c reorganize: Enclose bitfield routines under ifdef 2019-07-02 12:28:50 -03:00
dwarves_reorganize.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
elf_symtab.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
elf_symtab.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
elfcreator.c elfcreator: Address initialization warning emitted by 'gcc -O6' 2019-12-16 11:19:47 -03:00
elfcreator.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
fullcircle v1.13: New release 2019-04-16 16:13:19 -03:00
gobuffer.c gobuffer: Do not crash on object without any public symbols 2020-01-17 13:54:15 -03:00
gobuffer.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
hash.h [DWARVES]: Use a hash table for the tags in a CU 2008-02-11 11:47:17 -02:00
libbtf.c btf loader: Support raw BTF as available in /sys/kernel/btf/vmlinux 2020-01-06 13:09:16 -03:00
libbtf.h btf loader: Support raw BTF as available in /sys/kernel/btf/vmlinux 2020-01-06 13:09:16 -03:00
libctf.c libctf: Enlarge the 'cmd' buffer to not possibly truncate the pathname 2019-07-02 12:14:02 -03:00
libctf.h libctf: The type_ids returned are uint32_t fixup where it was uint16_t 2019-03-11 11:44:53 -03:00
list.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
pahole.c pahole: Initialize var to silence -Werror=maybe-uninitialized on gcc version 4.8.5 20150623 2020-01-17 12:40:37 -03:00
pdwtags.c core: Allow the loaders to advertise features they have 2019-04-15 14:45:27 -03:00
pfunct.c btf_loader: Add support for BTF_KIND_FUNC 2019-11-05 12:04:23 -03:00
pglobal.c pglobal: Allow passing the format path specifier, to use with BTF 2019-10-24 08:17:16 -03:00
prefcnt.c prefcnt: Avoid ambiguous else with for_each macro 2019-07-02 12:31:57 -03:00
rbtree.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
rbtree.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
regtest regtest: Accept --diff instad of plain 'diff' as long option 2012-05-14 19:36:58 -03:00
scncopy.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
strings.c Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
strings.h Adopt SPDX-License-Identifier 2019-01-18 15:41:48 -03:00
syscse.c dwarves: Make function__for_each_parameter receive 'cu' arg 2020-01-09 14:16:52 -03:00

README

Build instructions:

1. install cmake
2. mkdir build
3. cd build
4. cmake -D__LIB=lib ..
5. make install

Default is to be installed on /usr/local, see rpm spec file for
installing on other places.

Known to work scenarios:

Mandriva Cooker:

cmake 2.4.5-1mdv2007.1
libelfutils1-devel 0.123-1mdv2007.1

Debian Unstable:

cmake 2.4.5-1
libdw-dev 0.123-2

Fedora Core 6:

cmake 2.4.5-2.fc6
elfutils-devel 0.126-1.fc6