libabigail
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
elf_symbol Class Reference

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 environmentget_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...
 
versionget_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...
 

Detailed Description

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.

Definition at line 922 of file abg-ir.h.

Member Enumeration Documentation

◆ binding

enum binding

The binding of a symbol.

Definition at line 939 of file abg-ir.h.

◆ type

enum type

The type of a symbol.

Definition at line 926 of file abg-ir.h.

◆ visibility

enum visibility

The visibility of the symbol.

Definition at line 948 of file abg-ir.h.

Member Function Documentation

◆ add_alias()

void add_alias ( const elf_symbol_sptr alias)

Add an alias to the current elf symbol.

Parameters
aliasthe new alias. Note that this elf_symbol should *NOT* have aliases prior to the invocation of this function.

Definition at line 2362 of file abg-ir.cc.

◆ add_common_instance()

void add_common_instance ( const elf_symbol_sptr common)

Add a common instance to the current common elf symbol.

Note that this symbol must be the main symbol. Being the main symbol means being the first common symbol to appear in the symbol table.

Parameters
commonthe other common instance to add.

Definition at line 2483 of file abg-ir.cc.

◆ create()

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 
)
static

Factory of instances of elf_symbol.

This is the function to use to create instances of elf_symbol.

Parameters
ethe environment we are operating from.
ithe index of the symbol in the (ELF) symbol table.
sthe size of the symbol.
nthe name of the symbol.
tthe type of the symbol.
bthe binding of the symbol.
dtrue if the symbol is defined, false otherwise.
ctrue if the symbol is a common symbol.
vethe version of the symbol.
vithe visibility of the symbol.
crcthe CRC (modversions) value of Linux Kernel symbols
nsthe namespace of Linux Kernel symbols, if any
Returns
a (smart) pointer to a newly created instance of elf_symbol.

Definition at line 1994 of file abg-ir.cc.

◆ does_alias()

bool does_alias ( const elf_symbol o) const

Test if the current symbol aliases another one.

Parameters
othe other symbol to test against.
Returns
true iff the current symbol aliases o.

Definition at line 2723 of file abg-ir.cc.

◆ get_alias_from_name()

elf_symbol_sptr get_alias_from_name ( const string &  name) const

From the aliases of the current symbol, lookup one with a given name.

Parameters
namethe name of symbol alias we are looking for.
Returns
the symbol alias that has the name name, or nil if none has been found.

Definition at line 2555 of file abg-ir.cc.

◆ get_alias_which_equals()

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.

Parameters
otherthe elf symbol to get the potential aliases from.
Returns
the alias of other that texually equals the current symbol, or nil if no alias textually equals the current symbol.

Definition at line 2577 of file abg-ir.cc.

◆ get_aliases_id_string() [1/2]

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.

Parameters
include_symbol_itselfif set to true, then the name of the current symbol is included in the list of alias names that is emitted.
Returns
the string.

Definition at line 2630 of file abg-ir.cc.

◆ get_aliases_id_string() [2/2]

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.

Parameters
symsa map of all the symbols of the corpus the current symbol belongs to.
include_symbol_itselfif set to true, then the name of the current symbol is included in the list of alias names that is emitted.
Returns
the string.

Definition at line 2598 of file abg-ir.cc.

◆ get_binding()

elf_symbol::binding get_binding ( ) const

Getter for the binding of the current instance of elf_symbol.

Returns
the binding of the symbol.

Definition at line 2116 of file abg-ir.cc.

◆ get_crc()

const abg_compat::optional< uint32_t > & get_crc ( ) const

Getter of the 'crc' property.

Returns
the CRC (modversions) value for Linux Kernel symbols, if any

Definition at line 2240 of file abg-ir.cc.

◆ get_environment()

const environment & get_environment ( ) const

Getter of the environment used by the current instance of elf_symbol.

Returns
the enviroment used by the current instance of elf_symbol.

Definition at line 2050 of file abg-ir.cc.

◆ get_id_string()

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.

Returns
a the ID string.

Definition at line 2528 of file abg-ir.cc.

◆ get_index()

size_t get_index ( ) const

Getter for the index.

Returns
the index of the symbol.

