Commit Graph

1987 Commits

Author SHA1 Message Date
Arnaldo Carvalho de Melo 4b877c8e67 pahole: enumeration__lookup_enumerator() doesn't need a 'cu' argument
With the conversion of ->name members to plain char strings, no need
to use 'cu' to get the old string_t index and find the per-cu string
table.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo 3ff11828fe core: enumeration__emit_definitions() doesn't need a 'cu' argument
With the conversion of ->name members to plain char strings, no need
to use 'cu' to get the old string_t index and find the per-cu string
table.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo 0947d6e795 core: enumeration__fprintf() doesn't need a 'cu' argument
With the conversion of ->name members to plain char strings, no need
to use 'cu' to get the old string_t index and find the per-cu string
table.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo bb22f5bb0a core: Make enumeration__max_entry_name_len() static
As it is not used outside where it is defined.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo dc83336171 core: enumeration__max_entry_name_len() doesn't need a 'cu' argument
With the conversion of ->name members to plain char strings, no need
to use 'cu' to get the old string_t index and find the per-cu string
table.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo ec1667c76d core: Make enumeration__calc_prefix() static
As it is not used outside where it is defined.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo 45ec63ed20 core: enumeration__calc_prefix doesn't need a 'cu' argument
With the conversion of ->name members to plain char strings, no need
to use 'cu' to get the old string_t index and find the per-cu string
table.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo 2fae84e2f7 btf_encoder: btf_encoder__add_enum_type() doesn't need a 'cu' argument, ditch it
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo 96243fdd79 core: enumerator__name() doesn't need a 'cu' argument, ditch it
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo ee5c12893b core: Ditch dwarves__active_loader, unused
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo 713239bc00 core: Make enumerator->name a real string
For the threaded code we want to access strings in tags at the same time
that the string table may grow in another thread making the previous
pointer invalid, so, to avoid excessive locking, use plain strings.

The way the tools work will either consume the just produced CU straight
away or keep just one copy of each data structure when we keep all CUs
in memory, so lets try stopping using strings_t for strings.

For the enumerator->name case we get the bonus of removing the last user
of dwarves__active_loader in the btf_encoder class.

This covers unions, enums, structs and classes.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo 7721cc17ac emit: type__emit_fwd_decl() isn't used outside emit.c, make it static
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo 9aa5db7acd emit: type__emit_fwd_decl() doesn't need a cu arg
Due to previous simplifications in the FOO__name() methods.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo c46f91ef6f emit: type_emissions__find_definition() doesn't need a cu arg
Due to previous simplifications in the FOO__name() methods.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo c127d25daf core: class__name() doesn't need a cu arg
Now that namespace->name is a real char string.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo 00e8c5fe21 core: type__name() doesn't need a cu arg
Now that namespace->name is a real char string.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo b99c4008ac core: Make namespace->name a real string
For the threaded code we want to access strings in tags at the same time
that the string table may grow in another thread making the previous
pointer invalid, so, to avoid excessive locking, use plain strings.

The way the tools work will either consume the just produced CU straight
away or keep just one copy of each data structure when we keep all CUs
in memory, so lets try stopping using strings_t for strings.

For the namespace->name case we get the bonus of removing another
user of dwarves__active_loader.

This covers unions, enums, structs and classes.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo 379a73c6eb core: Make class_member->name a real string
For the threaded code we want to access strings in tags at the same time
that the string table may grow in another thread making the previous
pointer invalid, so, to avoid excessive locking, use plain strings.

The way the tools work will either consume the just produced CU straight
away or keep just one copy of each data structure when we keep all CUs
in memory, so lets try stopping using strings_t for strings.

For the class_member->name case we get the bonus of removing another
user of dwarves__active_loader.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo 3280cb4176 core: Make parameter->name a real string
For the threaded code we want to access strings in tags at the same time
that the string table may grow in another thread making the previous
pointer invalid, so, to avoid excessive locking, use plain strings.

The way the tools work will either consume the just produced CU straight
away or keep just one copy of each data structure when we keep all CUs
in memory, so lets try stopping using strings_t for strings.

