[10/12] libctf, include: add ctf_getsymsect and ctf_getstrsect

Message ID 20201025141413.363381-11-nick.alcock@oracle.com
State New
Headers show
  • CTF symbol functionality
Related show

Commit Message

H.J. Lu via Binutils Oct. 25, 2020, 2:14 p.m.
libctf has long provided ctf_getdatasect, which hands back a pointer to
the CTF section a (read-only) dict came from.  But it has no such
functions to return pointers to the ELF symbol table or string table
it's working from, which is unfortunate because several libctf functions
(ctf_open, ctf_fdopen, and ctf_bfdopen) figure out which string and
symbol table to use themselves, and don't tell the user what they
decided, so the caller can't agree on which symtab to use with libctf
even if it wanted to.

Add a pair of functions to return the symtab and strtab in use.  Like
ctf_getdatasect, these return ctf_sect_t structures by value, filled
with all-NULL/0 content if a symtab or strtab is not being used.

2020-10-23  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-api.h (ctf_getsymsect): New.
	(ctf_getstrsect): Likewise.

2020-10-23  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-open.c (ctf_getsymsect): New.
	(ctf_getstrsect): Likewise.
	* libctf.ver: Add them.
 include/ctf-api.h |  2 ++
 libctf/ctf-open.c | 12 ++++++++++++
 libctf/libctf.ver |  3 +++
 3 files changed, 17 insertions(+)



diff --git a/include/ctf-api.h b/include/ctf-api.h
index f0c00c01a89..8687475cc64 100644
--- a/include/ctf-api.h
+++ b/include/ctf-api.h
@@ -307,6 +307,8 @@  extern ctf_archive_t *ctf_open (const char *filename,
 				const char *target, int *errp);
 extern void ctf_close (ctf_archive_t *);
 extern ctf_sect_t ctf_getdatasect (const ctf_dict_t *);
+extern ctf_sect_t ctf_getsymsect (const ctf_dict_t *);
+extern ctf_sect_t ctf_getstrsect (const ctf_dict_t *);
 extern ctf_archive_t *ctf_get_arc (const ctf_dict_t *);
 extern ctf_archive_t *ctf_arc_open (const char *, int *);
 extern ctf_archive_t *ctf_arc_bufopen (const ctf_sect_t *,
diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c
index 3281c678ac4..ecf27eeeb21 100644
--- a/libctf/ctf-open.c
+++ b/libctf/ctf-open.c
@@ -1854,6 +1854,18 @@  ctf_getdatasect (const ctf_dict_t *fp)
   return fp->ctf_data;
+ctf_getsymsect (const ctf_dict_t *fp)
+  return fp->ctf_symtab;
+ctf_getstrsect (const ctf_dict_t *fp)
+  return fp->ctf_strtab;
 /* Return the CTF handle for the parent CTF dict, if one exists.  Otherwise
    return NULL to indicate this dict has no imported parent.  */
 ctf_dict_t *
diff --git a/libctf/libctf.ver b/libctf/libctf.ver
index f0633f26c4c..cfecc894350 100644
--- a/libctf/libctf.ver
+++ b/libctf/libctf.ver
@@ -190,4 +190,7 @@  LIBCTF_1.1 {
+	ctf_getsymsect;
+	ctf_getstrsect;
 } LIBCTF_1.0;