libabigail
|
Abstraction of an elf symbol. More...
#include <abg-ir.h>
Classes | |
class | version |
The abstraction of the version of an ELF symbol. More... | |
Public Types | |
enum | binding { LOCAL_BINDING , GLOBAL_BINDING , WEAK_BINDING , GNU_UNIQUE_BINDING } |
The binding of a symbol. More... | |
enum | type { NOTYPE_TYPE , OBJECT_TYPE , FUNC_TYPE , SECTION_TYPE , FILE_TYPE , COMMON_TYPE , TLS_TYPE , GNU_IFUNC_TYPE } |
The type of a symbol. More... | |
enum | visibility { DEFAULT_VISIBILITY , PROTECTED_VISIBILITY , HIDDEN_VISIBILITY , INTERNAL_VISIBILITY } |
The visibility of the symbol. More... | |
Public Member Functions | |
bool | does_alias (const elf_symbol &) const |
Test if the current symbol aliases another one. More... | |
elf_symbol_sptr | get_alias_with_default_symbol_version () const |
binding | get_binding () const |
Getter for the binding of the current instance of elf_symbol. More... | |
const abg_compat::optional< uint32_t > & | get_crc () const |
Getter of the 'crc' property. More... | |
const environment & | get_environment () const |
Getter of the environment used by the current instance of elf_symbol. More... | |
size_t | get_index () const |
Getter for the index. More... | |
const string & | get_name () const |
Getter for the name of the elf_symbol. More... | |
const abg_compat::optional< std::string > & | get_namespace () const |
Getter of the 'namespace' property. More... | |
size_t | get_size () const |
Getter of the size of the symbol. More... | |
type | get_type () const |
Getter for the type of the current instance of elf_symbol. More... | |
version & | get_version () const |
Getter for the version of the current instanc of elf_symbol. More... | |
visibility | get_visibility () const |
Getter of the visibility of the current instance of elf_symbol. More... | |
bool | is_defined () const |
Test if the current instance of elf_symbol is defined or not. More... | |
void | is_defined (bool d) |
Sets a flag saying if the current instance of elf_symbol is defined. More... | |
bool | is_function () const |
Test if the current instance of elf_symbol is a function symbol or not. More... | |
bool | is_in_ksymtab () const |
Getter of the 'is-in-ksymtab' property. More... | |
bool | is_public () const |
Test if the current instance of elf_symbol is public or not. More... | |
bool | is_suppressed () const |
Getter for the 'is-suppressed' property. More... | |
bool | is_variable () const |
Test if the current instance of elf_symbol is a variable symbol or not. More... | |
bool | operator== (const elf_symbol &) const |
Test if two main symbols are textually equal, or, if they have aliases that are textually equal. More... | |
void | set_binding (binding b) |
Setter for the binding of the current instance of elf_symbol. More... | |
void | set_crc (const abg_compat::optional< uint32_t > &crc) |
Setter of the 'crc' property. More... | |
void | set_index (size_t) |
Setter for the index. More... | |
void | set_is_in_ksymtab (bool is_in_ksymtab) |
Setter of the 'is-in-ksymtab' property. More... | |
void | set_is_suppressed (bool is_suppressed) |
Setter for the 'is-suppressed' property. More... | |
void | set_name (const string &n) |
Setter for the name of the current intance of elf_symbol. More... | |
void | set_namespace (const abg_compat::optional< std::string > &ns) |
Setter of the 'namespace' property. More... | |
void | set_size (size_t) |
Setter of the size of the symbol. More... | |
void | set_type (type t) |
Setter for the type of the current instance of elf_symbol. More... | |
void | set_version (const version &v) |
Setter for the version of the current instance of elf_symbol. More... | |
void | set_visibility (visibility v) |
Setter of the visibility of the current instance of elf_symbol. More... | |
Static Public Member Functions | |
static elf_symbol_sptr | create (const environment &e, size_t i, size_t s, const string &n, type t, binding b, bool d, bool c, const version &ve, visibility vi, bool is_in_ksymtab=false, const abg_compat::optional< uint32_t > &crc={}, const abg_compat::optional< std::string > &ns={}, bool is_suppressed=false) |
Factory of instances of elf_symbol. More... | |
Elf symbol aliases | |
An alias A for an elf symbol S is a symbol that is defined at the same address as S. S is chained to A through the elf_symbol::get_next_alias() method. When there are several aliases to a symbol, the main symbol is the the first symbol found in the symbol table for a given address. The alias chain is circular. That means if S is the main symbol and A is the alias, S is chained to A and A is chained back to the main symbol S. The last alias in an alias chain is always chained to the main symbol. Thus, when looping over the aliases of an elf_symbol A, detecting an alias that is equal to the main symbol should logically be a loop exit condition. Accessing and adding aliases for instances of elf_symbol is done through the member functions below. | |
static bool | get_name_and_version_from_id (const string &id, string &name, string &ver) |
Given the ID of a symbol, get the name and the version of said symbol. More... | |
const elf_symbol_sptr | get_main_symbol () const |
Get the main symbol of an alias chain. More... | |
elf_symbol_sptr | get_main_symbol () |
Get the main symbol of an alias chain. More... | |
bool | is_main_symbol () const |
Tests whether this symbol is the main symbol. More... | |
elf_symbol_sptr | update_main_symbol (const std::string &) |
Update the main symbol for a group of aliased symbols. More... | |
elf_symbol_sptr | get_next_alias () const |
Get the next alias of the current symbol. More... | |
bool | has_aliases () const |
Check if the current elf_symbol has an alias. More... | |
int | get_number_of_aliases () const |
Get the number of aliases to this elf symbol. More... | |
void | add_alias (const elf_symbol_sptr &) |
Add an alias to the current elf symbol. More... | |
bool | is_common_symbol () const |
Return true if the symbol is a common one. More... | |
bool | has_other_common_instances () const |
Return true if this common common symbol has other common instances. More... | |
elf_symbol_sptr | get_next_common_instance () const |
Get the next common instance of the current common symbol. More... | |
void | add_common_instance (const elf_symbol_sptr &) |
Add a common instance to the current common elf symbol. More... | |
const string & | get_id_string () const |
Get a string that is representative of a given elf_symbol. More... | |
elf_symbol_sptr | get_alias_from_name (const string &name) const |
From the aliases of the current symbol, lookup one with a given name. More... | |
elf_symbol_sptr | get_alias_which_equals (const elf_symbol &other) const |
In the list of aliases of a given elf symbol, get the alias that equals this current symbol. More... | |
string | get_aliases_id_string (const string_elf_symbols_map_type &symtab, bool include_symbol_itself=true) const |
Return a comma separated list of the id of the current symbol as well as the id string of its aliases. More... | |
string | get_aliases_id_string (bool include_symbol_itself=true) const |
Return a comma separated list of the id of the current symbol as well as the id string of its aliases. More... | |
Abstraction of an elf symbol.
This is useful when a given corpus has been read from an ELF file. In that case, a given decl might be associated to its underlying ELF symbol, if that decl is publicly exported in the ELF file. In that case, comparing decls might involve comparing their underlying symbols as well.
enum visibility |
void add_alias | ( | const elf_symbol_sptr & | alias | ) |
Add an alias to the current elf symbol.
alias | the new alias. Note that this elf_symbol should *NOT* have aliases prior to the invocation of this function. |
void add_common_instance | ( | const elf_symbol_sptr & | common | ) |
|
static |
Factory of instances of elf_symbol.
This is the function to use to create instances of elf_symbol.
e | the environment we are operating from. |
i | the index of the symbol in the (ELF) symbol table. |
s | the size of the symbol. |
n | the name of the symbol. |
t | the type of the symbol. |
b | the binding of the symbol. |
d | true if the symbol is defined, false otherwise. |
c | true if the symbol is a common symbol. |
ve | the version of the symbol. |
vi | the visibility of the symbol. |
crc | the CRC (modversions) value of Linux Kernel symbols |
ns | the namespace of Linux Kernel symbols, if any |
bool does_alias | ( | const elf_symbol & | o | ) | const |
elf_symbol_sptr get_alias_from_name | ( | const string & | name | ) | const |
elf_symbol_sptr get_alias_which_equals | ( | const elf_symbol & | other | ) | const |
In the list of aliases of a given elf symbol, get the alias that equals this current symbol.
other | the elf symbol to get the potential aliases from. |
other
that texually equals the current symbol, or nil if no alias textually equals the current symbol. string get_aliases_id_string | ( | bool | include_symbol_itself = true | ) | const |
Return a comma separated list of the id of the current symbol as well as the id string of its aliases.
include_symbol_itself | if set to true, then the name of the current symbol is included in the list of alias names that is emitted. |
string get_aliases_id_string | ( | const string_elf_symbols_map_type & | syms, |
bool | include_symbol_itself = true |
||
) | const |
Return a comma separated list of the id of the current symbol as well as the id string of its aliases.
syms | a map of all the symbols of the corpus the current symbol belongs to. |
include_symbol_itself | if set to true, then the name of the current symbol is included in the list of alias names that is emitted. |
elf_symbol::binding get_binding | ( | ) | const |
Getter for the binding of the current instance of elf_symbol.
const abg_compat::optional< uint32_t > & get_crc | ( | ) | const |
const environment & get_environment | ( | ) | const |
Getter of the environment used by the current instance of elf_symbol.
const string & get_id_string | ( | ) | const |
Get a string that is representative of a given elf_symbol.
If the symbol has a version, then the ID string is the concatenation of the name of the symbol, the '@' character, and the version of the symbol. If the version is the default version of the symbol then the '@' character is replaced by a "@@" string.
Otherwise, if the symbol does not have any version, this function returns the name of the symbol.
size_t get_index | ( | ) | const |
elf_symbol_sptr get_main_symbol | ( | ) |
const elf_symbol_sptr get_main_symbol | ( | ) | const |
const string & get_name | ( | ) | const |
Getter for the name of the elf_symbol.
|
static |
const abg_compat::optional< std::string > & get_namespace | ( | ) | const |
elf_symbol_sptr get_next_alias | ( | ) | const |
elf_symbol_sptr get_next_common_instance | ( | ) | const |
Get the next common instance of the current common symbol.
A common instance of a given common symbol is another common symbol with the same name. Those exist in relocatable files. The linker normally allocates all the instances into a common block in the final output file.
int get_number_of_aliases | ( | ) | const |
size_t get_size | ( | ) | const |
elf_symbol::type get_type | ( | ) | const |
Getter for the type of the current instance of elf_symbol.
elf_symbol::version & get_version | ( | ) | const |
Getter for the version of the current instanc of elf_symbol.
elf_symbol::visibility get_visibility | ( | ) | const |
Getter of the visibility of the current instance of elf_symbol.
bool has_aliases | ( | ) | const |
Check if the current elf_symbol has an alias.
bool has_other_common_instances | ( | ) | const |
Return true if this common common symbol has other common instances.
A common instance of a given common symbol is another common symbol with the same name. Those exist in relocatable files. The linker normally allocates all the instances into a common block in the final output file.
Note that the current object must be a common symbol, otherwise, this function aborts.
bool is_common_symbol | ( | ) | const |
bool is_defined | ( | ) | const |
Test if the current instance of elf_symbol is defined or not.
void is_defined | ( | bool | d | ) |
Sets a flag saying if the current instance of elf_symbol is defined.
b | the new value of the flag. |
bool is_function | ( | ) | const |
Test if the current instance of elf_symbol is a function symbol or not.
bool is_in_ksymtab | ( | ) | const |
bool is_main_symbol | ( | ) | const |
bool is_public | ( | ) | const |
Test if the current instance of elf_symbol is public or not.
This tests if the symbol is defined, has default or protected visibility, and either:
return true if the current instance of elf_symbol is public, false otherwise.
bool is_suppressed | ( | ) | const |
bool is_variable | ( | ) | const |
Test if the current instance of elf_symbol is a variable symbol or not.
bool operator== | ( | const elf_symbol & | other | ) | const |
void set_binding | ( | binding | b | ) |
Setter for the binding of the current instance of elf_symbol.
b | the new binding. |
void set_crc | ( | const abg_compat::optional< uint32_t > & | crc | ) |
void set_index | ( | size_t | s | ) |
void set_is_in_ksymtab | ( | bool | is_in_ksymtab | ) |
void set_is_suppressed | ( | bool | is_suppressed | ) |
void set_name | ( | const string & | n | ) |
Setter for the name of the current intance of elf_symbol.
n | the new name. |
void set_namespace | ( | const abg_compat::optional< std::string > & | ns | ) |
void set_size | ( | size_t | size | ) |
void set_type | ( | type | t | ) |
Setter for the type of the current instance of elf_symbol.
t | the new symbol type. |
void set_version | ( | const version & | v | ) |
Setter for the version of the current instance of elf_symbol.
v | the new version of the elf symbol. |
void set_visibility | ( | visibility | v | ) |
Setter of the visibility of the current instance of elf_symbol.
v | the new visibility of the elf symbol. |
elf_symbol_sptr update_main_symbol | ( | const std::string & | name | ) |
Update the main symbol for a group of aliased symbols.
If after the construction of the symbols (in order of discovery), the actual main symbol can be identified (e.g. as the symbol that actually is defined in the code), this method offers a way of updating the main symbol through one of the aliased symbols.
For that, locate the new main symbol by name and update all references to the main symbol among the group of aliased symbols.
name | the name of the main symbol |