libabigail
abg-corpus.cc
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2// -*- mode: C++ -*-
3//
4// Copyright (C) 2013-2023 Red Hat, Inc.
5
6/// @file
7
8#include "config.h"
9
10#include <algorithm>
11#include <cassert>
12#include <cstdio>
13#include <cstring>
14#include <stdexcept>
15#include <unordered_map>
16#include <set>
17
18#include "abg-internal.h"
19
20// <headers defining libabigail's API go under here>
21ABG_BEGIN_EXPORT_DECLARATIONS
22
23#include "abg-corpus.h"
24#include "abg-ir.h"
25#include "abg-reader.h"
26#include "abg-sptr-utils.h"
27#include "abg-symtab-reader.h"
28#include "abg-tools-utils.h"
29#include "abg-writer.h"
30
31ABG_END_EXPORT_DECLARATIONS
32// </headers defining libabigail's API>
33
34#include "abg-corpus-priv.h"
35#include "abg-ir-priv.h"
36
37namespace abigail
38{
39
40namespace ir
41{
42
43using std::ostringstream;
44using std::unordered_map;
45using std::list;
46using std::vector;
47
49
50/// Constructor of @ref corpus::exported_decls_builder.
51///
52/// @param fns a reference to the vector of exported functions.
53///
54/// @param vars a reference to the vector of exported variables.
55///
56/// @param fns_suppress_regexps the regular expressions that designate
57/// the functions to suppress from the exported functions set.
58///
59/// @param vars_suppress_regexps the regular expressions that designate
60/// the variables to suppress from the exported variables set.
61///
62/// @param fns_keep_regexps the regular expressions that designate the
63/// functions to keep in the exported functions set.
64///
65/// @param fns_keep_regexps the regular expressions that designate the
66/// functions to keep in the exported functions set.
67///
68/// @param vars_keep_regexps the regular expressions that designate
69/// the variables to keep in the exported variables set.
70///
71/// @param sym_id_of_fns_to_keep the IDs of the functions to keep in
72/// the exported functions set.
73///
74/// @param sym_id_of_vars_to_keep the IDs of the variables to keep in
75/// the exported variables set.
76corpus::exported_decls_builder
77::exported_decls_builder(functions& fns,
78 variables& vars,
79 strings_type& fns_suppress_regexps,
80 strings_type& vars_suppress_regexps,
81 strings_type& fns_keep_regexps,
82 strings_type& vars_keep_regexps,
83 strings_type& sym_id_of_fns_to_keep,
84 strings_type& sym_id_of_vars_to_keep)
85 : priv_(new priv(fns, vars,
86 fns_suppress_regexps,
87 vars_suppress_regexps,
88 fns_keep_regexps,
89 vars_keep_regexps,
90 sym_id_of_fns_to_keep,
91 sym_id_of_vars_to_keep))
92{
93}
94
95/// Getter for the reference to the vector of exported functions.
96/// This vector is shared with with the @ref corpus. It's where the
97/// set of exported function is ultimately stored.
98///
99/// @return a reference to the vector of exported functions.
102{return priv_->fns_;}
103
104/// Getter for the reference to the vector of exported functions.
105/// This vector is shared with with the @ref corpus. It's where the
106/// set of exported function is ultimately stored.
107///
108/// @return a reference to the vector of exported functions.
111{return priv_->fns_;}
112
113/// Test if a given function ID maps to several functions in the same corpus.
114///
115/// The magic of ELF symbol aliases makes it possible for an ELF
116/// symbol alias to designate several different functions. This
117/// function tests if the ELF symbol of a given function has a aliases
118/// that designates another function or not.
119///
120/// @param fn the function to consider.
121///
122/// @return the set of functions designated by the ELF symbol of @p
123/// fn, or nullptr if the function ID maps to just @p fn.
124std::unordered_set<function_decl*>*
126{
127 std::unordered_set<function_decl*> *fns_for_id =
128 priv_->fn_id_is_in_id_fns_map(fn);
129 if (fns_for_id && fns_for_id->size() > 1)
130 return fns_for_id;
131
132 return nullptr;
133}
134
135/// Getter for the reference to the vector of exported variables.
136/// This vector is shared with with the @ref corpus. It's where the
137/// set of exported variable is ultimately stored.
138///
139/// @return a reference to the vector of exported variables.
142{return priv_->vars_;}
143
144/// Getter for the reference to the vector of exported variables.
145/// This vector is shared with with the @ref corpus. It's where the
146/// set of exported variable is ultimately stored.
147///
148/// @return a reference to the vector of exported variables.
151{return priv_->vars_;}
152
153/// Consider at all the tunables that control wether a function should
154/// be added to the set of exported function and if it fits in, add
155/// the function to that set.
156///
157/// @param fn the function to add the set of exported functions.
158void
160{
162 return;
163
164 const string& fn_id = priv_->get_id(*fn);
165 ABG_ASSERT(!fn_id.empty());
166
167 if (priv_->fn_is_in_id_fns_map(fn))
168 return;
169
170 if (priv_->keep_wrt_id_of_fns_to_keep(fn)
171 && priv_->keep_wrt_regex_of_fns_to_suppress(fn)
172 && priv_->keep_wrt_regex_of_fns_to_keep(fn))
173 priv_->add_fn_to_exported(fn);
174}
175
176/// Consider at all the tunables that control wether a variable should
177/// be added to the set of exported variable and if it fits in, add
178/// the variable to that set.
179///
180/// @param fn the variable to add the set of exported variables.
181void
183{
185 return;
186
187 const interned_string& var_id = priv_->get_id(*var);
188 ABG_ASSERT(!var_id.empty());
189
190 if (priv_->var_id_is_in_id_var_map(var_id))
191 return;
192
193 if (priv_->keep_wrt_id_of_vars_to_keep(var)
194 && priv_->keep_wrt_regex_of_vars_to_suppress(var)
195 && priv_->keep_wrt_regex_of_vars_to_keep(var))
196 priv_->add_var_to_exported(var);
197}
198
199// </corpus::exported_decls_builder>
200
201/// Convenience typedef for a hash map of pointer to function_decl and
202/// boolean.
203typedef unordered_map<const function_decl*,
204 bool,
207
208/// Convenience typedef for a hash map of string and pointer to
209/// function_decl.
210typedef unordered_map<string, const function_decl*> str_fn_ptr_map_type;
211
212/// Convenience typedef for a hash map of pointer to var_decl and boolean.
213typedef unordered_map<const var_decl*,
214 bool,
217
218/// This is a comparison functor for comparing pointers to @ref
219/// function_decl.
220struct func_comp
221{
222 /// The comparisong operator for pointers to @ref function_decl. It
223 /// performs a string comparison of the mangled names of the
224 /// functions. If the functions don't have mangled names, it
225 /// compares their names instead.
226 ///
227 /// @param first the first function to consider in the comparison.
228 ///
229 /// @param second the second function to consider in the comparison.
230 ///
231 /// @return true if the (mangled) name of the first function is less
232 /// than the (mangled)name of the second one, false otherwise.
233 bool
234 operator()(const function_decl* first,
235 const function_decl* second) const
236 {
237 ABG_ASSERT(first != 0 && second != 0);
238
239 string first_name, second_name;
240 first_name = first->get_linkage_name();
241 if (first_name.empty())
242 first_name = first->get_name();
243 ABG_ASSERT(!first_name.empty());
244
245 second_name = second->get_linkage_name();
246 if (second_name.empty())
247 second_name = second->get_name();
248 ABG_ASSERT(!second_name.empty());
249
250 return first_name < second_name;
251 }
252};
253
254/// This is a comparison functor for comparing pointers to @ref
255/// var_decl.
256struct var_comp
257{
258 /// The comparison operator for pointers to @ref var_decl.
259 ///
260 /// It perform a string comparison on the names of the variables.
261 ///
262 /// @param first the first variable to consider for the comparison.
263 ///
264 /// @param second the second variable to consider for the comparison.
265 ///
266 /// @return true if first is less than second, false otherwise.
267 bool
268 operator()(const var_decl* first,
269 const var_decl* second) const
270 {
271 ABG_ASSERT(first != 0 && second != 0);
272
273 string first_name, second_name;
274 first_name = first->get_linkage_name();
275 if (first_name.empty())
276 {
277 first_name = first->get_pretty_representation();
278 second_name = second->get_pretty_representation();
279 ABG_ASSERT(!second_name.empty());
280 }
281 ABG_ASSERT(!first_name.empty());
282
283 if (second_name.empty())
284 second_name = second->get_linkage_name();
285
286 if (second_name.empty())
287 {
288 second_name = second->get_pretty_representation();
289 first_name = first->get_pretty_representation();
290 ABG_ASSERT(!first_name.empty());
291 }
292 ABG_ASSERT(!second_name.empty());
293
294 return first_name < second_name;
295 }
296};
297
298
299/// A comparison functor to compare elf_symbols for the purpose of
300/// sorting.
301struct comp_elf_symbols_functor
302{
303 bool
304 operator()(const elf_symbol& l,
305 const elf_symbol& r) const
306 {return l.get_id_string() < r.get_id_string();}
307
308 bool
309 operator()(const elf_symbol_sptr l,
310 const elf_symbol_sptr r) const
311 {return operator()(*l, *r);}
312}; // end struct comp_elf_symbols_functor
313
314
315// <corpus stuff>
316
317/// Get the maps that associate a name to a certain kind of type.
318type_maps&
320{return types_;}
321
322/// Get the maps that associate a name to a certain kind of type.
323const type_maps&
325{return types_;}
326
327/// Return a sorted vector of function symbols for this corpus.
328///
329/// Note that the first time this function is called, the symbols are
330/// sorted and cached. Subsequent invocations of this function return
331/// the cached vector that was built previously.
332///
333/// @return the sorted list of function symbols.
334const elf_symbols&
336{
337 if (!sorted_fun_symbols)
338 {
339 if (symtab_)
340 {
341 auto filter = symtab_->make_filter();
342 filter.set_functions();
343 sorted_fun_symbols = elf_symbols(symtab_->begin(filter),
344 symtab_->end());
345 }
346 else
347 sorted_fun_symbols = elf_symbols();
348 }
349 return *sorted_fun_symbols;
350}
351
352/// Return a map from name to function symbol for this corpus.
353///
354/// Note that the first time this function is called, the map is built.
355/// Subsequent invocations of this function return the cached map that was
356/// built previously.
357///
358/// @return the name function symbol map
361{
362 if (!fun_symbol_map)
363 {
364 fun_symbol_map = string_elf_symbols_map_type();
365 for (const auto& symbol : get_sorted_fun_symbols())
366 (*fun_symbol_map)[symbol->get_name()].push_back(symbol);
367 }
368 return *fun_symbol_map;
369}
370
371/// Getter for a sorted vector of the function symbols undefined in
372/// this corpus.
373///
374/// @return a vector of the function symbols undefined in this corpus,
375/// sorted by name and then version.
376const elf_symbols&
378{
379 if (!sorted_undefined_fun_symbols)
380 {
381 if (symtab_)
382 {
383 auto filter = symtab_->make_filter();
384 filter.set_functions();
385 filter.set_undefined_symbols();
386 filter.set_public_symbols(false);
387
388 sorted_undefined_fun_symbols =
389 elf_symbols(symtab_->begin(filter), symtab_->end());
390 }
391 else
392 sorted_undefined_fun_symbols = elf_symbols();
393 }
394 return *sorted_undefined_fun_symbols;
395}
396
397/// Return a map from name to undefined function symbol for this corpus.
398///
399/// Note that the first time this function is called, the map is built.
400/// Subsequent invocations of this function return the cached map that was
401/// built previously.
402///
403/// @return the name function symbol map for undefined symbols
406{
407 if (!undefined_fun_symbol_map)
408 {
409 undefined_fun_symbol_map = string_elf_symbols_map_type();
410 for (const auto& symbol : get_sorted_undefined_fun_symbols())
411 (*undefined_fun_symbol_map)[symbol->get_name()].push_back(symbol);
412 }
413 return *undefined_fun_symbol_map;
414}
415
416/// Return a list of symbols that are not referenced by any function of
417/// corpus::get_functions().
418///
419/// Note that this function considers the list of function symbols to keep,
420/// that is provided by corpus::get_sym_ids_of_fns_to_keep(). If a given
421/// unreferenced function symbol is not in the list of functions to keep, then
422/// that symbol is dropped and will not be part of the resulting table of
423/// unreferenced symbol that is built.
424///
425/// @return list of symbols that are not referenced by any function
426const elf_symbols&
428{
429 if (!unrefed_fun_symbols)
430 {
431 unrefed_fun_symbols = elf_symbols();
432 if (symtab_)
433 {
434 unordered_map<string, bool> refed_funs;
435
436 for (const auto& function : fns)
437 if (elf_symbol_sptr sym = function->get_symbol())
438 {
439 refed_funs[sym->get_id_string()] = true;
440 for (elf_symbol_sptr a = sym->get_next_alias();
441 a && !a->is_main_symbol(); a = a->get_next_alias())
442 refed_funs[a->get_id_string()] = true;
443 }
444
445 auto filter = symtab_->make_filter();
446 filter.set_functions();
447 for (const auto& symbol :
448 symtab_reader::filtered_symtab(*symtab_, filter))
449 {
450 const std::string sym_id = symbol->get_id_string();
451 if (refed_funs.find(sym_id) == refed_funs.end())
452 {
453 bool keep = sym_id_fns_to_keep.empty();
454 for (const auto& id : sym_id_fns_to_keep)
455 {
456 if (id == sym_id)
457 {
458 keep = true;
459 break;
460 }
461 }
462 if (keep)
463 unrefed_fun_symbols->push_back(symbol);
464 }
465 }
466 }
467 }
468 return *unrefed_fun_symbols;
469}
470
471/// Getter for the sorted vector of variable symbols for this corpus.
472///
473/// Note that the first time this function is called, it computes the
474/// sorted vector, caches the result and returns it. Subsequent
475/// invocations of this function just return the cached vector.
476///
477/// @return the sorted vector of variable symbols for this corpus.
478const elf_symbols&
480{
481 if (!sorted_var_symbols)
482 {
483 if (symtab_)
484 {
485 auto filter = symtab_->make_filter();
486 filter.set_variables();
487
488 sorted_var_symbols = elf_symbols(symtab_->begin(filter),
489 symtab_->end());
490 }
491 else
492 sorted_var_symbols = elf_symbols();
493 }
494 return *sorted_var_symbols;
495}
496
497/// Return a map from name to variable symbol for this corpus.
498///
499/// Note that the first time this function is called, the map is built.
500/// Subsequent invocations of this function return the cached map that was
501/// built previously.
502///
503/// @return the name variable symbol map
506{
507 if (!var_symbol_map)
508 {
509 var_symbol_map = string_elf_symbols_map_type();
510 for (const auto& symbol : get_sorted_var_symbols())
511 (*var_symbol_map)[symbol->get_name()].push_back(symbol);
512 }
513 return *var_symbol_map;
514}
515
516/// Getter for a sorted vector of the variable symbols undefined in
517/// this corpus.
518///
519/// @return a vector of the variable symbols undefined in this corpus,
520/// sorted by name and then version.
521const elf_symbols&
523{
524 if (!sorted_undefined_var_symbols)
525 {
526 if (symtab_)
527 {
528 auto filter = symtab_->make_filter();
529 filter.set_variables();
530 filter.set_undefined_symbols();
531 filter.set_public_symbols(false);
532
533 sorted_undefined_var_symbols =
534 elf_symbols(symtab_->begin(filter), symtab_->end());
535 }
536 else
537 sorted_undefined_var_symbols = elf_symbols();
538 }
539 return *sorted_undefined_var_symbols;
540}
541
542/// Return a map from name to undefined variable symbol for this corpus.
543///
544/// Note that the first time this function is called, the map is built.
545/// Subsequent invocations of this function return the cached map that was
546/// built previously.
547///
548/// @return the name undefined variable symbol map
551{
552 if (!undefined_var_symbol_map)
553 {
554 undefined_var_symbol_map = string_elf_symbols_map_type();
555 for (const auto& symbol : get_sorted_undefined_var_symbols())
556 (*undefined_var_symbol_map)[symbol->get_name()].push_back(symbol);
557 }
558 return *undefined_var_symbol_map;
559}
560
561/// Return a list of symbols that are not referenced by any variable of
562/// corpus::get_variables().
563///
564/// Note that this function considers the list of variable symbols to keep,
565/// that is provided by corpus::get_sym_ids_of_vars_to_keep(). If a given
566/// unreferenced variable symbol is not in the list of variable to keep, then
567/// that symbol is dropped and will not be part of the resulting table of
568/// unreferenced symbol that is built.
569///
570/// @return list of symbols that are not referenced by any variable
571const elf_symbols&
573{
574 if (!unrefed_var_symbols)
575 {
576 unrefed_var_symbols = elf_symbols();
577 if (symtab_)
578 {
579 unordered_map<string, bool> refed_vars;
580 for (const auto& variable : vars)
581 if (elf_symbol_sptr sym = variable->get_symbol())
582 {
583 refed_vars[sym->get_id_string()] = true;
584 for (elf_symbol_sptr a = sym->get_next_alias();
585 a && !a->is_main_symbol(); a = a->get_next_alias())
586 refed_vars[a->get_id_string()] = true;
587 }
588
589 auto filter = symtab_->make_filter();
590 filter.set_variables();
591 for (const auto& symbol :
592 symtab_reader::filtered_symtab(*symtab_, filter))
593 {
594 const std::string sym_id = symbol->get_id_string();
595 if (refed_vars.find(sym_id) == refed_vars.end())
596 {
597 bool keep = sym_id_vars_to_keep.empty();
598 for (const auto& id : sym_id_vars_to_keep)
599 {
600 if (id == sym_id)
601 {
602 keep = true;
603 break;
604 }
605 }
606 if (keep)
607 unrefed_var_symbols->push_back(symbol);
608 }
609 }
610 }
611 }
612 return *unrefed_var_symbols;
613}
614
615
616/// Getter of the set of pretty representation of types that are
617/// reachable from public interfaces (global functions and variables).
618///
619/// @return the set of pretty representation of types that are
620/// reachable from public interfaces (global functions and variables).
621unordered_set<interned_string, hash_interned_string>*
623{
624 if (group)
625 return group->get_public_types_pretty_representations();
626
627 if (pub_type_pretty_reprs_ == 0)
628 pub_type_pretty_reprs_ =
629 new unordered_set<interned_string, hash_interned_string>;
630 return pub_type_pretty_reprs_;
631}
632
633/// Lookup the function which has a given function ID.
634///
635/// Note that there can have been several functions with the same ID.
636/// This is because debug info can declare the same function in
637/// several different translation units. Normally, all these function
638/// should be equal. But still, this function returns all these
639/// functions.
640///
641/// @param id the ID of the function to lookup. This ID must be
642/// either the result of invoking function::get_id() of
643/// elf_symbol::get_id_string().
644///
645/// @return the set of functions which ID is @p id, or nil if no
646/// function with that ID was found.
647std::unordered_set<function_decl*>*
649{
651 if (b)
652 {
653 auto i = b->priv_->id_fns_map_.find(id);
654 if (i == b->priv_->id_fns_map_.end())
655 return 0;
656 return &i->second;
657 }
658 return nullptr;
659}
660
661/// Destructor of the @ref corpus::priv type.
663{
664 delete pub_type_pretty_reprs_;
665}
666
667/// Constructor of the @ref corpus type.
668///
669/// @param env the environment of the corpus.
670///
671/// @param path the path to the file containing the ABI corpus.
672corpus::corpus(const ir::environment& env, const string& path)
673{
674 priv_.reset(new priv(path, env));
675 init_format_version();
676}
677
678corpus::~corpus() = default;
679
680/// Getter of the enviroment of the corpus.
681///
682/// @return the environment of this corpus.
683const environment&
685{return priv_->env;}
686
687/// Test if logging was requested.
688///
689/// @return true iff logging was requested.
690bool
692{return priv_->do_log;}
693
694/// Request logging, or not.
695///
696/// @param f true iff logging is requested.
697void
699{priv_->do_log = f;}
700
701/// Add a translation unit to the current ABI Corpus.
702///
703/// Note that two translation units with the same path (as returned by
704/// translation_unit::get_path) cannot be added to the same @ref
705/// corpus. If that happens, the library aborts.
706///
707/// @param tu the new translation unit to add.
708void
710{
711 ABG_ASSERT(priv_->members.insert(tu).second);
712
713 if (!tu->get_absolute_path().empty())
714 {
715 // Update the path -> translation_unit map.
716 string_tu_map_type::const_iterator i =
717 priv_->path_tu_map.find(tu->get_absolute_path());
718 ABG_ASSERT(i == priv_->path_tu_map.end());
719 priv_->path_tu_map[tu->get_absolute_path()] = tu;
720 }
721
722 tu->set_corpus(this);
723}
724
725/// Return the list of translation units of the current corpus.
726///
727/// @return the list of translation units of the current corpus.
730{return priv_->members;}
731
732/// Find the translation unit that has a given path.
733///
734/// @param path the path of the translation unit to look for.
735///
736/// @return the translation unit found, if any. Otherwise, return
737/// nil.
739corpus::find_translation_unit(const string &path) const
740{
741 string_tu_map_type::const_iterator i =
742 priv_->path_tu_map.find(path);
743
744 if (i == priv_->path_tu_map.end())
745 return translation_unit_sptr();
746 return i->second;
747}
748
749/// Erase the translation units contained in this in-memory object.
750///
751/// Note that the on-disk archive file that contains the serialized
752/// representation of this object is not modified.
753void
755{priv_->members.clear();}
756
757/// Get the maps that associate a name to a certain kind of type.
758///
759/// @return the maps that associate a name to a certain kind of type.
762{return priv_->types_;}
763
764/// Get the maps that associate a name to a certain kind of type.
765///
766/// @return the maps that associate a name to a certain kind of
767/// type.
768const type_maps&
770{return priv_->types_;}
771
772/// Get the maps that associate a location string to a certain kind of
773/// type.
774///
775/// The location string is the result of the invocation to the
776/// function abigail::ir::location::expand(). It has the form
777/// "file.c:4:1", with 'file.c' being the file name, '4' being the
778/// line number and '1' being the column number.
779///
780/// @return the maps.
781const type_maps&
783{return priv_->type_per_loc_map_;}
784
785/// Test if the recording of reachable types (and thus, indirectly,
786/// the recording of non-reachable types) is activated for the
787/// current @ref corpus.
788///
789/// @return true iff the recording of reachable types is activated for
790/// the current @ref corpus.
791bool
793{
794 return (priv_->get_public_types_pretty_representations()
795 && !priv_->get_public_types_pretty_representations()->empty());
796}
797
798/// Record a type as being reachable from public interfaces (global
799/// functions and variables).
800///
801/// @param t the type to record as reachable.
802void
804{
805 string repr = get_pretty_representation(&t, /*internal=*/false);
807 priv_->get_public_types_pretty_representations()->insert(s);
808}
809
810/// Test if a type is reachable from public interfaces (global
811/// functions and variables).
812///
813/// For a type to be considered reachable from public interfaces, it
814/// must have been previously marked as such by calling
815/// corpus::record_type_as_reachable_from_public_interfaces.
816///
817/// @param t the type to test for.
818///
819/// @return true iff @p t is reachable from public interfaces.
820bool
822{
823 string repr = get_pretty_representation(&t, /*internal=*/false);
825
826 return (priv_->get_public_types_pretty_representations()->find(s)
827 != priv_->get_public_types_pretty_representations()->end());
828}
829
830/// Getter of a sorted vector of the types that are *NOT* reachable
831/// from public interfaces.
832///
833/// Note that for this to be non-empty, the libabigail reader that
834/// analyzed the input (be it a binary or an abixml file) must have be
835/// configured to load types that are not reachable from public
836/// interfaces.
837///
838/// @return a reference to a vector of sorted types NON reachable from
839/// public interfaces.
840const vector<type_base_wptr>&
842{
843 if (priv_->types_not_reachable_from_pub_ifaces_.empty())
844 {
845 const type_maps& types = get_types();
846 for (vector<type_base_wptr>::const_iterator it =
847 types.get_types_sorted_by_name().begin();
848 it != types.get_types_sorted_by_name().end();
849 ++it)
850 {
851 type_base_sptr t(*it);
853 priv_->types_not_reachable_from_pub_ifaces_.push_back(t);
854 }
855 }
856
857 return priv_->types_not_reachable_from_pub_ifaces_;
858}
859
860/// Get the maps that associate a location string to a certain kind of
861/// type.
862///
863/// The location string is the result of the invocation to the
864/// function abigail::ir::location::expand(). It has the form
865/// "file.c:4:1", with 'file.c' being the file name, '4' being the
866/// line number and '1' being the column number.
867///
868/// @return the maps.
871{return priv_->type_per_loc_map_;}
872
873/// Getter of the group this corpus is a member of.
874///
875/// @return the group this corpus is a member of, or nil if it's not
876/// part of any @ref corpus_group.
877const corpus_group*
879{return priv_->group;}
880
881/// Getter of the group this corpus belongs to.
882///
883/// @return the group this corpus belong to, or nil if it's not part
884/// of any @ref corpus_group.
887{return priv_->group;}
888
889/// Setter of the group this corpus belongs to.
890///
891/// @param g the new group.
892void
893corpus::set_group(corpus_group* g)
894{priv_->group = g;}
895
896/// Initialize the abixml serialization format version number of the
897/// corpus.
898///
899/// This function sets the format version number ot the default one
900/// supported by the current version of Libabigail.
901void
902corpus::init_format_version()
903{
905 (priv_->env.get_config().get_format_major_version_number());
907 (priv_->env.get_config().get_format_minor_version_number());
908}
909
910/// Getter for the origin of the corpus.
911///
912/// @return the origin of the corpus.
915{return priv_->origin_;}
916
917/// Setter for the origin of the corpus.
918///
919/// @param o the new origin for the corpus.
920void
922{priv_->origin_ = o;}
923
924/// Getter of the major version number of the abixml serialization
925/// format.
926///
927/// @return the major version number of the abixml format.
928string&
930{return priv_->format_major_version_number_;}
931
932/// Setter of the major version number of the abixml serialization
933/// format.
934///
935/// @param maj the new major version numberof the abixml format.
936void
938{priv_->format_major_version_number_ = maj;}
939
940/// Getter of the minor version number of the abixml serialization
941/// format.
942///
943/// @return the minor version number of the abixml serialization
944/// format.
945string&
947{return priv_->format_minor_version_number_;}
948
949/// Setter of the minor version number of the abixml serialization
950/// format.
951///
952/// @param min the new minor version number of the abixml
953/// serialization format.
954void
956{priv_->format_minor_version_number_ = min;}
957
958/// Get the file path associated to the corpus file.
959///
960/// A subsequent call to corpus::read will deserialize the content of
961/// the abi file expected at this path; likewise, a call to
962/// corpus::write will serialize the translation units contained in
963/// the corpus object into the on-disk file at this path.
964///
965/// @return the file path associated to the current corpus.
966string&
968{return priv_->path;}
969
970/// Set the file path associated to the corpus file.
971///
972/// A subsequent call to corpus::read will deserialize the content of
973/// the abi file expected at this path; likewise, a call to
974/// corpus::write will serialize the translation units contained in
975/// the corpus object into the on-disk file at this path.
976///
977/// @param path the new file path to assciate to the current corpus.
978void
979corpus::set_path(const string& path)
980{priv_->path = path;}
981
982/// Getter of the needed property of the corpus.
983///
984/// This property is meaningful for, e.g, corpora built from ELF
985/// shared library files. In that case, this is a vector of names of
986/// dependencies of the ELF shared library file.
987///
988/// @return the vector of dependencies needed by this corpus.
989const vector<string>&
991{return priv_->needed;}
992
993/// Setter of the needed property of the corpus.
994///
995/// This property is meaningful for, e.g, corpora built from ELF
996/// shared library files. In that case, this is a vector of names of
997/// dependencies of the ELF shared library file.
998///
999/// @param needed the new vector of dependencies needed by this
1000/// corpus.
1001void
1002corpus::set_needed(const vector<string>& needed)
1003{priv_->needed = needed;}
1004
1005/// Getter for the soname property of the corpus.
1006///
1007/// This property is meaningful for, e.g, corpora built from ELF
1008/// shared library files. In that case, this is the shared object
1009/// name exported by the shared library.
1010///
1011/// @return the soname property of the corpus.
1012const string&
1014{return priv_->soname;}
1015
1016/// Setter for the soname property of the corpus.
1017///
1018/// This property is meaningful for, e.g, corpora built from ELF
1019/// shared library files. In that case, this is the shared object
1020/// name exported by the shared library.
1021///
1022/// @param soname the new soname property of the corpus.
1023void
1024corpus::set_soname(const string& soname)
1025{priv_->soname = soname;}
1026
1027/// Getter for the architecture name of the corpus.
1028///
1029/// This property is meaningful for e.g, corpora built from ELF shared
1030/// library files. In that case, this is a string representation of
1031/// the Elf{32,64}_Ehdr::e_machine field.
1032///
1033/// @return the architecture name string.
1034const string&
1036{return priv_->architecture_name;}
1037
1038/// Setter for the architecture name of the corpus.
1039///
1040/// This property is meaningful for e.g, corpora built from ELF shared
1041/// library files. In that case, this is a string representation of
1042/// the Elf{32,64}_Ehdr::e_machine field.
1043///
1044/// @param arch the architecture name string.
1045void
1047{priv_->architecture_name = arch;}
1048
1049/// Tests if the corpus is empty from an ABI surface perspective. I.e. if all
1050/// of these criteria are true:
1051/// - all translation units (members) are empty
1052/// - the maps function and variable symbols are not having entries
1053/// - for shared libraries:
1054/// - the soname is empty
1055/// - there are no DT_NEEDED entries
1056///
1057/// @return true if the corpus contains no translation unit.
1058bool
1060{
1061 bool members_empty = true;
1062 for (translation_units::const_iterator i = priv_->members.begin(),
1063 e = priv_->members.end();
1064 i != e; ++i)
1065 {
1066 if (!(*i)->is_empty())
1067 {
1068 members_empty = false;
1069 break;
1070 }
1071 }
1072 return (members_empty
1073 && (!get_symtab() || !get_symtab()->has_symbols())
1074 && priv_->soname.empty()
1075 && priv_->needed.empty()
1076 && priv_->architecture_name.empty()
1077 && !priv_->group);
1078}
1079
1080/// Compare the current @ref corpus against another one.
1081///
1082/// @param other the other corpus to compare against.
1083///
1084/// @return true if the two corpus are equal, false otherwise.
1085bool
1086corpus::operator==(const corpus& other) const
1087{
1088 translation_units::const_iterator i, j;
1089 for (i = get_translation_units().begin(),
1090 j = other.get_translation_units().begin();
1091 (i != get_translation_units().end()
1092 && j != other.get_translation_units().end());
1093 ++i, ++j)
1094 if ((**i) != (**j))
1095 return false;
1096
1097 return (i == get_translation_units().end()
1098 && j == other.get_translation_units().end());
1099}
1100
1101/// Setter for the symtab object.
1102///
1103/// @param symtab a shared pointer to the new symtab object
1104void
1106{priv_->symtab_ = symtab;}
1107
1108/// Getter for the symtab object.
1109///
1110/// @return a shared pointer to the symtab object
1113{return priv_->symtab_;}
1114
1115/// Getter for the function symbols map.
1116///
1117/// @return a reference to the function symbols map.
1120{return priv_->get_fun_symbol_map();}
1121
1122/// Getter for the map of function symbols that are undefined in this
1123/// corpus.
1124///
1125/// @return the map of function symbols not defined in this corpus.
1126/// The key of the map is the name of the function symbol. The value
1127/// is a vector of all the function symbols that have the same name.
1130{return priv_->get_undefined_fun_symbol_map();}
1131
1132/// Return a sorted vector of function symbols for this corpus.
1133///
1134/// Note that the first time this function is called, the symbols are
1135/// sorted and cached. Subsequent invocations of this function return
1136/// the cached vector that was built previously.
1137///
1138/// @return the sorted list of function symbols.
1139const elf_symbols&
1141{return priv_->get_sorted_fun_symbols();}
1142
1143/// Getter for a sorted vector of the function symbols undefined in
1144/// this corpus.
1145///
1146/// @return a vector of the function symbols undefined in this corpus,
1147/// sorted by name and then version.
1148const elf_symbols&
1150{return priv_->get_sorted_undefined_fun_symbols();}
1151
1152/// Getter for the sorted vector of variable symbols for this corpus.
1153///
1154/// Note that the first time this function is called, it computes the
1155/// sorted vector, caches the result and returns it. Subsequent
1156/// invocations of this function just return the cached vector.
1157///
1158/// @return the sorted vector of variable symbols for this corpus.
1159const elf_symbols&
1161{return priv_->get_sorted_var_symbols();}
1162
1163/// Getter for a sorted vector of the variable symbols undefined in
1164/// this corpus.
1165///
1166/// @return a vector of the variable symbols undefined in this corpus,
1167/// sorted by name and then version.
1168const elf_symbols&
1170{return priv_->get_sorted_undefined_var_symbols();}
1171
1172/// Getter for the variable symbols map.
1173///
1174/// @return a reference to the variabl symbols map.
1177{return priv_->get_var_symbol_map();}
1178
1179/// Getter for the map of variable symbols that are undefined in this
1180/// corpus.
1181///
1182/// @return the map of variable symbols not defined in this corpus.
1183/// The key of the map is the name of the variable symbol. The value
1184/// is a vector of all the variable symbols that have the same name.
1187{return priv_->get_undefined_var_symbol_map();}
1188
1189/// Look in the function symbols map for a symbol with a given name.
1190///
1191/// @param n the name of the symbol to look for.
1192///
1193/// return the first symbol with the name @p n.
1194const elf_symbol_sptr
1196{
1197 if (get_fun_symbol_map().empty())
1198 return elf_symbol_sptr();
1199
1200 string_elf_symbols_map_type::const_iterator it =
1201 get_fun_symbol_map().find(n);
1202 if ( it == get_fun_symbol_map().end())
1203 return elf_symbol_sptr();
1204 return it->second[0];
1205}
1206
1207/// Look into a set of symbols and look for a symbol that has a given
1208/// version.
1209///
1210/// This is a sub-routine for corpus::lookup_function_symbol() and
1211/// corpus::lookup_variable_symbol().
1212///
1213/// @param version the version of the symbol to look for.
1214///
1215/// @param symbols the set of symbols to consider.
1216///
1217/// @return the symbol found, or nil if none was found.
1218static const elf_symbol_sptr
1219find_symbol_by_version(const elf_symbol::version& version,
1220 const vector<elf_symbol_sptr>& symbols)
1221{
1222 if (version.is_empty())
1223 {
1224 // We are looing for a symbol with no version.
1225
1226 // So first look for possible aliases with no version
1227 for (elf_symbols::const_iterator s = symbols.begin();
1228 s != symbols.end();
1229 ++s)
1230 if ((*s)->get_version().is_empty())
1231 return *s;
1232
1233 // Or, look for a version that is a default one!
1234 for (elf_symbols::const_iterator s = symbols.begin();
1235 s != symbols.end();
1236 ++s)
1237 if ((*s)->get_version().is_default())
1238 return *s;
1239 }
1240 else
1241 // We are looking for a symbol with a particular defined version.
1242 for (elf_symbols::const_iterator s = symbols.begin();
1243 s != symbols.end();
1244 ++s)
1245 if ((*s)->get_version().str() == version.str())
1246 return *s;
1247
1248 return elf_symbol_sptr();
1249}
1250
1251/// Look in the function symbols map for a symbol with a given name.
1252///
1253/// @param symbol_name the name of the symbol to look for.
1254///
1255/// @param version the version of the symbol to look for.
1256///
1257/// return the symbol with name @p symbol_name and with version @p
1258/// version, or nil if no symbol has been found with that name and
1259/// version.
1260const elf_symbol_sptr
1261corpus::lookup_function_symbol(const string& symbol_name,
1262 const elf_symbol::version& version) const
1263{
1264 if (get_fun_symbol_map().empty())
1265 return elf_symbol_sptr();
1266
1267 string_elf_symbols_map_type::const_iterator it =
1268 get_fun_symbol_map().find(symbol_name);
1269 if ( it == get_fun_symbol_map().end())
1270 return elf_symbol_sptr();
1271
1272 return find_symbol_by_version(version, it->second);
1273}
1274
1275/// Look in the function symbols map for a symbol with the same name
1276/// and version as a given symbol.
1277///
1278/// @param symbol the symbol to look for.
1279///
1280/// return the symbol with the same name and version as @p symbol.
1281const elf_symbol_sptr
1283{return lookup_function_symbol(symbol.get_name(), symbol.get_version());}
1284
1285/// Look in the variable symbols map for a symbol with a given name.
1286///
1287/// @param n the name of the symbol to look for.
1288///
1289/// return the first symbol with the name @p n.
1290const elf_symbol_sptr
1292{
1293 if (get_var_symbol_map().empty())
1294 return elf_symbol_sptr();
1295
1296 string_elf_symbols_map_type::const_iterator it =
1297 get_var_symbol_map().find(n);
1298 if ( it == get_var_symbol_map().end())
1299 return elf_symbol_sptr();
1300 return it->second[0];
1301}
1302
1303/// Look in the variable symbols map for a symbol with a given name.
1304///
1305/// @param symbol_name the name of the symbol to look for.
1306///
1307/// @param symbol_version the version of the symbol to look for.
1308///
1309/// return the first symbol with the name @p symbol_name and with
1310/// version @p version.
1311const elf_symbol_sptr
1312corpus::lookup_variable_symbol(const string& symbol_name,
1313 const elf_symbol::version& version) const
1314{
1315 if (get_var_symbol_map().empty())
1316 return elf_symbol_sptr();
1317
1318 string_elf_symbols_map_type::const_iterator it =
1319 get_var_symbol_map().find(symbol_name);
1320 if ( it == get_var_symbol_map().end())
1321 return elf_symbol_sptr();
1322
1323 return find_symbol_by_version(version, it->second);
1324}
1325
1326/// Look in the variable symbols map for a symbol with the same name
1327/// and version as a given symbol.
1328///
1329/// @param symbol the symbol to look for.
1330///
1331/// return the symbol with the same name and version as @p symbol.
1332const elf_symbol_sptr
1334{return lookup_variable_symbol(symbol.get_name(), symbol.get_version());}
1335
1336/// Return the functions public decl table of the current corpus.
1337///
1338/// The function public decl tables is a vector of all the functions
1339/// and member functions found in the current corpus.
1340///
1341/// Note that the caller can suppress some functions from the vector
1342/// supplying regular expressions describing the set of functions she
1343/// want to see removed from the public decl table by populating the
1344/// vector of regular expressions returned by
1345/// corpus::get_regex_patterns_of_fns_to_suppress().
1346///
1347/// @return the vector of functions of the public decl table. The
1348/// functions are sorted using their mangled name or name if they
1349/// don't have mangle names.
1350const corpus::functions&
1352{return priv_->fns;}
1353
1354/// Lookup the function which has a given function ID.
1355///
1356/// Note that there can have been several functions with the same ID.
1357/// This is because debug info can declare the same function in
1358/// several different translation units. Normally, all these function
1359/// should be equal. But still, this function returns all these
1360/// functions.
1361///
1362/// @param id the ID of the function to lookup. This ID must be
1363/// either the result of invoking function::get_id() of
1364/// elf_symbol::get_id_string().
1365///
1366/// @return the set of functions which ID is @p id, or nil if no
1367/// function with that ID was found.
1368const std::unordered_set<function_decl*>*
1370{return priv_->lookup_functions(id);}
1371
1372const std::unordered_set<function_decl*>*
1373corpus::lookup_functions(const char* id) const
1374{
1375 if (!id)
1376 return nullptr;
1377
1378 interned_string string_id = priv_->env.intern(id);
1379 return lookup_functions(string_id);
1380}
1381
1382/// Sort the set of functions exported by this corpus.
1383///
1384/// Normally, you shouldn't be calling this as the code that creates
1385/// the corpus for you should do it for you too.
1386void
1388{
1389 func_comp fc;
1390 std::sort(priv_->fns.begin(), priv_->fns.end(), fc);
1391}
1392
1393/// Return the public decl table of the global variables of the
1394/// current corpus.
1395///
1396/// The variable public decls table is a vector of all the public
1397/// global variables and static member variables found in the current
1398/// corpus.
1399///
1400/// Note that the caller can suppress some variables from the vector
1401/// supplying regular expressions describing the set of variables she
1402/// wants to see removed from the public decl table by populating the
1403/// vector of regular expressions returned by
1404/// corpus::get_regex_patterns_of_fns_to_suppress().
1405///
1406/// @return the vector of variables of the public decl table. The
1407/// variables are sorted using their name.
1408const corpus::variables&
1410{return priv_->vars;}
1411
1412/// Sort the set of variables exported by this corpus.
1413///
1414/// Normally, you shouldn't be calling this as the code that creates
1415/// the corpus for you should do it for you too.
1416void
1418{
1419 var_comp vc;
1420 std::sort(priv_->vars.begin(), priv_->vars.end(), vc);
1421}
1422
1423/// Getter of the set of function symbols that are not referenced by
1424/// any function exported by the current corpus.
1425///
1426/// When the corpus has been created from an ELF library or program,
1427/// this function returns the set of function symbols not referenced
1428/// by any debug information.
1429///
1430/// @return the vector of function symbols not referenced by any
1431/// function exported by the current corpus.
1432const elf_symbols&
1434{return priv_->get_unreferenced_function_symbols();}
1435
1436/// Getter of the set of variable symbols that are not referenced by
1437/// any variable exported by the current corpus.
1438///
1439/// When the corpus has been created from an ELF library or program,
1440/// this function returns the set of variable symbols not referenced
1441/// by any debug information.
1442///
1443/// @return the vector of variable symbols not referenced by any
1444/// variable exported by the current corpus.
1445const elf_symbols&
1447{return priv_->get_unreferenced_variable_symbols();}
1448
1449/// Accessor for the regex patterns describing the functions to drop
1450/// from the public decl table.
1451///
1452/// @return the regex patterns describing the functions to drop from
1453/// the public decl table.
1454vector<string>&
1456{return priv_->regex_patterns_fns_to_suppress;}
1457
1458/// Accessor for the regex patterns describing the functions to drop
1459/// from the public decl table.
1460///
1461/// @return the regex patterns describing the functions to drop from
1462/// the public decl table.
1463const vector<string>&
1465{return priv_->regex_patterns_fns_to_suppress;}
1466
1467/// Accessor for the regex patterns describing the variables to drop
1468/// from the public decl table.
1469///
1470/// @return the regex patterns describing the variables to drop from
1471/// the public decl table.
1472vector<string>&
1474{return priv_->regex_patterns_vars_to_suppress;}
1475
1476/// Accessor for the regex patterns describing the variables to drop
1477/// from the public decl table.
1478///
1479/// @return the regex patterns describing the variables to drop from
1480/// the public decl table.
1481const vector<string>&
1483{return priv_->regex_patterns_vars_to_suppress;}
1484
1485/// Accessor for the regex patterns describing the functions to keep
1486/// into the public decl table. The other functions not matches by these
1487/// regexes are dropped from the public decl table.
1488///
1489/// @return the regex patterns describing the functions to keep into
1490/// the public decl table.
1491vector<string>&
1493{return priv_->regex_patterns_fns_to_keep;}
1494
1495/// Accessor for the regex patterns describing the functions to keep
1496/// into the public decl table. The other functions not matches by these
1497/// regexes are dropped from the public decl table.
1498///
1499/// @return the regex patterns describing the functions to keep into
1500/// the public decl table.
1501const vector<string>&
1503{return priv_->regex_patterns_fns_to_keep;}
1504
1505/// Getter for the vector of function symbol IDs to keep.
1506///
1507/// A symbol ID is a string made of the name of the symbol and its
1508/// version, separated by one or two '@'.
1509///
1510/// @return a vector of IDs of function symbols to keep.
1511vector<string>&
1513{return priv_->sym_id_fns_to_keep;}
1514
1515/// Getter for the vector of function symbol IDs to keep.
1516///
1517/// A symbol ID is a string made of the name of the symbol and its
1518/// version, separated by one or two '@'.
1519///
1520/// @return a vector of IDs of function symbols to keep.
1521const vector<string>&
1523{return priv_->sym_id_fns_to_keep;}
1524
1525/// Accessor for the regex patterns describing the variables to keep
1526/// into the public decl table. The other variables not matches by these
1527/// regexes are dropped from the public decl table.
1528///
1529/// @return the regex patterns describing the variables to keep into
1530/// the public decl table.
1531vector<string>&
1533{return priv_->regex_patterns_vars_to_keep;}
1534
1535/// Accessor for the regex patterns describing the variables to keep
1536/// into the public decl table. The other variables not matches by these
1537/// regexes are dropped from the public decl table.
1538///
1539/// @return the regex patterns describing the variables to keep into
1540/// the public decl table.
1541const vector<string>&
1543{return priv_->regex_patterns_vars_to_keep;}
1544
1545/// Getter for the vector of variable symbol IDs to keep.
1546///
1547/// A symbol ID is a string made of the name of the symbol and its
1548/// version, separated by one or two '@'.
1549///
1550/// @return a vector of IDs of variable symbols to keep.
1551vector<string>&
1553{return priv_->sym_id_vars_to_keep;}
1554
1555/// Getter for the vector of variable symbol IDs to keep.
1556///
1557/// A symbol ID is a string made of the name of the symbol and its
1558/// version, separated by one or two '@'.
1559///
1560/// @return a vector of IDs of variable symbols to keep.
1561const vector<string>&
1563{return priv_->sym_id_vars_to_keep;}
1564
1565/// After the set of exported functions and variables have been built,
1566/// consider all the tunables that control that set and see if some
1567/// functions need to be removed from that set; if so, remove them.
1568void
1570{
1571 string sym_name, sym_version;
1572
1573 functions fns_to_keep;
1575 for (auto f = priv_->fns.begin(); f != priv_->fns.end(); ++f)
1576 {
1577 if (b->priv_->keep_wrt_id_of_fns_to_keep(*f)
1578 && b->priv_->keep_wrt_regex_of_fns_to_suppress(*f)
1579 && b->priv_->keep_wrt_regex_of_fns_to_keep(*f))
1580 fns_to_keep.push_back(*f);
1581 }
1582 priv_->fns = fns_to_keep;
1583
1584 variables vars_to_keep;
1585 for (auto v = priv_->vars.begin(); v != priv_->vars.end(); ++v)
1586 {
1587 if (b->priv_->keep_wrt_id_of_vars_to_keep(*v)
1588 && b->priv_->keep_wrt_regex_of_vars_to_suppress(*v)
1589 && b->priv_->keep_wrt_regex_of_vars_to_keep(*v))
1590 vars_to_keep.push_back(*v);
1591 }
1592 priv_->vars = vars_to_keep;
1593}
1594
1595/// Getter for the object that is responsible for determining what
1596/// decls ought to be in the set of exported decls.
1597///
1598/// The object does have methods to add the decls to the set of
1599/// exported decls, right at the place where the corpus expects it,
1600/// so that there is no unnecessary copying involved.
1601///
1602/// @return a (smart) pointer to the instance of @ref
1603/// corpus::exported_decls_builder that is responsible for determine
1604/// what decls ought to be in the set of exported decls.
1607{
1608 if (!priv_->exported_decls_builder)
1609 {
1610 priv_->exported_decls_builder.reset
1611 (new exported_decls_builder(priv_->fns,
1612 priv_->vars,
1613 priv_->regex_patterns_fns_to_suppress,
1614 priv_->regex_patterns_vars_to_suppress,
1615 priv_->regex_patterns_fns_to_keep,
1616 priv_->regex_patterns_vars_to_keep,
1617 priv_->sym_id_fns_to_keep,
1618 priv_->sym_id_vars_to_keep));
1619 }
1620 return priv_->exported_decls_builder;
1621}
1622
1623/// Bitwise | operator for the corpus::origin type.
1624///
1625/// @param l the left-hand side operand of the | operation.
1626///
1627/// @param r the right-hand side operand of the | operation.
1628///
1629/// @return the result of the operation.
1632{
1633 return static_cast<corpus::origin>
1634 (static_cast<uint32_t>(l) | static_cast<uint32_t>(r));
1635}
1636
1637/// Bitwise |= operator for the corpus::origin type.
1638///
1639/// @param l the left-hand side operand for the |= operation.
1640///
1641/// @param r the right-hand side operand for the |= operation.
1642///
1643/// @return the result of the operation.
1646{
1647 l = l | r;
1648 return l;
1649}
1650
1651/// Bitwise & operator for the corpus::origin type.
1652///
1653/// @param l the left-hand side operand of the & operation.
1654///
1655/// @param r the right-hand side operand of the & operation.
1656///
1657/// @return the result of the operation.
1660{
1661 return static_cast<corpus::origin>
1662 (static_cast<uint32_t>(l) & static_cast<uint32_t>(r));
1663}
1664
1665/// Bitwise &= operator for the corpus::origin type.
1666///
1667/// @param l the left-hand side operand of the &= operation.
1668///
1669/// @param r the right-hand side operand of the &= operation.
1670///
1671/// @return the result of the operation.
1674{
1675 l = l & r;
1676 return l;
1677}
1678
1679// </corpus stuff>
1680
1681// <corpus_group stuff>
1682
1683/// Type of the private data of @ref corpus_group
1684struct corpus_group::priv
1685{
1686 std::set<string> corpora_paths;
1687 corpora_type corpora;
1688 istring_function_decl_ptr_map_type fns_map;
1690 istring_var_decl_ptr_map_type vars_map;
1691 corpus::variables vars;
1692 string_elf_symbols_map_type var_symbol_map;
1693 string_elf_symbols_map_type fun_symbol_map;
1694 elf_symbols sorted_var_symbols;
1695 elf_symbols sorted_fun_symbols;
1696 unordered_map<string, elf_symbol_sptr> unrefed_fun_symbol_map;
1697 elf_symbols unrefed_fun_symbols;
1698 bool unrefed_fun_symbols_built;
1699 unordered_map<string, elf_symbol_sptr> unrefed_var_symbol_map;
1700 elf_symbols unrefed_var_symbols;
1701 bool unrefed_var_symbols_built;
1702 unordered_set<interned_string, hash_interned_string> pub_type_pretty_reprs_;
1703
1704 priv()
1705 : unrefed_fun_symbols_built(),
1706 unrefed_var_symbols_built()
1707 {}
1708
1709 /// Add symbols to the set of corpus group function symbols that are
1710 /// *NOT* referenced by debug info.
1711 ///
1712 /// @param syms the set the symbols to add.
1713 void
1714 add_unref_fun_symbols(const elf_symbols& syms)
1715 {
1716 for (elf_symbols::const_iterator e =
1717 syms.begin(); e != syms.end(); ++e)
1718 {
1719 string sym_id = (*e)->get_id_string();
1720 unordered_map<string, elf_symbol_sptr>::const_iterator j =
1721 unrefed_fun_symbol_map.find(sym_id);
1722 if (j != unrefed_fun_symbol_map.end())
1723 continue;
1724
1725 unrefed_fun_symbol_map[sym_id] = *e;
1726 unrefed_fun_symbols.push_back(*e);
1727 }
1728 unrefed_fun_symbols_built = true;
1729 }
1730
1731 /// Add symbols to the set of corpus group variable symbols that are
1732 /// *NOT* referenced by debug info.
1733 ///
1734 /// @param syms the set the symbols to add.
1735 void
1736 add_unref_var_symbols(const elf_symbols& syms)
1737 {
1738 for (elf_symbols::const_iterator e =
1739 syms.begin(); e != syms.end(); ++e)
1740 {
1741 string sym_id = (*e)->get_id_string();
1742 unordered_map<string, elf_symbol_sptr>::const_iterator j =
1743 unrefed_var_symbol_map.find(sym_id);
1744 if (j != unrefed_var_symbol_map.end())
1745 continue;
1746
1747 unrefed_var_symbol_map[sym_id] = *e;
1748 unrefed_var_symbols.push_back(*e);
1749 }
1750 unrefed_var_symbols_built = true;
1751 }
1752}; // end corpus_group::priv
1753
1754/// Constructor of the @ref corpus_group type.
1755///
1756/// @param env the environment of the @ref corpus_group.
1757///
1758/// @param path the path to the file represented by the corpus group.
1759corpus_group::corpus_group(const environment& env, const string& path = "")
1760 : corpus(env, path), priv_(new priv)
1761{}
1762
1763/// Desctructor of the @ref corpus_group type.
1765{}
1766
1767/// Add a new corpus to the current instance of @ref corpus_group.
1768///
1769/// @param corp the new corpus to add.
1770void
1771corpus_group::add_corpus(const corpus_sptr& corp)
1772{
1773 if (!corp)
1774 return;
1775
1776 if (!corp->get_path().empty()
1777 && has_corpus(corp->get_path()))
1778 return;
1779
1780 // Ensure the new architecture name matches the current one.
1781 string cur_arch = get_architecture_name(),
1782 corp_arch = corp->get_architecture_name();
1783 if (cur_arch.empty())
1784 set_architecture_name(corp_arch);
1785 else if (cur_arch != corp_arch)
1786 {
1787 std::cerr << "corpus '" << corp->get_path() << "'"
1788 << " has architecture '" << corp_arch << "'"
1789 << " but expected '" << cur_arch << "'\n";
1791 }
1792
1793 priv_->corpora.push_back(corp);
1794 corp->set_group(this);
1795 priv_->corpora_paths.insert(corp->get_path());
1796
1797 /// Add the unreferenced function and variable symbols of this
1798 /// corpus to the unreferenced symbols of the current corpus group.
1799 priv_->add_unref_fun_symbols(get_unreferenced_function_symbols());
1800 priv_->add_unref_var_symbols(get_unreferenced_variable_symbols());
1801}
1802
1803/// Test if a corpus of a given path has been added to the group.
1804///
1805/// @param path the path to the corpus to consider.
1806///
1807/// @return true iff a corpus with path @p path is already present in
1808/// the groupâ‹…
1809bool
1810corpus_group::has_corpus(const string& path)
1811{
1812 if (priv_->corpora_paths.find(path) != priv_->corpora_paths.end())
1813 return true;
1814 return false;
1815}
1816
1817/// Getter of the vector of corpora held by the current @ref
1818/// corpus_group.
1819///
1820/// @return the vector corpora.
1821const corpus_group::corpora_type&
1823{return priv_->corpora;}
1824
1825/// Getter of the first corpus added to this Group.
1826///
1827/// @return the first corpus added to this Group.
1828const corpus_sptr
1830{return const_cast<corpus_group*>(this)->get_main_corpus();}
1831
1832/// Getter of the first corpus added to this Group.
1833///
1834/// @return the first corpus added to this Group.
1835corpus_sptr
1837{
1838 if (!get_corpora().empty())
1839 return get_corpora().front();
1840 return corpus_sptr();
1841}
1842
1843/// Test if the current corpus group is empty.
1844///
1845/// @return true iff the current corpus group is empty.
1846bool
1848{return get_corpora().empty();}
1849
1850/// Get the functions exported by the corpora of the current corpus
1851/// group.
1852///
1853/// Upon its first invocation, this function walks the corpora
1854/// contained in the corpus group and caches the functions they exported.
1855///
1856/// Subsequent invocations just return the cached functions.
1857///
1858/// @return the exported functions.
1859const corpus::functions&
1861{
1862 if (priv_->fns.empty())
1863 for (corpora_type::const_iterator i = get_corpora().begin();
1864 i != get_corpora().end();
1865 ++i)
1866 {
1867 corpus_sptr c = *i;
1868 for (corpus::functions::const_iterator f = c->get_functions().begin();
1869 f != c->get_functions().end();
1870 ++f)
1871 {
1872 interned_string fid = (*f)->get_id();
1873 istring_function_decl_ptr_map_type::const_iterator j =
1874 priv_->fns_map.find(fid);
1875
1876 if (j != priv_->fns_map.end())
1877 // Don't cache the same function twice ...
1878 continue;
1879
1880 priv_->fns_map[fid] = *f;
1881 // really cache the function now.
1882 priv_->fns.push_back(*f);
1883 }
1884 }
1885
1886 return priv_->fns;
1887}
1888
1889/// Get the global variables exported by the corpora of the current
1890/// corpus group.
1891///
1892/// Upon its first invocation, this function walks the corpora
1893/// contained in the corpus group and caches the variables they
1894/// export.
1895///
1896/// @return the exported variables.
1897const corpus::variables&
1899{
1900 if (priv_->vars.empty())
1901 for (corpora_type::const_iterator i = get_corpora().begin();
1902 i != get_corpora().end();
1903 ++i)
1904 {
1905 corpus_sptr c = *i;
1906 for (corpus::variables::const_iterator v = c->get_variables().begin();
1907 v != c->get_variables().end();
1908 ++v)
1909 {
1910 interned_string vid = (*v)->get_id();
1911 istring_var_decl_ptr_map_type::const_iterator j =
1912 priv_->vars_map.find(vid);
1913
1914 if (j != priv_->vars_map.end())
1915 // Don't cache the same variable twice ...
1916 continue;
1917
1918 priv_->vars_map[vid] = *v;
1919 // Really cache the variable now.
1920 priv_->vars.push_back(*v);
1921 }
1922 }
1923
1924 return priv_->vars;
1925}
1926
1927/// Get the symbols of the global variables exported by the corpora of
1928/// the current @ref corpus_group.
1929///
1930/// @return the symbols of the global variables exported by the corpora
1933{
1934 if (priv_->var_symbol_map.empty())
1935 for (corpora_type::const_iterator i = get_corpora().begin();
1936 i != get_corpora().end();
1937 ++i)
1938 priv_->var_symbol_map.insert((*i)->get_var_symbol_map().begin(),
1939 (*i)->get_var_symbol_map().end());
1940
1941 return priv_->var_symbol_map;
1942}
1943
1944/// Get the symbols of the global functions exported by the corpora of
1945/// the current @ref corpus_group.
1946///
1947/// @return the symbols of the global functions exported by the corpora
1950{
1951 if (priv_->fun_symbol_map.empty())
1952 for (corpora_type::const_iterator i = get_corpora().begin();
1953 i != get_corpora().end();
1954 ++i)
1955 priv_->fun_symbol_map.insert((*i)->get_fun_symbol_map().begin(),
1956 (*i)->get_fun_symbol_map().end());
1957
1958 return priv_->fun_symbol_map;
1959}
1960
1961/// Get a sorted vector of the symbols of the functions exported by
1962/// the corpora of the current group.
1963///
1964/// @return the sorted vectors of the exported function symbols.
1965const elf_symbols&
1967{
1968 if (priv_->sorted_fun_symbols.empty()
1969 && !get_fun_symbol_map().empty())
1970 {
1971 for (corpora_type::const_iterator i = get_corpora().begin();
1972 i != get_corpora().end();
1973 ++i)
1974 {
1975 corpus_sptr c = *i;
1976 for (string_elf_symbols_map_type::const_iterator j =
1977 c->get_fun_symbol_map().begin();
1978 j != c->get_fun_symbol_map().begin();
1979 ++j)
1980 priv_->sorted_fun_symbols.insert(priv_->sorted_fun_symbols.end(),
1981 j->second.begin(),
1982 j->second.end());
1983 }
1984 comp_elf_symbols_functor comp;
1985 std::sort(priv_->sorted_fun_symbols.begin(),
1986 priv_->sorted_fun_symbols.end(),
1987 comp);
1988 }
1989
1990 return priv_->sorted_fun_symbols;
1991}
1992
1993/// Get a sorted vector of the symbols of the variables exported by
1994/// the corpora of the current group.
1995///
1996/// @return the sorted vectors of the exported variable symbols.
1997const elf_symbols&
1999{
2000 if (priv_->sorted_var_symbols.empty()
2001 && !get_var_symbol_map().empty())
2002 {
2003 for (corpora_type::const_iterator i = get_corpora().begin();
2004 i != get_corpora().end();
2005 ++i)
2006 {
2007 corpus_sptr c = *i;
2008 for (string_elf_symbols_map_type::const_iterator j =
2009 c->get_var_symbol_map().begin();
2010 j != c->get_var_symbol_map().begin();
2011 ++j)
2012 priv_->sorted_var_symbols.insert(priv_->sorted_var_symbols.end(),
2013 j->second.begin(),
2014 j->second.end());
2015 }
2016 comp_elf_symbols_functor comp;
2017 std::sort(priv_->sorted_var_symbols.begin(),
2018 priv_->sorted_var_symbols.end(),
2019 comp);
2020 }
2021
2022 return priv_->sorted_var_symbols;
2023}
2024
2025/// Get the set of function symbols not referenced by any debug info,
2026/// from all the corpora of the current corpus group.
2027///
2028/// Upon its first invocation, this function possibly walks all the
2029/// copora of this corpus group and caches the unreferenced symbols
2030/// they export. The function then returns the cache.
2031///
2032/// Upon subsequent invocations, this functions just returns the
2033/// cached symbols.
2034///
2035/// @return the unreferenced symbols.
2036const elf_symbols&
2038{
2039 if (!priv_->unrefed_fun_symbols_built)
2040 if (priv_->unrefed_fun_symbols.empty())
2041 {
2042 for (corpora_type::const_iterator i = get_corpora().begin();
2043 i != get_corpora().end();
2044 ++i)
2045 {
2046 corpus_sptr c = *i;
2047 for (elf_symbols::const_iterator e =
2048 c->get_unreferenced_function_symbols().begin();
2049 e != c->get_unreferenced_function_symbols().end();
2050 ++e)
2051 {
2052 string sym_id = (*e)->get_id_string();
2053 unordered_map<string, elf_symbol_sptr>::const_iterator j =
2054 priv_->unrefed_fun_symbol_map.find(sym_id);
2055 if (j != priv_->unrefed_fun_symbol_map.end())
2056 continue;
2057
2058 priv_->unrefed_fun_symbol_map[sym_id] = *e;
2059 priv_->unrefed_fun_symbols.push_back(*e);
2060 }
2061 }
2062 priv_->unrefed_fun_symbols_built = true;
2063 }
2064
2065 return priv_->unrefed_fun_symbols;
2066}
2067
2068/// Get the set of variable symbols not referenced by any debug info,
2069/// from all the corpora of the current corpus group.
2070///
2071/// Upon its first invocation, this function possibly walks all the
2072/// copora of this corpus group and caches the unreferenced symbols
2073/// they export. The function then returns the cache.
2074///
2075/// Upon subsequent invocations, this functions just returns the
2076/// cached symbols.
2077///
2078/// @return the unreferenced symbols.
2079const elf_symbols&
2081{
2082 if (!priv_->unrefed_var_symbols_built)
2083 if (priv_->unrefed_var_symbols.empty())
2084 {
2085 for (corpora_type::const_iterator i = get_corpora().begin();
2086 i != get_corpora().end();
2087 ++i)
2088 {
2089 corpus_sptr c = *i;
2090 for (elf_symbols::const_iterator e =
2091 c->get_unreferenced_variable_symbols().begin();
2092 e != c->get_unreferenced_variable_symbols().end();
2093 ++e)
2094 {
2095 string sym_id = (*e)->get_id_string();
2096 unordered_map<string, elf_symbol_sptr>::const_iterator j =
2097 priv_->unrefed_var_symbol_map.find(sym_id);
2098 if (j != priv_->unrefed_var_symbol_map.end())
2099 continue;
2100
2101 priv_->unrefed_var_symbol_map[sym_id] = *e;
2102 priv_->unrefed_var_symbols.push_back(*e);
2103 }
2104 }
2105 priv_->unrefed_var_symbols_built = true;
2106 }
2107
2108 return priv_->unrefed_var_symbols;
2109}
2110
2111/// Getter of a pointer to the set of types reachable from public
2112/// interfaces of a given corpus group.
2113unordered_set<interned_string, hash_interned_string>*
2115{return &priv_->pub_type_pretty_reprs_;}
2116
2117/// Test if the recording of reachable types (and thus, indirectly,
2118/// the recording of non-reachable types) is activated for the
2119/// current @ref corpus_group.
2120///
2121/// @return true iff the recording of reachable types is activated for
2122/// the current @ref corpus_group.
2123bool
2125{return !get_public_types_pretty_representations()->empty();}
2126
2127// </corpus_group stuff>
2128
2129}// end namespace ir
2130}// end namespace abigail
The private data and functions of the abigail::ir::corpus type.
std::shared_ptr< symtab > symtab_sptr
Convenience typedef for a shared pointer to a symtab.
Definition: abg-fwd.h:1648
#define ABG_ASSERT(cond)
This is a wrapper around the 'assert' glibc call. It allows for its argument to have side effects,...
Definition: abg-fwd.h:1695
This contains the private implementation of the suppression engine of libabigail.
Types of the main internal representation of libabigail.
This file contains the declarations of the entry points to de-serialize an instance of abigail::trans...
Utilities to ease the wrapping of C types into std::shared_ptr.
This contains the declarations for the symtab reader.
#define ABG_ASSERT_NOT_REACHED
A macro that expands to aborting the program when executed.
This file contains the declarations of the entry points to de-serialize an instance of abigail::trans...
The abstraction of an interned string.
bool empty() const
Test if the current instance of interned_string is empty.
The type of the private data of corpus::exported_decls_builder type.
Abstracts the building of the set of exported variables and functions.
Definition: abg-corpus.h:307
const functions & exported_functions() const
Getter for the reference to the vector of exported functions. This vector is shared with with the cor...
Definition: abg-corpus.cc:101
void maybe_add_fn_to_exported_fns(function_decl *)
Consider at all the tunables that control wether a function should be added to the set of exported fu...
Definition: abg-corpus.cc:159
std::unordered_set< function_decl * > * fn_id_maps_to_several_fns(const function_decl *)
Test if a given function ID maps to several functions in the same corpus.
Definition: abg-corpus.cc:125
void maybe_add_var_to_exported_vars(const var_decl *)
Consider at all the tunables that control wether a variable should be added to the set of exported va...
Definition: abg-corpus.cc:182
const variables & exported_variables() const
Getter for the reference to the vector of exported variables. This vector is shared with with the cor...
Definition: abg-corpus.cc:141
Abstraction of a group of corpora.
Definition: abg-corpus.h:356
virtual const elf_symbols & get_sorted_var_symbols() const
Get a sorted vector of the symbols of the variables exported by the corpora of the current group.
Definition: abg-corpus.cc:1998
bool has_corpus(const string &)
Test if a corpus of a given path has been added to the group.
Definition: abg-corpus.cc:1810
const corpora_type & get_corpora() const
Getter of the vector of corpora held by the current corpus_group.
Definition: abg-corpus.cc:1822
unordered_set< interned_string, hash_interned_string > * get_public_types_pretty_representations()
Getter of a pointer to the set of types reachable from public interfaces of a given corpus group.
Definition: abg-corpus.cc:2114
virtual const string_elf_symbols_map_type & get_var_symbol_map() const
Get the symbols of the global variables exported by the corpora of the current corpus_group.
Definition: abg-corpus.cc:1932
virtual const elf_symbols & get_sorted_fun_symbols() const
Get a sorted vector of the symbols of the functions exported by the corpora of the current group.
Definition: abg-corpus.cc:1966
virtual bool is_empty() const
Test if the current corpus group is empty.
Definition: abg-corpus.cc:1847
virtual const string_elf_symbols_map_type & get_fun_symbol_map() const
Get the symbols of the global functions exported by the corpora of the current corpus_group.
Definition: abg-corpus.cc:1949
const corpus_sptr get_main_corpus() const
Getter of the first corpus added to this Group.
Definition: abg-corpus.cc:1829
virtual const elf_symbols & get_unreferenced_function_symbols() const
Get the set of function symbols not referenced by any debug info, from all the corpora of the current...
Definition: abg-corpus.cc:2037
virtual const elf_symbols & get_unreferenced_variable_symbols() const
Get the set of variable symbols not referenced by any debug info, from all the corpora of the current...
Definition: abg-corpus.cc:2080
virtual bool recording_types_reachable_from_public_interface_supported()
Test if the recording of reachable types (and thus, indirectly, the recording of non-reachable types)...
Definition: abg-corpus.cc:2124
virtual const corpus::variables & get_variables() const
Get the global variables exported by the corpora of the current corpus group.
Definition: abg-corpus.cc:1898
virtual ~corpus_group()
Desctructor of the corpus_group type.
Definition: abg-corpus.cc:1764
void add_corpus(const corpus_sptr &)
Add a new corpus to the current instance of corpus_group.
Definition: abg-corpus.cc:1771
virtual const corpus::functions & get_functions() const
Get the functions exported by the corpora of the current corpus group.
Definition: abg-corpus.cc:1860
This is the abstraction of a set of translation units (themselves seen as bundles of unitary abi arte...
Definition: abg-corpus.h:25
virtual const elf_symbols & get_sorted_var_symbols() const
Getter for the sorted vector of variable symbols for this corpus.
Definition: abg-corpus.cc:1160
const elf_symbol_sptr lookup_function_symbol(const string &n) const
Look in the function symbols map for a symbol with a given name.
Definition: abg-corpus.cc:1195
origin
This abstracts where the corpus comes from. That is, either it has been read from the native xml form...
Definition: abg-corpus.h:45
void sort_functions()
Sort the set of functions exported by this corpus.
Definition: abg-corpus.cc:1387
void set_soname(const string &)
Setter for the soname property of the corpus.
Definition: abg-corpus.cc:1024
vector< const var_decl * > variables
Convenience typedef for std::vector<abigail::ir::var_decl*>
Definition: abg-corpus.h:34
const vector< type_base_wptr > & get_types_not_reachable_from_public_interfaces() const
Getter of a sorted vector of the types that are *NOT* reachable from public interfaces.
Definition: abg-corpus.cc:841
void record_type_as_reachable_from_public_interfaces(const type_base &)
Record a type as being reachable from public interfaces (global functions and variables).
Definition: abg-corpus.cc:803
const vector< string > & get_needed() const
Getter of the needed property of the corpus.
Definition: abg-corpus.cc:990
exported_decls_builder_sptr get_exported_decls_builder() const
Getter for the object that is responsible for determining what decls ought to be in the set of export...
Definition: abg-corpus.cc:1606
void maybe_drop_some_exported_decls()
After the set of exported functions and variables have been built, consider all the tunables that con...
Definition: abg-corpus.cc:1569
const string_elf_symbols_map_type & get_undefined_var_symbol_map() const
Getter for the map of variable symbols that are undefined in this corpus.
Definition: abg-corpus.cc:1186
void add(const translation_unit_sptr &)
Add a translation unit to the current ABI Corpus.
Definition: abg-corpus.cc:709
virtual const string_elf_symbols_map_type & get_var_symbol_map() const
Getter for the variable symbols map.
Definition: abg-corpus.cc:1176
shared_ptr< exported_decls_builder > exported_decls_builder_sptr
Convenience typedef for shared_ptr<exported_decls_builder>.
Definition: abg-corpus.h:39
const elf_symbol_sptr lookup_variable_symbol(const string &n) const
Look in the variable symbols map for a symbol with a given name.
Definition: abg-corpus.cc:1291
virtual const elf_symbols & get_sorted_fun_symbols() const
Return a sorted vector of function symbols for this corpus.
Definition: abg-corpus.cc:1140
const string & get_soname()
Getter for the soname property of the corpus.
Definition: abg-corpus.cc:1013
const translation_units & get_translation_units() const
Return the list of translation units of the current corpus.
Definition: abg-corpus.cc:729
const symtab_reader::symtab_sptr & get_symtab() const
Getter for the symtab object.
Definition: abg-corpus.cc:1112
origin get_origin() const
Getter for the origin of the corpus.
Definition: abg-corpus.cc:914
virtual bool is_empty() const
Tests if the corpus is empty from an ABI surface perspective. I.e. if all of these criteria are true:
Definition: abg-corpus.cc:1059
type_maps & get_types()
Get the maps that associate a name to a certain kind of type.
Definition: abg-corpus.cc:761
vector< string > & get_sym_ids_of_vars_to_keep()
Getter for the vector of variable symbol IDs to keep.
Definition: abg-corpus.cc:1552
bool do_log() const
Test if logging was requested.
Definition: abg-corpus.cc:691
const translation_unit_sptr find_translation_unit(const string &path) const
Find the translation unit that has a given path.
Definition: abg-corpus.cc:739
const elf_symbols & get_sorted_undefined_fun_symbols() const
Getter for a sorted vector of the function symbols undefined in this corpus.
Definition: abg-corpus.cc:1149
string & get_path() const
Get the file path associated to the corpus file.
Definition: abg-corpus.cc:967
const string_elf_symbols_map_type & get_undefined_fun_symbol_map() const
Getter for the map of function symbols that are undefined in this corpus.
Definition: abg-corpus.cc:1129
void set_origin(origin)
Setter for the origin of the corpus.
Definition: abg-corpus.cc:921
virtual const string_elf_symbols_map_type & get_fun_symbol_map() const
Getter for the function symbols map.
Definition: abg-corpus.cc:1119
bool operator==(const corpus &) const
Compare the current corpus against another one.
Definition: abg-corpus.cc:1086
type_maps & get_type_per_loc_map()
Get the maps that associate a location string to a certain kind of type.
Definition: abg-corpus.cc:870
void drop_translation_units()
Erase the translation units contained in this in-memory object.
Definition: abg-corpus.cc:754
void sort_variables()
Sort the set of variables exported by this corpus.
Definition: abg-corpus.cc:1417
vector< string > & get_regex_patterns_of_vars_to_keep()
Accessor for the regex patterns describing the variables to keep into the public decl table....
Definition: abg-corpus.cc:1532
vector< string > & get_regex_patterns_of_vars_to_suppress()
Accessor for the regex patterns describing the variables to drop from the public decl table.
Definition: abg-corpus.cc:1473
const corpus_group * get_group() const
Getter of the group this corpus is a member of.
Definition: abg-corpus.cc:878
vector< string > & get_regex_patterns_of_fns_to_suppress()
Accessor for the regex patterns describing the functions to drop from the public decl table.
Definition: abg-corpus.cc:1455
virtual const elf_symbols & get_unreferenced_function_symbols() const
Getter of the set of function symbols that are not referenced by any function exported by the current...
Definition: abg-corpus.cc:1433
void set_path(const string &)
Set the file path associated to the corpus file.
Definition: abg-corpus.cc:979
virtual const elf_symbols & get_unreferenced_variable_symbols() const
Getter of the set of variable symbols that are not referenced by any variable exported by the current...
Definition: abg-corpus.cc:1446
bool type_is_reachable_from_public_interfaces(const type_base &) const
Test if a type is reachable from public interfaces (global functions and variables).
Definition: abg-corpus.cc:821
virtual bool recording_types_reachable_from_public_interface_supported()
Test if the recording of reachable types (and thus, indirectly, the recording of non-reachable types)...
Definition: abg-corpus.cc:792
virtual const variables & get_variables() const
Return the public decl table of the global variables of the current corpus.
Definition: abg-corpus.cc:1409
const elf_symbols & get_sorted_undefined_var_symbols() const
Getter for a sorted vector of the variable symbols undefined in this corpus.
Definition: abg-corpus.cc:1169
void set_needed(const vector< string > &)
Setter of the needed property of the corpus.
Definition: abg-corpus.cc:1002
vector< string > & get_sym_ids_of_fns_to_keep()
Getter for the vector of function symbol IDs to keep.
Definition: abg-corpus.cc:1512
vector< const function_decl * > functions
Convenience typedef for std::vector<abigail::ir::function_decl*>
Definition: abg-corpus.h:31
void set_architecture_name(const string &)
Setter for the architecture name of the corpus.
Definition: abg-corpus.cc:1046
void set_symtab(symtab_reader::symtab_sptr)
Setter for the symtab object.
Definition: abg-corpus.cc:1105
void set_format_major_version_number(const string &)
Setter of the major version number of the abixml serialization format.
Definition: abg-corpus.cc:937
const string & get_architecture_name() const
Getter for the architecture name of the corpus.
Definition: abg-corpus.cc:1035
vector< string > strings_type
A convenience typedef for std::vector<string>.
Definition: abg-corpus.h:28
const environment & get_environment() const
Getter of the enviroment of the corpus.
Definition: abg-corpus.cc:684
vector< string > & get_regex_patterns_of_fns_to_keep()
Accessor for the regex patterns describing the functions to keep into the public decl table....
Definition: abg-corpus.cc:1492
void set_format_minor_version_number(const string &)
Setter of the minor version number of the abixml serialization format.
Definition: abg-corpus.cc:955
string & get_format_minor_version_number() const
Getter of the minor version number of the abixml serialization format.
Definition: abg-corpus.cc:946
const std::unordered_set< function_decl * > * lookup_functions(const interned_string &id) const
Lookup the function which has a given function ID.
Definition: abg-corpus.cc:1369
virtual const functions & get_functions() const
Return the functions public decl table of the current corpus.
Definition: abg-corpus.cc:1351
string & get_format_major_version_number() const
Getter of the major version number of the abixml serialization format.
Definition: abg-corpus.cc:929
const interned_string & get_name() const
Getter for the name of the current decl.
Definition: abg-ir.cc:5044
const interned_string & get_linkage_name() const
Getter for the mangled name.
Definition: abg-ir.cc:4993
bool get_is_in_public_symbol_table() const
Test if the decl is defined in a ELF symbol table as a public symbol.
Definition: abg-ir.cc:4810
The abstraction of the version of an ELF symbol.
Definition: abg-ir.h:1194
const string & str() const
Getter for the version name.
Definition: abg-ir.cc:3110
Abstraction of an elf symbol.
Definition: abg-ir.h:923
const string & get_name() const
Getter for the name of the elf_symbol.
Definition: abg-ir.cc:2070
version & get_version() const
Getter for the version of the current instanc of elf_symbol.
Definition: abg-ir.cc:2129
This is an abstraction of the set of resources necessary to manage several aspects of the internal re...
Definition: abg-ir.h:140
interned_string intern(const string &) const
Do intern a string.
Definition: abg-ir.cc:3876
Abstraction for a function declaration.
Definition: abg-ir.h:3111
An abstraction helper for type declarations.
Definition: abg-ir.h:1973
This is a type that aggregates maps of all the kinds of types that are supported by libabigail.
Definition: abg-ir.h:593
const vector< type_base_wptr > & get_types_sorted_by_name() const
Getter of all types types sorted by their pretty representation.
Definition: abg-ir.cc:1213
const environment & get_environment() const
Getter of the environment of the current ABI artifact.
Definition: abg-ir.cc:4415
Abstracts a variable declaration.
Definition: abg-ir.h:3008
virtual string get_pretty_representation(bool internal=false, bool qualified_name=true) const
Build and return the pretty representation of this variable.
Definition: abg-ir.cc:20994
Helper class to allow range-for loops on symtabs for C++11 and later code. It serves as a proxy for t...
corpus::origin operator|=(corpus::origin &l, corpus::origin r)
Bitwise |= operator for the corpus::origin type.
Definition: abg-corpus.cc:1645
shared_ptr< elf_symbol > elf_symbol_sptr
A convenience typedef for a shared pointer to elf_symbol.
Definition: abg-ir.h:888
string get_pretty_representation(const type_or_decl_base *tod, bool internal)
Build and return a copy of the pretty representation of an ABI artifact that could be either a type o...
Definition: abg-ir.cc:9332
std::vector< elf_symbol_sptr > elf_symbols
Convenience typedef for a vector of elf_symbol.
Definition: abg-ir.h:904
unordered_map< string, const function_decl * > str_fn_ptr_map_type
Convenience typedef for a hash map of string and pointer to function_decl.
Definition: abg-corpus.cc:210
corpus::origin operator|(corpus::origin l, corpus::origin r)
Bitwise | operator for the corpus::origin type.
Definition: abg-corpus.cc:1631
unordered_map< const function_decl *, bool, function_decl::hash, function_decl::ptr_equal > fn_ptr_map_type
Convenience typedef for a hash map of pointer to function_decl and boolean.
Definition: abg-corpus.cc:206
corpus::origin operator&(corpus::origin l, corpus::origin r)
Bitwise & operator for the corpus::origin type.
Definition: abg-corpus.cc:1659
shared_ptr< translation_unit > translation_unit_sptr
Convenience typedef for a shared pointer on a translation_unit type.
Definition: abg-fwd.h:137
unordered_map< const var_decl *, bool, var_decl::hash, var_decl::ptr_equal > var_ptr_map_type
Convenience typedef for a hash map of pointer to var_decl and boolean.
Definition: abg-corpus.cc:216
std::set< translation_unit_sptr, shared_translation_unit_comp > translation_units
Convenience typedef for an ordered set of translation_unit_sptr.
Definition: abg-ir.h:851
corpus::origin operator&=(corpus::origin &l, corpus::origin r)
Bitwise &= operator for the corpus::origin type.
Definition: abg-corpus.cc:1673
std::unordered_map< string, elf_symbols > string_elf_symbols_map_type
Convenience typedef for a map which key is a string and which value is a vector of elf_symbol.
Definition: abg-ir.h:909
std::shared_ptr< regex_t > regex_t_sptr
A convenience typedef for a shared pointer of regex_t.
Definition: abg-fwd.h:88
Toplevel namespace for libabigail.
A functor to compare instances of var_decl base on their qualified names.
The private data of the corpus type.
const elf_symbols & get_sorted_var_symbols() const
Getter for the sorted vector of variable symbols for this corpus.
Definition: abg-corpus.cc:479
const string_elf_symbols_map_type & get_undefined_var_symbol_map() const
Return a map from name to undefined variable symbol for this corpus.
Definition: abg-corpus.cc:550
unordered_set< interned_string, hash_interned_string > * get_public_types_pretty_representations()
Getter of the set of pretty representation of types that are reachable from public interfaces (global...
Definition: abg-corpus.cc:622
const string_elf_symbols_map_type & get_var_symbol_map() const
Return a map from name to variable symbol for this corpus.
Definition: abg-corpus.cc:505
const elf_symbols & get_sorted_fun_symbols() const
Return a sorted vector of function symbols for this corpus.
Definition: abg-corpus.cc:335
type_maps & get_types()
Get the maps that associate a name to a certain kind of type.
Definition: abg-corpus.cc:319
const elf_symbols & get_sorted_undefined_fun_symbols() const
Getter for a sorted vector of the function symbols undefined in this corpus.
Definition: abg-corpus.cc:377
const string_elf_symbols_map_type & get_undefined_fun_symbol_map() const
Return a map from name to undefined function symbol for this corpus.
Definition: abg-corpus.cc:405
const string_elf_symbols_map_type & get_fun_symbol_map() const
Return a map from name to function symbol for this corpus.
Definition: abg-corpus.cc:360
const elf_symbols & get_unreferenced_function_symbols() const
Return a list of symbols that are not referenced by any function of corpus::get_functions().
Definition: abg-corpus.cc:427
const elf_symbols & get_unreferenced_variable_symbols() const
Return a list of symbols that are not referenced by any variable of corpus::get_variables().
Definition: abg-corpus.cc:572
const elf_symbols & get_sorted_undefined_var_symbols() const
Getter for a sorted vector of the variable symbols undefined in this corpus.
Definition: abg-corpus.cc:522
std::unordered_set< function_decl * > * lookup_functions(const interned_string &id)
Lookup the function which has a given function ID.
Definition: abg-corpus.cc:648
~priv()
Destructor of the corpus::priv type.
Definition: abg-corpus.cc:662
A hashing functor fo instances and pointers of function_decl.
Definition: abg-ir.h:4851
Equality functor for instances of function_decl.
Definition: abg-ir.h:4861
A hashing functor for instances and pointers of var_decl.
Definition: abg-ir.h:4820
A comparison functor for pointers to var_decl.
Definition: abg-ir.h:4830