[16/22] libctf: make ctf_lookup of symbols by name work in more cases

Message ID 20240417202018.34966-17-nick.alcock@oracle.com
State New
Series more modifiable CTF dicts (and a few bugfixes) |


Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Testing passed

Commit Message

Nick Alcock April 17, 2024, 8:20 p.m. UTC
  In particular, we don't need a symbol table if we're looking up a
symbol by name and that type of symbol has an indexed symtypetab,
since in that case we get the name from the symtypetab index, not
from the symbol table.

This lets you do symbol lookups in unlinked object files and unlinked
dicts written out via libctf's writeout functions.


	* ctf-lookup.c (ctf_lookup_by_sym_or_name): Allow lookups
	by index even when there is no symtab.
 libctf/ctf-lookup.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)


diff --git a/libctf/ctf-lookup.c b/libctf/ctf-lookup.c
index aa251bafb89..f37dd7e45ce 100644
--- a/libctf/ctf-lookup.c
+++ b/libctf/ctf-lookup.c
@@ -1045,7 +1045,9 @@  ctf_lookup_by_sym_or_name (ctf_dict_t *fp, unsigned long symidx,
-  if (sp->cts_data == NULL)
+  if (sp->cts_data == NULL && symname == NULL &&
+      ((is_function && !fp->ctf_funcidx_names) ||
+       (!is_function && !fp->ctf_objtidx_names)))
     goto try_parent;
   /* This covers both out-of-range lookups by index and a dynamic dict which