Definition at line 2057 of file abg-ir.cc.

◆ get_main_symbol() [1/2]

elf_symbol_sptr get_main_symbol ( )

Get the main symbol of an alias chain.

Returns
the main symbol.

Definition at line 2316 of file abg-ir.cc.

◆ get_main_symbol() [2/2]

const elf_symbol_sptr get_main_symbol ( ) const

Get the main symbol of an alias chain.

Returns
the main symbol.

Definition at line 2309 of file abg-ir.cc.

◆ get_name()

const string & get_name ( ) const

Getter for the name of the elf_symbol.

Returns
a reference to the name of the symbol.

Definition at line 2071 of file abg-ir.cc.

◆ get_name_and_version_from_id()

bool get_name_and_version_from_id ( const string &  id,
string &  name,
string &  ver 
)
static

Given the ID of a symbol, get the name and the version of said symbol.

Parameters
idthe symbol ID to consider.
namethe symbol name extracted from the ID. This is set only if the function returned true.
verthe symbol version extracted from the ID.

Definition at line 2664 of file abg-ir.cc.

◆ get_namespace()

const abg_compat::optional< std::string > & get_namespace ( ) const

Getter of the 'namespace' property.

Returns
the namespace for Linux Kernel symbols, if any

Definition at line 2254 of file abg-ir.cc.

◆ get_next_alias()

elf_symbol_sptr get_next_alias ( ) const

Get the next alias of the current symbol.

Returns
the alias, or NULL if there is no alias.

Definition at line 2330 of file abg-ir.cc.

◆ get_next_common_instance()

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.

Returns
the next common instance, or nil if there is not any.

Definition at line 2472 of file abg-ir.cc.

◆ get_number_of_aliases()

int get_number_of_aliases ( ) const

Get the number of aliases to this elf symbol.

Returns
the number of aliases to this elf symbol.

Definition at line 2345 of file abg-ir.cc.

◆ get_size()

size_t get_size ( ) const

Getter of the size of the symbol.

Returns
the size of the symbol, in bytes.

Definition at line 2102 of file abg-ir.cc.

◆ get_type()

elf_symbol::type get_type ( ) const

Getter for the type of the current instance of elf_symbol.

Returns
the type of the elf symbol.

Definition at line 2088 of file abg-ir.cc.

◆ get_version()

elf_symbol::version & get_version ( ) const

Getter for the version of the current instanc of elf_symbol.

Returns
the version of the elf symbol.

Definition at line 2130 of file abg-ir.cc.

◆ get_visibility()

elf_symbol::visibility get_visibility ( ) const

Getter of the visibility of the current instance of elf_symbol.

Returns
the visibility of the elf symbol.

Definition at line 2156 of file abg-ir.cc.

◆ has_aliases()

bool has_aliases ( ) const

Check if the current elf_symbol has an alias.

Returns
true iff the current elf_symbol has an alias.

Definition at line 2338 of file abg-ir.cc.

◆ has_other_common_instances()

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.

Returns
true iff the current common symbol has other common instances.

Definition at line 2457 of file abg-ir.cc.

◆ is_common_symbol()

bool is_common_symbol ( ) const

Return true if the symbol is a common one.

Returns
true iff the symbol is common.

Definition at line 2441 of file abg-ir.cc.

◆ is_defined() [1/2]

bool is_defined ( ) const

Test if the current instance of elf_symbol is defined or not.

Returns
true if the current instance of elf_symbol is defined, false otherwise.

Definition at line 2164 of file abg-ir.cc.

◆ is_defined() [2/2]

void is_defined ( bool  d)

Sets a flag saying if the current instance of elf_symbol is defined.

Parameters
bthe new value of the flag.

Definition at line 2172 of file abg-ir.cc.

◆ is_function()

bool is_function ( ) const

Test if the current instance of elf_symbol is a function symbol or not.

Returns
true if the current instance of elf_symbol is a function symbol, false otherwise.

Definition at line 2202 of file abg-ir.cc.

◆ is_in_ksymtab()

bool is_in_ksymtab ( ) const

Getter of the 'is-in-ksymtab' property.

