1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 // -*- Mode: C++ -*- 3 // 4 // Copyright (C) 2022 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 36 ELF_TYPE_EXEC, 37 /// A Position Independant Executable binary 38 ELF_TYPE_PI_EXEC, 39 /// A dynamic shared object, a.k.a shared library binary. 40 ELF_TYPE_DSO, 41 /// A relocatalbe binary. 42 ELF_TYPE_RELOCATABLE, 43 /// An unknown kind of binary. 44 ELF_TYPE_UNKNOWN 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 void 76 reset(const std::string& elf_path, 77 const vector<char**>& debug_info_roots); 78 79 const vector<char**>& 80 debug_info_root_paths() const; 81 82 const Dwfl_Callbacks& 83 dwfl_offline_callbacks() const; 84 85 Dwfl_Callbacks& 86 dwfl_offline_callbacks(); 87 88 Elf* 89 elf_handle() const; 90 91 const Dwarf* 92 dwarf_debug_info() const; 93 94 bool 95 has_dwarf_debug_info() const; 96 97 bool 98 has_ctf_debug_info() const; 99 100 const Dwarf* 101 alternate_dwarf_debug_info() const; 102 103 const string& 104 alternate_dwarf_debug_info_path() const; 105 106 bool 107 refers_to_alt_debug_info(string& alt_di_path) const; 108 109 const Elf_Scn* 110 find_symbol_table_section() const; 111 112 void 113 reset_symbol_table_section(); 114 115 const Elf_Scn* 116 find_ctf_section() const; 117 118 const Elf_Scn* 119 find_alternate_ctf_section() const; 120 121 const vector<string>& 122 dt_needed()const; 123 124 const string& 125 elf_architecture() const; 126 127 symtab_reader::symtab_sptr& 128 symtab() const; 129 130 elf_symbol_sptr 131 function_symbol_is_exported(GElf_Addr symbol_address) const; 132 133 elf_symbol_sptr 134 variable_symbol_is_exported(GElf_Addr symbol_address) const; 135 136 elf_symbol_sptr 137 function_symbol_is_exported(const string& name) const; 138 139 elf_symbol_sptr 140 variable_symbol_is_exported(const string& name) const; 141 142 void 143 load_dt_soname_and_needed(); 144 145 void 146 load_elf_architecture(); 147 148 void 149 load_elf_properties(); 150 151 virtual ir::corpus_sptr 152 read_corpus(status& status); 153 };//end class reader. 154 155 /// A convenience typedef for a smart pointer to a 156 /// elf::reader. 157 typedef shared_ptr<elf::reader> reader_sptr; 158 159 bool 160 get_soname_of_elf_file(const string& path, string &soname); 161 162 bool 163 get_type_of_elf_file(const string& path, elf_type& type); 164 } // end namespace elf. 165 } // end namespace abigail 166 167 #endif // __ABG_ELF_READER_H__ 168