For the parameter->name case we get the bonus of removing a user of
dwarves__active_loader.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo f009162fd1 core: Make base_type->name a real string
For the threaded code we want to access strings in tags at the same time
that the string table may grow in another thread making the previous
pointer invalid, so, to avoid excessive locking, use plain strings.

The way the tools work will either consume the just produced CU straight
away or keep just one copy of each data structure when we keep all CUs
in memory, so lets try stopping using strings_t for strings.

For the base_type->name case we get the bonus of removing some more
functions related base types and a user of dwarves__active_loader.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo e2ee753fa7 pahole: Disable incomplete CTF encoder
It was never fully functional and now its getting in the way of further
improvements for loading/encoding BTF and loading DWARF.

Eventually we can use Oracle's libctf library to add an encoder.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:44 -03:00
Arnaldo Carvalho de Melo 0d13bc50ee core: Ditch unused cu__find_struct_by_sname()
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:17 -03:00
Arnaldo Carvalho de Melo 46f3f37241 core: Convert cu__find_base_type_by_sname_and_size to search for a string
It looked for an index into a string table, a string_t, but since for
multithreading we'd be growing the string table while looking up stuff,
we'd be looking at realloc'ed memory, so lets move to stable char
pointer strings.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo f84e8777ea core: Convert cu__find_enumeration_by_sname_and_size to search for a string
It looked for an index into a string table, a string_t, but since for
multithreading we'd be growing the string table while looking up stuff,
we'd be looking at realloc'ed memory, so lets move to stable char
pointer strings.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo a16c82f711 dwarf_loader: Rename strings_t 'name' to 'sname' to clarify usage
We're transitioning to plain strings, so lets pave the way for that
step by step.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo 82e5b5101a core: Make function->name a real string
For the threaded code we want to access strings in tags at the same time
that the string table may grow in another thread making the previous
pointer invalid, so, to avoid excessive locking, use plain strings.

The way the tools work will either consume the just produced CU straight
away or keep just one copy of each data structure when we keep all CUs
in memory, so lets try stopping using strings_t for strings.

For the function->name case we get the bonus of removing the need of a
debug_fmt_ops->function() callback receiving the 'cu', just access the
string directly.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo 4f73cac853 core: Make function->linkage_name a real string
For the threaded code we want to access strings in tags at the same time
that the string table may grow in another thread making the previous
pointer invalid, so, to avoid excessive locking, use plain strings.

The way the tools work will either consume the just produced CU straight
away or keep just one copy of each data structure when we keep all CUs
in memory, so lets try stopping using strings_t for strings.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo a93160df53 dwarf_loader: Make dwarf_tag->decl_file a real string
For the threaded code we want to access strings in tags at the same time
that the string table may grow in another thread making the previous
pointer invalid, so, to avoid excessive locking, use plain strings.

The way the tools work will either consume the just produced CU straight
away or keep just one copy of each data structure when we keep all CUs
in memory, so lets try stopping using strings_t for strings.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo a3fcbcacf7 pahole: Allow specifying the number of threads to use while loading files
Using the same command line option as 'make' and 'ninja': -j.
Unfortunately the argp parser in glibc expects a '=' for single letter
args, so it is:

  $ pahole -j=10

or, like with 'make':

  $ make --jobs=10

This is unwired at the moment, probably I'll reorder the patch, but for
testing, add it first.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo d70b2562ee pahole: Make '-j' available for use as number of jobs (threads)
The '-j' option, to generate detached BTF files wasn't published in any
tagged release, so leave it as just --btf_encode_detached and make '-j'
available for specifying the number of jobs/threads, as is the case with
'make -j', 'ninja -j', etc.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo 41a283c65d core: Protect cus->cus with a mutex
Paving the way for having multiple threads creating CUs and possibly
adding them to cus->cus.