Returns
true iff the current symbol is in the Linux Kernel specific 'ksymtab' symbol table.

Definition at line 2225 of file abg-ir.cc.

◆ is_main_symbol()

bool is_main_symbol ( ) const

Tests whether this symbol is the main symbol.

Returns
true iff this symbol is the main symbol.

Definition at line 2323 of file abg-ir.cc.

◆ is_public()

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:

  • has global binding
  • has weak binding
  • or has a GNU_UNIQUE binding.

return true if the current instance of elf_symbol is public, false otherwise.

Definition at line 2186 of file abg-ir.cc.

◆ is_suppressed()

bool is_suppressed ( ) const

Getter for the 'is-suppressed' property.

Returns
true iff the current symbol has been suppressed by a suppression specification that was provided in the context that led to the creation of the corpus this ELF symbol belongs to.

Definition at line 2270 of file abg-ir.cc.

◆ is_variable()

bool is_variable ( ) const

Test if the current instance of elf_symbol is a variable symbol or not.

Returns
true if the current instance of elf_symbol is a variable symbol, false otherwise.

Definition at line 2211 of file abg-ir.cc.

◆ operator==()

bool operator== ( const elf_symbol other) const

Test if two main symbols are textually equal, or, if they have aliases that are textually equal.

Parameters
otherthe symbol to compare against.
Returns
true iff the current instance of elf symbol equals the other.

Definition at line 2709 of file abg-ir.cc.

◆ set_binding()

void set_binding ( binding  b)

Setter for the binding of the current instance of elf_symbol.

Parameters
bthe new binding.

Definition at line 2123 of file abg-ir.cc.

◆ set_crc()

void set_crc ( const abg_compat::optional< uint32_t > &  crc)

Setter of the 'crc' property.

Parameters
crcthe new CRC (modversions) value for Linux Kernel symbols

Definition at line 2247 of file abg-ir.cc.

◆ set_index()

void set_index ( size_t  s)

Setter for the index.

Parameters
sthe new index.

Definition at line 2064 of file abg-ir.cc.

◆ set_is_in_ksymtab()

void set_is_in_ksymtab ( bool  is_in_ksymtab)

Setter of the 'is-in-ksymtab' property.

Parameters
is_in_ksymtabthis is true iff the current symbol is in the Linux Kernel specific 'ksymtab' symbol table.

Definition at line 2233 of file abg-ir.cc.

◆ set_is_suppressed()

void set_is_suppressed ( bool  is_suppressed)

Setter for the 'is-suppressed' property.

Parameters
trueiff the current symbol has been suppressed by a suppression specification that was provided in the context that led to the creation of the corpus this ELF symbol belongs to.

Definition at line 2279 of file abg-ir.cc.

◆ set_name()

void set_name ( const string &  n)

Setter for the name of the current intance of elf_symbol.

Parameters
nthe new name.

Definition at line 2078 of file abg-ir.cc.

◆ set_namespace()

void set_namespace ( const abg_compat::optional< std::string > &  ns)

Setter of the 'namespace' property.

Parameters
nsthe new namespace for Linux Kernel symbols, if any

Definition at line 2261 of file abg-ir.cc.

◆ set_size()

void set_size ( size_t  size)

Setter of the size of the symbol.

Parameters
sizethe new size of the symbol, in bytes.

Definition at line 2109 of file abg-ir.cc.

◆ set_type()

void set_type ( type  t)

Setter for the type of the current instance of elf_symbol.

Parameters
tthe new symbol type.

Definition at line 2095 of file abg-ir.cc.

◆ set_version()

void set_version ( const version v)

Setter for the version of the current instance of elf_symbol.

Parameters
vthe new version of the elf symbol.

Definition at line 2137 of file abg-ir.cc.

◆ set_visibility()

void set_visibility ( visibility  v)

Setter of the visibility of the current instance of elf_symbol.

Parameters
vthe new visibility of the elf symbol.

Definition at line 2148 of file abg-ir.cc.

◆ update_main_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.

Parameters
namethe name of the main symbol
Returns
the new main elf_symbol

Definition at line 2408 of file abg-ir.cc.


The documentation for this class was generated from the following files: