libabigail
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 
25 namespace abigail
26 {
27 
28 /// The namespace for the ELF Reader.
29 namespace elf
30 {
31 
32 /// The kind of ELF file we are looking at.
33 enum 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.
62 class 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  virtual void
76  initialize(const std::string& elf_path,
77  const vector<char**>& debug_info_roots);
78 
79  virtual void
80  initialize(const std::string& elf_path);
81 
82  const vector<char**>&
83  debug_info_root_paths() const;
84 
85  const Dwfl_Callbacks&
86  dwfl_offline_callbacks() const;
87 
88  Dwfl_Callbacks&
90 
91  Elf*
92  elf_handle() const;
93 
94  const Dwarf*
95  dwarf_debug_info() const;
96 
97  bool
98  has_dwarf_debug_info() const;
99 
100  bool
101  has_ctf_debug_info() const;
102 
103  bool
104  has_btf_debug_info() const;
105 
106  const Dwarf*
108 
109  const string&
111 
112  bool
113  refers_to_alt_debug_info(string& alt_di_path) const;
114 
115  const Elf_Scn*
117 
118  void
120 
121  const Elf_Scn*
122  find_ctf_section() const;
123 
124  const Elf_Scn*
126 
127  const Elf_Scn*
128  find_btf_section() const;
129 
130  const vector<string>&
131  dt_needed()const;
132 
133  const string&
134  elf_architecture() const;
135 
137  symtab() const;
138 
140  function_symbol_is_exported(GElf_Addr symbol_address) const;
141 
143  variable_symbol_is_exported(GElf_Addr symbol_address) const;
144 
146  function_symbol_is_exported(const string& name) const;
147 
149  variable_symbol_is_exported(const string& name) const;
150 
151  void
153 
154  void
156 
157  void
159 
160  virtual ir::corpus_sptr
162 };//end class reader.
163 
164 /// A convenience typedef for a smart pointer to a
165 /// elf::reader.
166 typedef shared_ptr<elf::reader> reader_sptr;
167 
168 bool
169 get_soname_of_elf_file(const string& path, string &soname);
170 
171 bool
172 get_type_of_elf_file(const string& path, elf_type& type);
173 } // end namespace elf.
174 } // end namespace abigail
175 
176 #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:1610
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.
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.
virtual void initialize(const std::string &elf_path, const vector< char ** > &debug_info_roots)
Re-initialize the resources used by the current elf::reader type.
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:872
Toplevel namespace for libabigail.