From patchwork Tue Apr 21 12:28:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 39118 From: mark@klomp.org (Mark J. Wielaard) Date: Tue, 21 Apr 2020 14:28:20 +0200 Subject: [PATCH 3/4] Add --no-elf-needed option to drop DT_NEEDED list from corpus. In-Reply-To: <20200421122821.13769-1-mark@klomp.org> References: <20200421122821.13769-1-mark@klomp.org> Message-ID: <20200421122821.13769-4-mark@klomp.org> From: Mark Wielaard The elf-needed list is not relevant for the exported ABI of a library so provide an option to drop it. * doc/manuals/abidw.rst: Document --no-elf-needed. * include/abg-writer.h (set_write_elf_needed): New function. (set_common_options): Call it. * src/abg-writer.cc (write_context): Add m_write_elf_needed bool, get_write_elf_needed and set_write_elf_needed methods. (set_write_elf_needed): New function. (write_context::write_corpus): Check write_elf_needed. * tools/abidw.cc (options): Add write_elf_needed bool. (display_usage): Describe --no-elf-needed. (parse_command_line): Parse --no-elf-needed. Signed-off-by: Mark Wielaard --- doc/manuals/abidw.rst | 5 +++++ include/abg-writer.h | 4 ++++ src/abg-writer.cc | 30 +++++++++++++++++++++++++++++- tools/abidw.cc | 5 +++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/doc/manuals/abidw.rst b/doc/manuals/abidw.rst index dd72d149..7ae44737 100644 --- a/doc/manuals/abidw.rst +++ b/doc/manuals/abidw.rst @@ -146,6 +146,11 @@ Options representation build by Libabigail to represent the ABI and will not end up in the abi XML file. + * ``--no-elf-needed`` + + Do not include the list of DT_NEEDED dependency names in the + corpus. + * ``--drop-undefined-syms`` With this option functions or variables for which the (exported) diff --git a/include/abg-writer.h b/include/abg-writer.h index 71b7efe6..bece11e6 100644 --- a/include/abg-writer.h +++ b/include/abg-writer.h @@ -62,6 +62,9 @@ set_write_corpus_path(write_context& ctxt, bool flag); void set_write_comp_dir(write_context& ctxt, bool flag); +void +set_write_elf_needed(write_context& ctxt, bool flag); + void set_short_locs(write_context& ctxt, bool flag); @@ -89,6 +92,7 @@ set_common_options(write_context& ctxt, const OPTS& opts) set_write_architecture(ctxt, opts.write_architecture); set_write_corpus_path(ctxt, opts.write_corpus_path); set_write_comp_dir(ctxt, opts.write_comp_dir); + set_write_elf_needed(ctxt, opts.write_elf_needed); set_write_parameter_names(ctxt, opts.write_parameter_names); set_short_locs(ctxt, opts.short_locs); set_named_type_ids(ctxt, opts.named_type_ids); diff --git a/src/abg-writer.cc b/src/abg-writer.cc index 6c57166f..ccfb3f63 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -221,6 +221,7 @@ class write_context bool m_write_architecture; bool m_write_corpus_path; bool m_write_comp_dir; + bool m_write_elf_needed; bool m_write_parameter_names; bool m_short_locs; bool m_named_type_ids; @@ -258,6 +259,7 @@ public: m_write_architecture(true), m_write_corpus_path(true), m_write_comp_dir(true), + m_write_elf_needed(true), m_write_parameter_names(true), m_short_locs(false), m_named_type_ids(false) @@ -316,6 +318,20 @@ public: set_write_architecture(bool f) {m_write_architecture = f;} + /// Getter of the elf-needed option. + /// + /// @return true iff elf needed information shall be emitted + bool + get_write_elf_needed() + {return m_write_elf_needed;} + + /// Setter of the elf-needed option. + /// + /// @param f the new value of the flag. + void + set_write_elf_needed(bool f) + {m_write_elf_needed = f;} + /// Getter of the write-corpus-path option. /// /// @return true iff corpus-path information shall be emitted @@ -2140,6 +2156,18 @@ void set_write_parameter_names(write_context& ctxt, bool flag) {ctxt.set_write_parameter_names(flag);} +/// Set the 'elf-needed' flag. +/// +/// When this flag is set then the XML writer will emit corpus +/// get_needed() (DT_NEEDED) information. +/// +/// @param ctxt the context to set this flag on to. +/// +/// @param flag the new value of the 'elf-needed' flag. +void +set_write_elf_needed(write_context& ctxt, bool flag) +{ctxt.set_write_elf_needed(flag);} + /// Serialize the canonical types of a given scope. /// /// @param scope the scope to consider. @@ -4529,7 +4557,7 @@ write_corpus(write_context& ctxt, // Write the list of needed corpora. - if (!corpus->get_needed().empty()) + if (ctxt.get_write_elf_needed () && !corpus->get_needed().empty()) { do_indent_to_level(ctxt, indent, 1); out << "\n"; diff --git a/tools/abidw.cc b/tools/abidw.cc index 510a0707..3f4b3f42 100644 --- a/tools/abidw.cc +++ b/tools/abidw.cc @@ -99,6 +99,7 @@ struct options bool write_architecture; bool write_corpus_path; bool write_comp_dir; + bool write_elf_needed; bool write_parameter_names; bool short_locs; bool load_all_types; @@ -121,6 +122,7 @@ struct options write_architecture(true), write_corpus_path(true), write_comp_dir(true), + write_elf_needed(true), write_parameter_names(true), short_locs(false), load_all_types(), @@ -170,6 +172,7 @@ display_usage(const string& prog_name, ostream& out) << " --drop-undefined-syms drop undefined symbols from representation\n" << " --named_type-ids use id attributes based on type names in XML file\n" << " --no-comp-dir-path do not show compilation path information\n" + << " --no-elf-needed do not show the DT_NEEDED information\n" << " --no-parameter-names do not show names of function parameters\n" << " --check-alternate-debug-info check alternate debug info " "of \n" @@ -291,6 +294,8 @@ parse_command_line(int argc, char* argv[], options& opts) opts.short_locs = true; else if (!strcmp(argv[i], "--no-comp-dir-path")) opts.write_comp_dir = false; + else if (!strcmp(argv[i], "--no-elf-needed")) + opts.write_elf_needed = false; else if (!strcmp(argv[i], "--no-parameter-names")) opts.write_parameter_names = false; else if (!strcmp(argv[i], "--check-alternate-debug-info")