The mutex will also be used to ask elfutils-libdwfl to read the next CU,
after a thread finishes reading one.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo 972065482a core: Make 'struct cus' opaque, only visible in dwarves.c
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo 3895b29060 core: Introduce helper to return number of cu entries in a 'struct cus'
Provide a helper so that we can make 'struct cus' opaque.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo 874e750fb8 core: Move cus__find_pair() from codiff to the core
To avoid touching 'struct cus' internal state outside dwarves.c

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo bf74fc1fcf core: Introduce helper to return if there is no cu entries in a 'struct cus'
Provide a helper so that we can make 'struct cus' opaque.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo 7020f92143 core: Prepare cus__find_cu_by_name() for locking
By having just one exit point.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo 4bf7285b37 core: Prepare cus__find_function_at_addr() for locking
By having just one exit point.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo 73a2fd1e5a core: Prepare __cus__find_struct_by_name() for locking
By having just one exit point.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo 5020bf721b core: Prepare cus__find_type_by_name() for locking
By having just one exit point.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:18:16 -03:00
Arnaldo Carvalho de Melo d124926baf core: Initialize cu->priv in cu__new()
cus__load_btf() may bail out if btf__parse_split() fails, for instance
when processing a malformed detached BTF file, and then call
cu__delete(cu) that in turn calls btf__cu_delete(cu->priv), and as
cu->priv wasn't initialized, a segfault ensues.

Fix it by initializing cu->priv in cu__new().

This fix was in the 'next'/'tmp.master' branch and was also found and
fixed by Thomas Weißschuh <thomas@t-8ch.de>.

Link: https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?h=tmp.master&id=e9f3028efbeff225d8ced3c0bfa9fe82857b0a14
Link: https://lore.kernel.org/dwarves/20210728175459.143265-1-thomas@t-8ch.de/
Reported-by: Thomas Weißschuh <thomas@t-8ch.de>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-28 15:13:08 -03:00
Arnaldo Carvalho de Melo 3ec54ee72f CMakeList.txt: Bump version to the upcoming 1.22 release, not out of the door yet
This is just for CIs to be able to, building from master, encode
variables, that are disabled in the Linux kernel but fixed with what
came after v1.21.

Requested-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-07-27 13:28:19 -03:00
Arnaldo Carvalho de Melo 1ef87b26fd Revert "btf_encoder: Reduce the size of encode_cu() by moving function encoding to separate method"
This reverts commit de3a7f9125.

Andrii reports that this cset is breaking the CI, as reported at:

  https://travis-ci.com/github/libbpf/libbpf/jobs/514329152

So revert it while investigation about the root cause continues.

Reported-by: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-16 21:07:22 -03:00
Arnaldo Carvalho de Melo 7869cc113b dwarf_loader: Separate non-LTO per CU processing + BTF encoding part
So that we can on from there to a multi-threaded CU loading + BTF
encoding.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-15 18:10:01 -03:00
Arnaldo Carvalho de Melo de3a7f9125 btf_encoder: Reduce the size of encode_cu() by moving function encoding to separate method
Just to make code more manageable, no change intended.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-15 15:12:00 -03:00
Arnaldo Carvalho de Melo d348b37ed1 btf_encoder: Reduce the size of encode_cu() by moving var encoding to separate method
Just to make code more manageable, no change intended.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-15 15:07:41 -03:00
Arnaldo Carvalho de Melo f62196d3be btf_encoder: No need to set the endianness twice when encoding into an ELF file
We do it already at the constructor.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-14 18:53:35 -03:00
Arnaldo Carvalho de Melo 819f83bd97 btf_encoder: Pass detached_filename to the constructor
The ->filename only points out to the ELF file when we're not writing to
a raw, detached BTF file, so reuse it to store the detached filename
when using that mode.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-14 18:53:35 -03:00
Arnaldo Carvalho de Melo 7ed4ddc468 btf_encoder: Adopt writing to raw file method
To stop using the btf__ namespace.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-14 18:53:35 -03:00
Arnaldo Carvalho de Melo 1498094d33 btf_encoder: Rename btf__encode_in_elf to btf_encoder__write_elf, shortening function signature
We were passing two 'btf_encoder' fields, so pass just the btf_encoder
instance. Ditch the unused 'flags' arg.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-14 18:53:35 -03:00
Arnaldo Carvalho de Melo cd2b8978c4 btf_encoder: Combine btf__write_elf() with btf__encode_in_elf()
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-14 18:53:35 -03:00