public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] ctf-reader: Add support for arbitrary CTF archive member as the CTF parent
@ 2024-07-16 18:17 claudiu.zissulescu-ianculescu
  2024-07-17 13:38 ` Dodji Seketeli
  0 siblings, 1 reply; 4+ messages in thread
From: claudiu.zissulescu-ianculescu @ 2024-07-16 18:17 UTC (permalink / raw)
  To: libabigail; +Cc: Claudiu Zissulescu

From: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>

If the CTF section contains ambiguously-defined types, it will consist
of an archive of many CTF dictionaries, all inheriting from one
dictionary containing unambiguous types.  This member is by default
named .ctf, like the section containing it, but it is possible to
change this name using the "ctf_link_set_memb_name_changer" function
at link time.  When looking at CTF archives that have been created by
a linker that uses the name changer to rename the parent archive
member, --ctf-parent can be used to specify the name used for the
parent.  This new option can be used with abidw, abidiff and
abipkgdiff tools.

	* include/abg-ctf-reader.h (parent_name): New function.
	* src/abg-ctf-reader.cc (ctf_parent_name): New variable.
	(ctf_parent_name): Sets ctf parent name.
	(parent_name): Gets the elf base reader and sets the parent name.
	* tools/abidiff.cc (ctf_parent): New option.
	(parse_command_line): Parse the new option.
	(main): Handle the new option.
	* tools/abidw.cc (ctf_parent): New option.
	(parse_command_line): Parse the new option.
	(load_corpus_and_write_abixml): Handle the new option.
	* tools/abipkgdiff.cc (ctf_parent): New option.
	(compare): Handle the new option.
	(compare_to_self): Likewise.
	(parse_command_line): Parse the new option.

Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
---
 include/abg-ctf-reader.h |  5 ++++-
 src/abg-ctf-reader.cc    | 25 +++++++++++++++++++++++++
 tools/abidiff.cc         | 27 +++++++++++++++++++++++++++
 tools/abidw.cc           | 19 +++++++++++++++++++
 tools/abipkgdiff.cc      | 38 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 113 insertions(+), 1 deletion(-)

diff --git a/include/abg-ctf-reader.h b/include/abg-ctf-reader.h
index c1f2a3f9..4e7f5a12 100644
--- a/include/abg-ctf-reader.h
+++ b/include/abg-ctf-reader.h
@@ -37,7 +37,10 @@ void
 reset_reader(elf_based_reader&		ctxt,
 	     const std::string&	elf_path,
 	     const vector<char**>&	debug_info_root_path);
+
+void
+parent_name(elf_based_reader& rdr,
+	    const std::string& parent_name);
 } // end namespace ctf_reader
 } // end namespace abigail
-
 #endif // ! __ABG_CTF_READER_H__
diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc
index 4b6c6cd8..6ee96265 100644
--- a/src/abg-ctf-reader.cc
+++ b/src/abg-ctf-reader.cc
@@ -156,6 +156,9 @@ class reader : public elf_based_reader
   ctf_sect_t strtab_sect;
   translation_unit_sptr cur_tu_;
 
+  ///CTF parent name.
+  std::string ctf_parent_name;
+
 public:
 
   /// Getter of the exported decls builder object.
@@ -464,6 +467,10 @@ public:
 
 	std::replace(dict_name.begin(), dict_name.end(), '-', '_');
       }
+    else
+      {
+	dict_name = ctf_parent_name;
+      }
 
     if ((ctf_dict = ctf_dict_open(ctfa,
 				  dict_name.empty() ? NULL : dict_name.c_str(),
@@ -745,6 +752,13 @@ public:
     return corp;
   }
 
+  /// Sets ctf_parent_name.
+  void
+  set_parent_name(const std::string& parent_name)
+  {
+    ctf_parent_name = parent_name;
+  }
+
   /// Destructor of the CTF reader.
   ~reader()
   {
@@ -1748,6 +1762,17 @@ reset_reader(elf_based_reader&		rdr,
   r.initialize(elf_path, debug_info_root_path);
 }
 
+/// Set a given parent name.
+///
+/// @param ctf_parent_name the custom ctf parent name.
+void
+parent_name(elf_based_reader& rdr,
+	    const std::string& parent_name)
+{
+  ctf::reader& r = dynamic_cast<reader&>(rdr);
+  r.set_parent_name(parent_name);
+}
+
 /// Returns a key to be use in types_map dict conformed by
 /// dictionary id and the CTF type id for a given type.
 ///
diff --git a/tools/abidiff.cc b/tools/abidiff.cc
index cadb742b..515b5128 100644
--- a/tools/abidiff.cc
+++ b/tools/abidiff.cc
@@ -134,6 +134,7 @@ struct options
 #endif
 #ifdef WITH_CTF
   bool			use_ctf;
+  string                ctf_parent;
 #endif
 #ifdef WITH_BTF
   bool			use_btf;
@@ -310,6 +311,7 @@ display_usage(const string& prog_name, ostream& out)
     <<  " --stats  show statistics about various internal stuff\n"
 #ifdef WITH_CTF
     << " --ctf use CTF instead of DWARF in ELF files\n"
+    << " --ctf-parent <name> set the CTF archive parent name\n"
 #endif
 #ifdef WITH_BTF
     << " --btf use BTF instead of DWARF in ELF files\n"
@@ -756,6 +758,14 @@ parse_command_line(int argc, char* argv[], options& opts)
 #ifdef WITH_CTF
       else if (!strcmp(argv[i], "--ctf"))
         opts.use_ctf = true;
+      else if (!strcmp(argv[i], "--ctf-parent"))
+	{
+	  int j = i + 1;
+	  if (j >= argc)
+	    return false;
+	  opts.ctf_parent = argv[j];
+	  ++i;
+	}
 #endif
 #ifdef WITH_BTF
       else if (!strcmp(argv[i], "--btf"))
@@ -1432,6 +1442,15 @@ main(int argc, char* argv[])
             ABG_ASSERT(rdr);
 	    set_generic_options(*rdr, opts);
 	    set_suppressions(*rdr, opts);
+
+#ifdef WITH_CTF
+	    // If the user sets the ctf parent make sure we propagate it.
+	    if (!opts.ctf_parent.empty()
+		&& opts.use_ctf)
+	      {
+		abigail::ctf::parent_name(*rdr, opts.ctf_parent);
+	      }
+#endif
 	    c1 = rdr->read_corpus(c1_status);
 
 	    if (!c1
@@ -1524,6 +1543,14 @@ main(int argc, char* argv[])
 	    set_generic_options(*rdr, opts);
 	    set_suppressions(*rdr, opts);
 
+#ifdef WITH_CTF
+	    // If the user sets the ctf parent make sure we propagate it.
+	    if (!opts.ctf_parent.empty()
+		&& opts.use_ctf)
+	      {
+		abigail::ctf::parent_name(*rdr, opts.ctf_parent);
+	      }
+#endif
 	    c2 = rdr->read_corpus(c2_status);
 
 	    if (!c2
diff --git a/tools/abidw.cc b/tools/abidw.cc
index 14f2078c..41909512 100644
--- a/tools/abidw.cc
+++ b/tools/abidw.cc
@@ -118,6 +118,7 @@ struct options
   bool			list_dependencies;
 #ifdef WITH_CTF
   bool			use_ctf;
+  string                ctf_parent;
 #endif
 #ifdef WITH_BTF
   bool			use_btf;
@@ -261,6 +262,7 @@ display_usage(const string& prog_name, ostream& out)
 #endif
 #ifdef WITH_CTF
     << "  --ctf use CTF instead of DWARF in ELF files\n"
+    << "  --ctf-parent <name> set the CTF archive parent name\n"
 #endif
     << "  --no-leverage-dwarf-factorization  do not use DWZ optimisations to "
     "speed-up the analysis of the binary\n"
@@ -402,6 +404,14 @@ parse_command_line(int argc, char* argv[], options& opts)
 #ifdef WITH_CTF
         else if (!strcmp(argv[i], "--ctf"))
           opts.use_ctf = true;
+        else if (!strcmp(argv[i], "--ctf-parent"))
+	  {
+	    int j = i + 1;
+	    if (j >= argc)
+	      return false;
+	    opts.ctf_parent = argv[j];
+	    ++i;
+	  }
 #endif
 #ifdef WITH_BTF
         else if (!strcmp(argv[i], "--btf"))
@@ -683,6 +693,15 @@ load_corpus_and_write_abixml(char* argv[],
   set_generic_options(*reader, opts);
   set_suppressions(*reader, opts);
 
+#ifdef WITH_CTF
+  // If the user sets the ctf parent make sure we propagate it.
+  if (!opts.ctf_parent.empty()
+      && opts.use_ctf)
+    {
+      abigail::ctf::parent_name(*reader, opts.ctf_parent);
+    }
+#endif
+
   // If the user asked us to check if we found the "alternate debug
   // info file" associated to the input binary, then proceed to do so
   // ...
diff --git a/tools/abipkgdiff.cc b/tools/abipkgdiff.cc
index d1ddd341..0d6a1fb2 100644
--- a/tools/abipkgdiff.cc
+++ b/tools/abipkgdiff.cc
@@ -214,6 +214,7 @@ public:
   optional<bool> exported_interfaces_only;
 #ifdef WITH_CTF
   bool		use_ctf;
+  string        ctf_parent;
 #endif
 #ifdef WITH_BTF
   bool		use_btf;
@@ -922,6 +923,7 @@ display_usage(const string& prog_name, ostream& out)
     "binaries inside the input package against their ABIXML representation\n"
 #ifdef WITH_CTF
     << " --ctf                          use CTF instead of DWARF in ELF files\n"
+    << " --ctf-parent <name>            set the CTF archive parent name\n"
 #endif
 #ifdef WITH_BTF
     << " --btf                          use BTF instead of DWARF in ELF files\n"
@@ -1486,6 +1488,15 @@ compare(const elf_file&		elf1,
     reader->add_suppressions(supprs);
     set_generic_options(*reader, opts);
 
+#ifdef WITH_CTF
+    // If the user sets the ctf parent make sure we propagate it.
+    if (!opts.ctf_parent.empty()
+	&& opts.use_ctf)
+      {
+	abigail::ctf::parent_name(*reader, opts.ctf_parent);
+      }
+#endif
+
     corpus1 = reader->read_corpus(c1_status);
 
     bool bail_out = false;
@@ -1575,6 +1586,16 @@ compare(const elf_file&		elf1,
     reader->add_suppressions(priv_types_supprs2);
     set_generic_options(*reader, opts);
 
+#ifdef WITH_CTF
+    // If the user sets the ctf parent make sure we propagate it.
+    // Note: Do we need to have sparate parents per package?
+    if (!opts.ctf_parent.empty()
+	&& opts.use_ctf)
+      {
+	abigail::ctf::parent_name(*reader, opts.ctf_parent);
+      }
+#endif
+
     corpus2 = reader->read_corpus(c2_status);
 
     bool bail_out = false;
@@ -1741,6 +1762,15 @@ compare_to_self(const elf_file&		elf,
     reader->add_suppressions(supprs);
     corp = reader->read_corpus(c_status);
 
+#ifdef WITH_CTF
+    // If the user sets the ctf parent make sure we propagate it.
+    if (!opts.ctf_parent.empty()
+	&& opts.use_ctf)
+      {
+	abigail::ctf::parent_name(*reader, opts.ctf_parent);
+      }
+#endif
+
     if (!(c_status & abigail::fe_iface::STATUS_OK))
       {
 	if (opts.verbose)
@@ -3631,6 +3661,14 @@ parse_command_line(int argc, char* argv[], options& opts)
 #ifdef WITH_CTF
 	else if (!strcmp(argv[i], "--ctf"))
           opts.use_ctf = true;
+        else if (!strcmp(argv[i], "--ctf-parent"))
+	  {
+	    int j = i + 1;
+	    if (j >= argc)
+	      return false;
+	    opts.ctf_parent = argv[j];
+	    ++i;
+	  }
 #endif
 #ifdef WITH_BTF
 	else if (!strcmp(argv[i], "--btf"))
-- 
2.45.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-08  9:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-16 18:17 [PATCH] ctf-reader: Add support for arbitrary CTF archive member as the CTF parent claudiu.zissulescu-ianculescu
2024-07-17 13:38 ` Dodji Seketeli
2024-07-23 13:26   ` claudiu.zissulescu-ianculescu
2024-08-08  9:38     ` Dodji Seketeli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).