1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- Mode: C++ -*-
//
// Copyright (C) 2022-2025 Red Hat, Inc.
//
// Author: Dodji Seketeli
/// @file
///
/// This file contains the declarations for the @ref fe_iface a.k.a
/// "Front End Interface".
#ifndef __ABG_ELF_READER_H__
#define __ABG_ELF_READER_H__
#include <memory>
#include <string>
#include <elfutils/libdwfl.h>
#include "abg-fe-iface.h"
#include "abg-ir.h"
#include "abg-suppression.h"
namespace abigail
{
/// The namespace for the ELF Reader.
namespace elf
{
/// The kind of ELF file we are looking at.
enum elf_type : unsigned
{
/// A normal executable binary
ELF_TYPE_EXEC,
/// A Position Independant Executable binary
ELF_TYPE_PI_EXEC,
/// A dynamic shared object, a.k.a shared library binary.
ELF_TYPE_DSO,
/// A relocatalbe binary.
ELF_TYPE_RELOCATABLE,
/// An unknown kind of binary.
ELF_TYPE_UNKNOWN
};
/// This is the interface an ELF reader.
///
/// It knows how to open an ELF file, read its content and expose an
/// interface for its symbol table and other properties.
///
/// Note that the ABI corpus returned by the elf::read_corpus()
/// member function doesn't contain any type representation. It only
/// contains the representations of the the ELF symbols found in the
/// ELF file.
///
/// To construct the type representations for the functions and global
/// variables present in the ELF file, please use the implementations
/// of the @ref elf_based_reader interface. Those know how to read
/// the debug information from the ELF file to build type
/// representation in the @ref abigail::ir::corpus instance.
class reader : public fe_iface
{
struct priv;
priv *priv_;
public:
reader(const std::string& elf_path,
const vector<string>& debug_info_roots,
environment& env);
~reader();
virtual void
initialize(const std::string& elf_path,
const vector<string>& debug_info_roots);
virtual void
initialize(const std::string& elf_path);
const vector<string>&
debug_info_root_paths() const;
const Dwfl_Callbacks&
dwfl_offline_callbacks() const;
Dwfl_Callbacks&
dwfl_offline_callbacks();
Elf*
elf_handle() const;
const Dwarf*
dwarf_debug_info() const;
bool
has_dwarf_debug_info() const;
bool
has_ctf_debug_info() const;
bool
has_btf_debug_info() const;
const Dwarf*
alternate_dwarf_debug_info() const;
const string&
alternate_dwarf_debug_info_path() const;
bool
refers_to_alt_debug_info(string& alt_di_path) const;
const Elf_Scn*
find_symbol_table_section() const;
void
reset_symbol_table_section();
const Elf_Scn*
find_ctf_section() const;
const Elf_Scn*
find_alternate_ctf_section() const;
const Elf_Scn*
find_btf_section() const;
const vector<string>&
dt_needed()const;
const string&
elf_architecture() const;
symtab_reader::symtab_sptr&
symtab() const;
elf_symbol_sptr
function_symbol_is_exported(GElf_Addr symbol_address) const;
elf_symbol_sptr
variable_symbol_is_exported(GElf_Addr symbol_address) const;
elf_symbol_sptr
function_symbol_is_exported(const string& name) const;
elf_symbol_sptr
variable_symbol_is_exported(const string& name) const;
elf_symbol_sptr
function_symbol_is_undefined(const string& name) const;
elf_symbol_sptr
variable_symbol_is_undefined(const string& name) const;
void
load_dt_soname_and_needed();
void
load_elf_architecture();
void
load_elf_properties();
virtual ir::corpus_sptr
read_corpus(status& status);
};//end class reader.
/// A convenience typedef for a smart pointer to a
/// elf::reader.
typedef shared_ptr<elf::reader> reader_sptr;
bool
get_soname_of_elf_file(const string& path, string &soname);
bool
get_type_of_elf_file(const string& path, elf_type& type);
} // end namespace elf.
} // end namespace abigail
#endif // __ABG_ELF_READER_H__
|