libctf, include, binutils, gdb: rename CTF-opening functions
authorNick Alcock <nick.alcock@oracle.com>
Fri, 20 Nov 2020 13:34:04 +0000 (13:34 +0000)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 20 Nov 2020 13:34:05 +0000 (13:34 +0000)
The functions that return ctf_dict_t's given a ctf_archive_t and a name
are very clumsily named.  It sounds like they return *archives*, not
dictionaries, and the names are very long and clunky.  Why do we
have a ctf_arc_open_by_name when it opens a dictionary, not an archive,
and when there is no way to open a dictionary in any other way?  The
answer is purely internal: the function is located in ctf-archive.c,
and everything in there was called ctf_arc_*, and there is another
way to open a dict (by offset in the archive), that is internal to
ctf-archive.c and that nothing else can call.

This is clearly bad naming. The internal organization of the source tree
should not dictate public API names!

So rename things (keeping the old, bad names for compatibility), and
adjust all users.  You now open a dict using ctf_dict_open, and
open it giving ELF sections via ctf_dict_open_sections.

binutils/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* objdump.c (dump_ctf): Use ctf_dict_open, not
ctf_arc_open_by_name.
* readelf.c (dump_section_as_ctf): Likewise.

gdb/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctfread.c (elfctf_build_psymtabs): Use ctf_dict_open, not
ctf_arc_open_by_name.

include/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-api.h (ctf_arc_open_by_name): Rename to...
(ctf_dict_open): ... this, keeping compatibility function.
(ctf_arc_open_by_name_sections): Rename to...
(ctf_dict_open_sections): ... this, keeping compatibility function.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

* ctf-archive.c (ctf_arc_open_by_offset): Rename to...
(ctf_dict_open_by_offset): ... this.  Adjust callers.
(ctf_arc_open_by_name_internal): Rename to...
(ctf_dict_open_internal): ... this.  Adjust callers.
(ctf_arc_open_by_name_sections): Rename to...
(ctf_dict_open_sections): ... this, keeping compatibility function.
(ctf_arc_open_by_name): Rename to...
(ctf_dict_open): ... this, keeping compatibility function.
* libctf.ver: New functions added.
* ctf-link.c (ctf_link_one_input_archive): Adjusted accordingly.
(ctf_link_deduplicating_open_inputs): Likewise.

binutils/ChangeLog
binutils/objdump.c
binutils/readelf.c
gdb/ChangeLog
gdb/ctfread.c
include/ChangeLog
include/ctf-api.h
libctf/ChangeLog
libctf/ctf-archive.c
libctf/ctf-link.c
libctf/libctf.ver

index e1a5a3d10cf8d5e81d9e92b7ff395d7b095be84f..8b7cba02859bf11ccf29762332495410f3601666 100644 (file)
@@ -1,3 +1,9 @@
+2020-11-20  Nick Alcock  <nick.alcock@oracle.com>
+
+       * objdump.c (dump_ctf): Use ctf_dict_open, not
+       ctf_arc_open_by_name.
+       * readelf.c (dump_section_as_ctf): Likewise.
+
 2020-11-20  Nick Alcock  <nick.alcock@oracle.com>
 
        * objdump.c (dump_ctf_errs): Rename ctf_file_t to ctf_dict_t.
index 54f4081d1c92ed4328a0726b38badf39a4e97ad3..bf8234987f02ed4276d7c739e34277b0f4f80007 100644 (file)
@@ -4194,7 +4194,7 @@ dump_ctf (bfd *abfd, const char *sect_name, const char *parent_name)
   /* Assume that the applicable parent archive member is the default one.
      (This is what all known implementations are expected to do, if they
      put CTFs and their parents in archives together.)  */
-  if ((parent = ctf_arc_open_by_name (lookparent, NULL, &err)) == NULL)
+  if ((parent = ctf_dict_open (lookparent, NULL, &err)) == NULL)
     {
       dump_ctf_errs (NULL);
       non_fatal (_("CTF open failure: %s"), ctf_errmsg (err));
index e3b9f6f4d709e80eaea564ec2ee141652ffe008f..a79f29548a1bab8e9fe90688c05d007071af5596 100644 (file)
@@ -14775,7 +14775,7 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata)
   /* Assume that the applicable parent archive member is the default one.
      (This is what all known implementations are expected to do, if they
      put CTFs and their parents in archives together.)  */
