libabigail
Loading...
Searching...
No Matches
abg-elf-reader.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2// -*- Mode: C++ -*-
3//
4// Copyright (C) 2022-2023 Red Hat, Inc.
5//
6// Author: Dodji Seketeli
7
8/// @file
9///
10/// This file contains the declarations for the @ref fe_iface a.k.a
11/// "Front End Interface".
12
13#ifndef __ABG_ELF_READER_H__
14#define __ABG_ELF_READER_H__
15
16#include <memory>
17#include <string>
18
19#include <elfutils/libdwfl.h>
20
21#include "abg-fe-iface.h"
22#include "abg-ir.h"
23#include "abg-suppression.h"
24
25namespace abigail
26{
27
28/// The namespace for the ELF Reader.
29namespace elf
30{
31
32/// The kind of ELF file we are looking at.
33enum elf_type : unsigned
34{
35 /// A normal executable binary
37 /// A Position Independant Executable binary
39 /// A dynamic shared object, a.k.a shared library binary.
41 /// A relocatalbe binary.
43 /// An unknown kind of binary.
45};
46
47/// This is the interface an ELF reader.
48///
49/// It knows how to open an ELF file, read its content and expose an
50/// interface for its symbol table and other properties.
51///
52/// Note that the ABI corpus returned by the elf::read_corpus()
53/// member function doesn't contain any type representation. It only
54/// contains the representations of the the ELF symbols found in the
55/// ELF file.
56///
57/// To construct the type representations for the functions and global
58/// variables present in the ELF file, please use the implementations
59/// of the @ref elf_based_reader interface. Those know how to read
60/// the debug information from the ELF file to build type
61/// representation in the @ref abigail::ir::corpus instance.
62class reader : public fe_iface
63{
64 struct priv;
65 priv *priv_;
66
67 public:
68
69 reader(const std::string& elf_path,
70 const vector<char**>& debug_info_roots,
71 environment& env);
72
73 ~reader();
74
75 void
76 reset(const std::string& elf_path,
77 const vector<char**>& debug_info_roots);
78
79 const vector<char**>&
81
82 const Dwfl_Callbacks&
84
85 Dwfl_Callbacks&
87
88 Elf*
89 elf_handle() const;
90
91 const Dwarf*
92 dwarf_debug_info() const;
93
94 bool
96
97 bool
98 has_ctf_debug_info() const;
99
100 bool
101 has_btf_debug_info() const;
102
103 const Dwarf*
105
106 const string&
108
109 bool
110 refers_to_alt_debug_info(string& alt_di_path) const;
111
112 const Elf_Scn*
114
115 void
117
118 const Elf_Scn*
119 find_ctf_section() const;
120
121 const Elf_Scn*
123
124 const Elf_Scn*
125 find_btf_section() const;
126
127 const vector<string>&
128 dt_needed()const;
129
130 const string&
131 elf_architecture() const;
132
134 symtab() const;
135
137 function_symbol_is_exported(GElf_Addr symbol_address) const;
138
140 variable_symbol_is_exported(GElf_Addr symbol_address) const;
141
143 function_symbol_is_exported(const string& name) const;
144
146 variable_symbol_is_exported(const string& name) const;
147
148 void
150
151 void
153
154 void
156
157 virtual ir::corpus_sptr
159};//end class reader.
160
161/// A convenience typedef for a smart pointer to a
162/// elf::reader.
163typedef shared_ptr<elf::reader> reader_sptr;
164
165bool
166get_soname_of_elf_file(const string& path, string &soname);
167
168bool
169get_type_of_elf_file(const string& path, elf_type& type);
170} // end namespace elf.
171} // end namespace abigail
172
173#endif // __ABG_ELF_READER_H__
This file contains the declarations for the fe_iface a.k.a "Front End Interface".
std::shared_ptr< symtab > symtab_sptr
Convenience typedef for a shared pointer to a symtab.
Definition: abg-fwd.h:1542
Types of the main internal representation of libabigail.
This is the interface an ELF reader.
const string & alternate_dwarf_debug_info_path() const
Getter of the path to the alternate split DWARF information file, on disk. In othe words,...
void load_elf_properties()
Load various ELF data.
void reset(const std::string &elf_path, const vector< char ** > &debug_info_roots)
Resets (erase) the resources used by the current elf::reader type.
const string & elf_architecture() const
Get the value of the 'ARCHITECTURE' property of the current ELF file.
const Dwarf * dwarf_debug_info() const
Getter of the handle used to access DWARF information from the current ELF file.
void reset_symbol_table_section()
Clear the pointer to the ELF symbol table section.
const Elf_Scn * find_alternate_ctf_section() const
Find and return a pointer to the alternate CTF section of the current ELF file.
Elf * elf_handle() const
Getter of the handle used to access ELF information from the current ELF file.
const Elf_Scn * find_ctf_section() const
Find and return a pointer to the the CTF section.
~reader()
The destructor of the elf::reader type.
bool has_ctf_debug_info() const
Test if the binary has CTF debug info.
bool has_btf_debug_info() const
Test if the binary has BTF debug info.
void load_dt_soname_and_needed()
Load the DT_NEEDED and DT_SONAME elf TAGS.
virtual ir::corpus_sptr read_corpus(status &status)
Read the ELF information associated to the current ELF file and construct an ABI representation from ...
const Dwarf * alternate_dwarf_debug_info() const
Getter of the handle use to access DWARF information from the alternate split DWARF information.
bool refers_to_alt_debug_info(string &alt_di_path) const
Check if the underlying elf file refers to an alternate debug info file associated to it.
const vector< char ** > & debug_info_root_paths() const
Getter of the vector of directory paths to look into for split debug information files.
void load_elf_architecture()
Read the string representing the architecture of the current ELF file.
bool has_dwarf_debug_info() const
Test if the binary has DWARF debug info.
const Dwfl_Callbacks & dwfl_offline_callbacks() const
Getter of the functions used by the DWARF Front End library of elfutils to locate DWARF debug informa...
elf_symbol_sptr variable_symbol_is_exported(GElf_Addr symbol_address) const
Test if a given variable symbol has been exported.
symtab_reader::symtab_sptr & symtab() const
Getter of an abstract representation of the symbol table of the underlying ELF file.
const Elf_Scn * find_btf_section() const
Find and return a pointer to the BTF section of the current ELF file.
elf_symbol_sptr function_symbol_is_exported(GElf_Addr symbol_address) const
Test if a given function symbol has been exported.
const vector< string > & dt_needed() const
Get the value of the DT_NEEDED property of the current ELF file.
const Elf_Scn * find_symbol_table_section() const
Find and return a pointer to the ELF symbol table section.
The base class of all libabigail front-ends: The Front End Interface.
Definition: abg-fe-iface.h:29
status
The status of the fe_iface::read_corpus call.
Definition: abg-fe-iface.h:38
This is an abstraction of the set of resources necessary to manage several aspects of the internal re...
Definition: abg-ir.h:140
bool get_soname_of_elf_file(const string &path, string &soname)
Get the SONAME property of a designated ELF file.
shared_ptr< elf::reader > reader_sptr
A convenience typedef for a smart pointer to a elf::reader.
elf_type
The kind of ELF file we are looking at.
@ ELF_TYPE_RELOCATABLE
A relocatalbe binary.
@ ELF_TYPE_UNKNOWN
An unknown kind of binary.
@ ELF_TYPE_PI_EXEC
A Position Independant Executable binary.
@ ELF_TYPE_EXEC
A normal executable binary.
@ ELF_TYPE_DSO
A dynamic shared object, a.k.a shared library binary.
bool get_type_of_elf_file(const string &path, elf::elf_type &type)
Get the type of a given elf type.
shared_ptr< elf_symbol > elf_symbol_sptr
A convenience typedef for a shared pointer to elf_symbol.
Definition: abg-ir.h:865
Toplevel namespace for libabigail.