Commit Graph

424 Commits

Author SHA1 Message Date
Arnaldo Carvalho de Melo caa219dffc core: base_type__name() doesn't need a 'cu' arg
Another simplification made possible by using a plain char string
instead of string_t, that was only needed in the core as prep work
for CTF encoding.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:41:13 -03:00
Arnaldo Carvalho de Melo 7569e46d35 core: namespace__delete() doesn't need a 'cu' arg
Since we stopped using per-cu obstacks we don't need it. If we ever
want to use it we can do per thread obstacks.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:41:13 -03:00
Arnaldo Carvalho de Melo de4e8b7f17 core: {tag,function,lexblock}__delete() doesn't need a 'cu' arg
Since we stopped using per-cu obstacks we don't need it. If we ever
want to use it we can do per thread obstacks.

They call each other, so do the three at once.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:41:13 -03:00
Arnaldo Carvalho de Melo 789ed4e3a2 core: ftype__delete() doesn't need a 'cu' arg
Since we stopped using per-cu obstacks we don't need it. If we ever
want to use it we can do per thread obstacks.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:41:13 -03:00
Arnaldo Carvalho de Melo 6340cb4627 core: enumeration__delete() doesn't need a 'cu' arg
Since we stopped using per-cu obstacks we don't need it. If we ever
want to use it we can do per thread obstacks.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:41:13 -03:00
Arnaldo Carvalho de Melo 33e44f5295 core: type__delete() doesn't need a 'cu' arg
Since we stopped using per-cu obstacks we don't need it. If we ever
want to use it we can do per thread obstacks.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:41:13 -03:00
Arnaldo Carvalho de Melo 0f54ca9c82 core: class__clone() doesn't need a 'cu' arg
Since we stopped using per-cu obstacks we don't need it. If we ever
want to use it we can do per thread obstacks.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:41:13 -03:00
Arnaldo Carvalho de Melo 2b2014187b core: class__delete() doesn't need a 'cu' arg
Since we stopped using per-cu obstacks we don't need it. If we ever
want to use it we can do per thread obstacks.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:41:13 -03:00
Arnaldo Carvalho de Melo f40900eba6 core: type__delete_class_members() doesn't need a 'cu' arg
Since we stopped using per-cu obstacks we don't need it. If we ever
want to use it we can do per thread obstacks.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:41:13 -03:00
Arnaldo Carvalho de Melo 50916756d5 core: class_member__delete() doesn't need a 'cu' arg
Since we stopped using per-cu obstacks we don't need it. If we ever
want to use it we can do per thread obstacks.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:41:13 -03:00
Arnaldo Carvalho de Melo 2e50463c3a core: type__clone_members() doesn't need a 'cu' arg
Since we stopped using per-cu obstacks we don't need it. If we ever
want to use it we can do per thread obstacks.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:41:13 -03:00
Arnaldo Carvalho de Melo a66208355e core: class_member__clone() doesn't need a 'cu' arg
Since we stopped using per-cu obstacks we don't need it. If we ever
want to use it we can do per thread obstacks.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:41:13 -03:00
Arnaldo Carvalho de Melo 63992cb02a core: Use namespace->name in class__clone()
Now that we stopped using string indexes, no need for that, just set
namespace->name with the new class name.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:41:13 -03:00
Arnaldo Carvalho de Melo ced4c34c37 core: Remove strings.c, unused
We were using this just for the ctf_encoder, that never really got
complete, so ditch it.

For BTF the strings table is done by libbpf, so we don't need it there
either.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:41:11 -03:00
Arnaldo Carvalho de Melo ad707445b3 core: Remove base_type_name_to_size_table.sname, unused
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo 05687c547e core: Remove unused cu__string() method
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo 6b7f1b72f9 core: No need for debug_fmt_ops->variable_name() anymore
Since we store a char pointer string in variable->name, we can use it
directly.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo 9d0e3ab9a2 pahole: function__name() doesn't need a 'struct cu *' argument
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo a7d789a4f8 core: Make variable->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-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo f8d98eff75 core: Ditch unused enumeration__prefix_len() method
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-12 09:39:46 -03:00
Arnaldo Carvalho de Melo 5cc365164a core: Ditch unused enumeration__prefix() method
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 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 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 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 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 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 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 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 790dfbda79 headers: Rebame __unused to __maybe_unused to avoid clashes with system headers
Andrii reported that __unused is a field in /usr/include/bits/stat.h and
vmlinux.h (generated by bpftool), so use the Linux kernel jargon for
this and rename it to '__maybe_unused'.

Reported-by: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-13 10:25:35 -03:00
Arnaldo Carvalho de Melo 7fb31d787d btf_loader: Stop using libbtf.h and the btf_elf class
Now we just use libbpf's API to do everything.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-04 17:28:56 -03:00
Arnaldo Carvalho de Melo fb418f9d83 dwarves: Make handling of NULL by destructos consistent
All should accept a NULL and bail out, just like free().

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo db37185d16 dwarves: Use zfree()
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo 972001e58e dutil: Adopt zfree(), to use it more pervasively
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo 5847901abf dwarves: Plug leaks in cu__new() found by covscan
Error: GCC_ANALYZER_WARNING (CWE-401):
  dwarves-1.21/dwarves.c: scope_hint: In function 'cu__new'
  dwarves-1.21/dwarves.c:604:16: warning[-Wanalyzer-malloc-leak]: leak of '<unknown>'
  #  602|         }
  #  603|   out:
  #  604|->       return cu;
  #  605|   out_free_name:
  #  606|         free(cu->name);

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo 8772c9d827 dwarves: Accept NULL in cu__delete(), just like free() accepts
To facilitate error handling, where we would be checking for NULL in
multiple places.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo 674063b1ea loaders: Plug enumeration__delete() leak detected by covscan
Error: RESOURCE_LEAK (CWE-772):
  dwarves-1.21/btf_loader.c:293: alloc_fn: Storage is returned from allocation function "type__new".
  dwarves-1.21/btf_loader.c:293: var_assign: Assigning: "enumeration" = storage returned from "type__new(DW_TAG_enumeration_type, tp->name_off, ((*tp).size ? (*tp).size * 8U : 32UL))".
  dwarves-1.21/btf_loader.c:315: noescape: Resource "enumeration" is not freed or pointed-to in "enumeration__delete".
  dwarves-1.21/btf_loader.c:316: leaked_storage: Variable "enumeration" going out of scope leaks the storage it points to.
  #  314|   out_free:
  #  315|         enumeration__delete(enumeration, btfe->priv);
  #  316|->       return -ENOMEM;
  #  317|   }
  #  318|

  Error: RESOURCE_LEAK (CWE-772):
  dwarves-1.21/ctf_loader.c:398: alloc_fn: Storage is returned from allocation function "type__new".
  dwarves-1.21/ctf_loader.c:398: var_assign: Assigning: "enumeration" = storage returned from "type__new(DW_TAG_enumeration_type, ctf__get32(ctf, &tp->base.ctf_name), (size ?: 32UL))".
  dwarves-1.21/ctf_loader.c:421: noescape: Resource "enumeration" is not freed or pointed-to in "enumeration__delete".
  dwarves-1.21/ctf_loader.c:422: leaked_storage: Variable "enumeration" going out of scope leaks the storage it points to.
  #  420|   out_free:
  #  421|         enumeration__delete(enumeration, ctf->priv);
  #  422|->       return -ENOMEM;
  #  423|   }
  #  424|

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-17 16:47:34 -03:00