libabigail/include/abg-corpus.h
Dodji Seketeli 06279598c8 Support reading undefined symbols from an ELF file
In preparation to support the upcoming 'abicompat' tool, we need the
ABI corpus type to capture the symbols that are undefined in a given
ELF file.

This patch changes the ELF reader to capture the undefined symbols as
well as the symbol versions they need to be satisfied.  These
undefined symbols are then stored in the instance ABI corpus build as
a result of the reading of the ELF file.

At the moment, these undefined symbols are not serialized to the
native XML format of libabigail yet.  I guess I'll do that in a
subsequent patch.

	* include/abg-corpus.h (corpus::{set_undefined_fun_symbol_map,
	set_undefined_var_symbol_map, get_undefined_fun_symbol_map_sptr,
	get_undefined_fun_symbol_map, get_sorted_undefined_fun_symbols,
	get_undefined_var_symbol_map_sptr, get_undefined_var_symbol_map,
	get_sorted_undefined_var_symbols}): Declare new methods ...
	* src/abg-corpus.cc (corpus::{set_undefined_fun_symbol_map,
	set_undefined_var_symbol_map, get_undefined_fun_symbol_map_sptr,
	get_undefined_fun_symbol_map, get_sorted_undefined_fun_symbols,
	get_undefined_var_symbol_map_sptr, get_undefined_var_symbol_map,
	get_sorted_undefined_var_symbols}): ... and define them.
	(struct corpus::priv::{undefined_var_symbol_map,
	sorted_undefined_var_symbols, undefined_fun_symbol_map,
	sorted_undefined_fun_symbols}): New data members.
	* src/abg-dwarf-reader.cc (get_symbol_versionning_sections): Also
	return the SHT_GNU_verneed section.
	(get_version_needed_for_versym): New static function.
	(get_version_definition_for_versym): Factorize this function out
	of ..
	(get_version_for_symbol): ... this one.  Take a flag that says if
	we want the definition version or the needed version of a symbol.
	Extend the implementation using the two new function
	get_version_needed_for_versym() and
	get_version_definition_for_versym() above.  This function now
	returns the version either for a defined & exported symbol, or for
	an undefined symbol.
	(lookup_symbol_from_sysv_hash_tab)
	(lookup_symbol_from_gnu_hash_tab, lookup_symbol_from_symtab):
	Adjust for the change of signature of get_version_for_symbol().
	(read_context::{undefined_fun_syms_, undefined_var_syms_}): New
	data members.
	(read_context::lookup_elf_symbol_from_index): Adjust for
	invocation of the new signature of get_version_for_symbol().
	(read_context::{undefined_fun_syms_sptr, undefined_fun_syms,
	undefined_var_syms_sptr, undefined_var_syms}): Define new methods.
	(read_context::load_symbol_maps): Add support for loading
	undefined symbols and their versions.
	(read_context::maybe_load_symbol_maps):  Take in account the need
	to load undefined symbols as well.
	(read_corpus_from_elf): Once the undefined symbols have been read
	from the ELF file, stuff them into the resulting ABI corpus that
	has been built.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-30 19:57:05 +01:00

201 lines
4.5 KiB
C++

// -*- mode: C++ -*-
//
// Copyright (C) 2013-2014 Red Hat, Inc.
//
// This file is part of the GNU Application Binary Interface Generic
// Analysis and Instrumentation Library (libabigail). This library is
// free software; you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License as published by the
// Free Software Foundation; either version 3, or (at your option) any
// later version.
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this program; see the file COPYING-LGPLV3. If
// not, see <http://www.gnu.org/licenses/>.
/// @file
#ifndef __ABG_CORPUS_H__
#define __ABG_CORPUS_H__
#include <abg-ir.h>
namespace abigail
{
namespace ir
{
class corpus;
/// A convenience typedef for shared pointer to @ref corpus.
typedef shared_ptr<corpus> corpus_sptr;
/// This is the abstraction of a set of translation units (themselves
/// seen as bundles of unitary abi artefacts like types and decls)
/// bundled together as a corpus. A corpus is thus the Application
/// binary interface of a program, a library or just a set of modules
/// put together.
class corpus
{
public:
struct priv;
typedef shared_ptr<priv> priv_sptr;
typedef std::string string;
typedef vector<function_decl*> functions;
typedef vector<var_decl*> variables;
/// This abstracts where the corpus comes from. That is, either it
/// has been read from the native xml format, from DWARF or built
/// artificially using the library's API.
enum origin
{
ARTIFICIAL_ORIGIN = 0,
NATIVE_XML_ORIGIN,
DWARF_ORIGIN
};
private:
shared_ptr<priv> priv_;
corpus();
public:
corpus(const string&);
void
add(const translation_unit_sptr);
const translation_units&
get_translation_units() const;
void
drop_translation_units();
origin
get_origin() const;
void
set_origin(origin);
string&
get_path() const;
void
set_path(const string&);
bool
is_empty() const;
bool
operator==(const corpus&) const;
void
set_fun_symbol_map(string_elf_symbols_map_sptr);
void
set_undefined_fun_symbol_map(string_elf_symbols_map_sptr);
void
set_var_symbol_map(string_elf_symbols_map_sptr);
void
set_undefined_var_symbol_map(string_elf_symbols_map_sptr);
const string_elf_symbols_map_sptr
get_fun_symbol_map_sptr() const;
const string_elf_symbols_map_type&
get_fun_symbol_map() const;
const string_elf_symbols_map_sptr
get_undefined_fun_symbol_map_sptr() const;
const string_elf_symbols_map_type&
get_undefined_fun_symbol_map() const;
const elf_symbols&
get_sorted_fun_symbols() const;
const elf_symbols&
get_sorted_undefined_fun_symbols() const;
const string_elf_symbols_map_sptr
get_var_symbol_map_sptr() const;
const string_elf_symbols_map_type&
get_var_symbol_map() const;
const string_elf_symbols_map_sptr
get_undefined_var_symbol_map_sptr() const;
const string_elf_symbols_map_type&
get_undefined_var_symbol_map() const;
const elf_symbols&
get_sorted_var_symbols() const;
const elf_symbols&
get_sorted_undefined_var_symbols() const;
const elf_symbol_sptr
lookup_function_symbol(const string& n) const;
const elf_symbol_sptr
lookup_function_symbol(const string& symbol_name,
const string& symbol_version) const;
const elf_symbol_sptr
lookup_variable_symbol(const string& n) const;
const elf_symbol_sptr
lookup_variable_symbol(const string& symbol_name,
const string& symbol_version) const;
const functions&
get_functions() const;
const variables&
get_variables() const;
const elf_symbols&
get_unreferenced_function_symbols() const;
const elf_symbols&
get_unreferenced_variable_symbols() const;
vector<string>&
get_regex_patterns_of_fns_to_suppress();
const vector<string>&
get_regex_patterns_of_fns_to_suppress() const;
vector<string>&
get_regex_patterns_of_vars_to_suppress();
const vector<string>&
get_regex_patterns_of_vars_to_suppress() const;
vector<string>&
get_regex_patterns_of_fns_to_keep();
const vector<string>&
get_regex_patterns_of_fns_to_keep() const;
vector<string>&
get_regex_patterns_of_vars_to_keep();
const vector<string>&
get_regex_patterns_of_vars_to_keep() const;
};// end class corpus.
}// end namespace ir
}//end namespace abigail
#endif //__ABG_CORPUS_H__