-  if ((parent = ctf_arc_open_by_name (lookparent, NULL, &err)) == NULL)
+  if ((parent = ctf_dict_open (lookparent, NULL, &err)) == NULL)
     {
       dump_ctf_errs (NULL);
       error (_("CTF open failure: %s\n"), ctf_errmsg (err));
index 3eaadddb6241ab1712eab7e452f2fdd089f539a8..0fb0997779bc488569b7cc84e7bb1a39d718691e 100644 (file)
@@ -1,3 +1,8 @@
+2020-11-20  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctfread.c (elfctf_build_psymtabs): Use ctf_dict_open, not
+       ctf_arc_open_by_name.
+
 2020-11-20  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctfread.c: Change uses of ctf_file_t to ctf_dict_t.
index dd401efcb7266965eed921d8c3163c777696e414..d532e01a0e6057f873c4d0aeb2d6e26794bf1439 100644 (file)
@@ -1482,9 +1482,9 @@ elfctf_build_psymtabs (struct objfile *of)
     error (_("ctf_bfdopen failed on %s - %s"),
           bfd_get_filename (abfd), ctf_errmsg (err));
 
-  ctf_dict_t *fp = ctf_arc_open_by_name (arc, NULL, &err);
+  ctf_dict_t *fp = ctf_dict_open (arc, NULL, &err);
   if (fp == NULL)
-    error (_("ctf_arc_open_by_name failed on %s - %s"),
+    error (_("ctf_dict_open failed on %s - %s"),
           bfd_get_filename (abfd), ctf_errmsg (err));
   ctf_dict_key.emplace (of, fp);
 
index e1fcc928369f3fe20082a14725c5ecacb1e1faad..11ec1f4c712400cbf101c2c7d297d4a7112e2f83 100644 (file)
@@ -1,3 +1,10 @@
+2020-11-20  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-api.h (ctf_arc_open_by_name): Rename to...
+       (ctf_dict_open): ... this, keeping compatibility function.
+       (ctf_arc_open_by_name_sections): Rename to...
+       (ctf_dict_open_sections): ... this, keeping compatibility function.
+
 2020-11-20  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-api.h (ctf_file_t): Rename to...
index 60e06b39ee7064be605f7ba4b6bfddf097504cdd..38d7758a48e635d2193cece93e6ad8d14fe717b0 100644 (file)
@@ -306,12 +306,12 @@ extern ctf_archive_t *ctf_arc_bufopen (const ctf_sect_t *,
                                       const ctf_sect_t *,
                                       int *);
 extern void ctf_arc_close (ctf_archive_t *);
-extern ctf_dict_t *ctf_arc_open_by_name (const ctf_archive_t *,
-                                        const char *, int *);
-extern ctf_dict_t *ctf_arc_open_by_name_sections (const ctf_archive_t *,
-                                                 const ctf_sect_t *,
-                                                 const ctf_sect_t *,
-                                                 const char *, int *);
+extern ctf_dict_t *ctf_dict_open (const ctf_archive_t *,
+                                 const char *, int *);
+extern ctf_dict_t *ctf_dict_open_sections (const ctf_archive_t *,
+                                          const ctf_sect_t *,
+                                          const ctf_sect_t *,
+                                          const char *, int *);
 extern size_t ctf_archive_count (const ctf_archive_t *);
 
 /* The next functions return or close real CTF files, or write out CTF archives,
@@ -511,6 +511,12 @@ struct ctf_file;
 typedef struct ctf_dict ctf_file_t;
 extern void ctf_file_close (ctf_file_t *);
 extern ctf_dict_t *ctf_parent_file (ctf_dict_t *);
+extern ctf_dict_t *ctf_arc_open_by_name (const ctf_archive_t *,
+                                        const char *, int *);
+extern ctf_dict_t *ctf_arc_open_by_name_sections (const ctf_archive_t *,
+                                                 const ctf_sect_t *,
+                                                 const ctf_sect_t *,
+                                                 const char *, int *);
 
 #ifdef __cplusplus
 }
index 71a8e53384cd2970e54b92dec11af4ff438cd8fb..804f1314af25b2cd1bcce15d8f61d8abcf061753 100644 (file)
@@ -1,3 +1,17 @@
+2020-11-20  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-archive.c (ctf_arc_open_by_offset): Rename to...
+       (ctf_dict_open_by_offset): ... this.  Adjust callers.
+       (ctf_arc_open_by_name_internal): Rename to...
+       (ctf_dict_open_internal): ... this.  Adjust callers.
+       (ctf_arc_open_by_name_sections): Rename to...
+       (ctf_dict_open_sections): ... this, keeping compatibility function.
+       (ctf_arc_open_by_name): Rename to...
+       (ctf_dict_open): ... this, keeping compatibility function.
+       * libctf.ver: New functions added.
+       * ctf-link.c (ctf_link_one_input_archive): Adjusted accordingly.
+       (ctf_link_deduplicating_open_inputs): Likewise.
+
 2020-11-20  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-impl.h: Rename ctf_file_t to ctf_dict_t: all declarations
index 90780da38340f9690792a1ce74c68f3316bad92c..72cdef91ac4e53f89f017f531e29d182c4adf024 100644 (file)
 #endif
 
 static off_t arc_write_one_ctf (ctf_dict_t * f, int fd, size_t threshold);
-static ctf_dict_t *ctf_arc_open_by_offset (const struct ctf_archive *arc,
-                                          const ctf_sect_t *symsect,
-                                          const ctf_sect_t *strsect,
-                                          size_t offset, int *errp);
+static ctf_dict_t *ctf_dict_open_by_offset (const struct ctf_archive *arc,
+                                           const ctf_sect_t *symsect,
+                                           const ctf_sect_t *strsect,
+                                           size_t offset, int *errp);
 static int sort_modent_by_name (const void *one, const void *two, void *n);
 static void *arc_mmap_header (int fd, size_t headersz);
 static void *arc_mmap_file (int fd, size_t size);
@@ -506,10 +506,10 @@ ctf_arc_close (ctf_archive_t *arc)
 /* Return the ctf_dict_t with the given name, or NULL if none, setting 'err' if
    non-NULL.  A name of NULL means to open the default file.  */
 static ctf_dict_t *
-ctf_arc_open_by_name_internal (const struct ctf_archive *arc,
-                              const ctf_sect_t *symsect,
-                              const ctf_sect_t *strsect,
-                              const char *name, int *errp)
+ctf_dict_open_internal (const struct ctf_archive *arc,
+                       const ctf_sect_t *symsect,
+                       const ctf_sect_t *strsect,
+                       const char *name, int *errp)
 {
   struct ctf_archive_modent *modent;
   const char *search_nametbl;
@@ -517,7 +517,7 @@ ctf_arc_open_by_name_internal (const struct ctf_archive *arc,
   if (name == NULL)
     name = _CTF_SECTION;                /* The default name.  */
 
-  ctf_dprintf ("ctf_arc_open_by_name(%s): opening\n", name);
+  ctf_dprintf ("ctf_dict_open_internal(%s): opening\n", name);
 
   modent = (ctf_archive_modent_t *) ((char *) arc
                                     + sizeof (struct ctf_archive));
@@ -536,8 +536,8 @@ ctf_arc_open_by_name_internal (const struct ctf_archive *arc,
       return NULL;
     }
 
-  return ctf_arc_open_by_offset (arc, symsect, strsect,
-                                le64toh (modent->ctf_offset), errp);
+  return ctf_dict_open_by_offset (arc, symsect, strsect,
+                                 le64toh (modent->ctf_offset), errp);
 }
 
 /* Return the ctf_dict_t with the given name, or NULL if none, setting 'err' if
@@ -547,17 +547,17 @@ ctf_arc_open_by_name_internal (const struct ctf_archive *arc,
 
    Public entry point.  */
 ctf_dict_t *
-ctf_arc_open_by_name_sections (const ctf_archive_t *arc,
-                              const ctf_sect_t *symsect,
-                              const ctf_sect_t *strsect,
-                              const char *name,
-                              int *errp)
+ctf_dict_open_sections (const ctf_archive_t *arc,
+                       const ctf_sect_t *symsect,
+                       const ctf_sect_t *strsect,
+                       const char *name,
+                       int *errp)
 {
   if (arc->ctfi_is_archive)
     {
       ctf_dict_t *ret;
-      ret = ctf_arc_open_by_name_internal (arc->ctfi_archive, symsect, strsect,
-                                          name, errp);
+      ret = ctf_dict_open_internal (arc->ctfi_archive, symsect, strsect,
+                                   name, errp);
       if (ret)
        ret->ctf_archive = (ctf_archive_t *) arc;
       return ret;
@@ -581,7 +581,7 @@ ctf_arc_open_by_name_sections (const ctf_archive_t *arc,
 
    Public entry point.  */
 ctf_dict_t *
-ctf_arc_open_by_name (const ctf_archive_t *arc, const char *name, int *errp)
+ctf_dict_open (const ctf_archive_t *arc, const char *name, int *errp)
 {
   const ctf_sect_t *symsect = &arc->ctfi_symsect;
   const ctf_sect_t *strsect = &arc->ctfi_strsect;
@@ -591,21 +591,21 @@ ctf_arc_open_by_name (const ctf_archive_t *arc, const char *name, int *errp)
   if (strsect->cts_name == NULL)
     strsect = NULL;
 
-  return ctf_arc_open_by_name_sections (arc, symsect, strsect, name, errp);
+  return ctf_dict_open_sections (arc, symsect, strsect, name, errp);
 }
 
 /* Return the ctf_dict_t at the given ctfa_ctfs-relative offset, or NULL if
    none, setting 'err' if non-NULL.  */
 static ctf_dict_t *
-ctf_arc_open_by_offset (const struct ctf_archive *arc,
-                       const ctf_sect_t *symsect,
-                       const ctf_sect_t *strsect, size_t offset,
-                       int *errp)
+ctf_dict_open_by_offset (const struct ctf_archive *arc,
+                        const ctf_sect_t *symsect,
+                        const ctf_sect_t *strsect, size_t offset,
+                        int *errp)
 {
   ctf_sect_t ctfsect;
   ctf_dict_t *fp;
 
-  ctf_dprintf ("ctf_arc_open_by_offset(%lu): opening\n", (unsigned long) offset);
+  ctf_dprintf ("ctf_dict_open_by_offset(%lu): opening\n", (unsigned long) offset);
 
   memset (&ctfsect, 0, sizeof (ctf_sect_t));
 
@@ -621,6 +621,24 @@ ctf_arc_open_by_offset (const struct ctf_archive *arc,
   return fp;
 }
 
+/* Backward compatibility.  */
+ctf_dict_t *
+ctf_arc_open_by_name (const ctf_archive_t *arc, const char *name,
+                     int *errp)
+{
+  return ctf_dict_open (arc, name, errp);
+}
+
+ctf_dict_t *
+ctf_arc_open_by_name_sections (const ctf_archive_t *arc,
+                              const ctf_sect_t *symsect,
+                              const ctf_sect_t *strsect,
+                              const char *name,
+                              int *errp)
+{
+  return ctf_dict_open_sections (arc, symsect, strsect, name, errp);
+}
+
 /* Return the number of members in an archive.  */
 size_t
 ctf_archive_count (const ctf_archive_t *wrapper)
@@ -699,8 +717,8 @@ ctf_archive_iter_internal (const ctf_archive_t *wrapper,
       const char *name;
 
       name = &nametbl[le64toh (modent[i].name_offset)];
-      if ((f = ctf_arc_open_by_name_internal (arc, symsect, strsect,
-                                             name, &rc)) == NULL)
+      if ((f = ctf_dict_open_internal (arc, symsect, strsect,
+                                   name, &rc)) == NULL)
        return rc;
 
       f->ctf_archive = (ctf_archive_t *) wrapper;
@@ -837,8 +855,7 @@ ctf_archive_next (const ctf_archive_t *wrapper, ctf_next_t **it, const char **na
   if (name)
     *name = name_;
 
-  f = ctf_arc_open_by_name_internal (arc, symsect, strsect,
-                                    name_, errp);
+  f = ctf_dict_open_internal (arc, symsect, strsect, name_, errp);
   f->ctf_archive = (ctf_archive_t *) wrapper;
   return f;
 }
index c3801e6f3cbfe8ca1887e6e1fc59261ac95c1082..192d4fd662213ea163e5fd144de9520534e8fc92 100644 (file)
@@ -789,8 +789,8 @@ ctf_link_one_input_archive (void *key, void *value, void *arg_)
 
   arg->in_file_name = file_name;
   arg->done_parent = 0;
-  if ((arg->in_fp_parent = ctf_arc_open_by_name (input->clin_arc, NULL,
-                                                &err)) == NULL)
+  if ((arg->in_fp_parent = ctf_dict_open (input->clin_arc,
+                                         NULL, &err)) == NULL)
     if (err != ECTF_ARNNAME)
       {
        ctf_err_warn (arg->out_fp, 1, 0,
@@ -1015,8 +1015,8 @@ ctf_link_deduplicating_open_inputs (ctf_dict_t *fp, ctf_dynhash_t *cu_names,
         multiple members.  We assume, as elsewhere, that the parent is named
         _CTF_SECTION.  */
 
-      if ((parent_fp = ctf_arc_open_by_name (one_input->clin_arc,
-                                            _CTF_SECTION, &err)) == NULL)
+      if ((parent_fp = ctf_dict_open (one_input->clin_arc, _CTF_SECTION,
+                                     &err)) == NULL)
        {
          if (err != ECTF_NOMEMBNAM)
            {
index 5f5dc57885de8850097e60a86cd6ceb6291fb55d..cf4fa7396b52e102c3919a29fe9bb41dcd77630d 100644 (file)
@@ -177,6 +177,8 @@ LIBCTF_1.0 {
 
 LIBCTF_1.1 {
     global:
+       ctf_dict_open;
+       ctf_dict_open_sections;
        ctf_dict_close;
        ctf_parent_dict;
 } LIBCTF_1.0;