Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 135 additions & 7 deletions src/dw_sys/elfutils/gelf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,144 @@
//

use libc::{
Elf64_Addr, Elf64_Half, Elf64_Off, Elf64_Phdr, Elf64_Shdr, Elf64_Sxword, Elf64_Sym, Elf64_Word,
Elf64_Xword,
c_int, c_long, c_uint, c_void, size_t, Elf32_Word, Elf64_Addr, Elf64_Chdr, Elf64_Ehdr,
Elf64_Half, Elf64_Off, Elf64_Phdr, Elf64_Rel, Elf64_Rela, Elf64_Shdr, Elf64_Sword,
Elf64_Sxword, Elf64_Sym, Elf64_Word, Elf64_Xword,
};

use super::super::{Elf, Elf_Data, Elf_Scn, Elf_Type};

pub type GElf_Half = Elf64_Half;
pub type GElf_Word = Elf64_Word;
pub type GElf_Sword = Elf64_Sword;
pub type GElf_Xword = Elf64_Xword;
pub type GElf_Sxword = Elf64_Sxword;
pub type GElf_Addr = Elf64_Addr;
pub type GElf_Phdr = Elf64_Phdr;
pub type GElf_Off = Elf64_Off;
pub type GElf_Ehdr = Elf64_Ehdr;
pub type GElf_Shdr = Elf64_Shdr;
pub type GElf_Sxword = Elf64_Sxword;
pub type GElf_Section = Elf64_Half;
pub type GElf_Sym = Elf64_Sym;
pub type GElf_Off = Elf64_Off;
pub type GElf_Xword = Elf64_Xword;
pub type GElf_Half = Elf64_Half;
pub type GElf_Rel = Elf64_Rel;
pub type GElf_Rela = Elf64_Rela;
pub type GElf_Phdr = Elf64_Phdr;
pub type GElf_Chdr = Elf64_Chdr;
pub type GElf_Versym = Elf64_Half;

#[repr(C)]
#[derive(Copy, Clone)]
pub struct GElf_Dyn {
pub d_tag: Elf64_Sxword,
pub d_un: Elf64_Xword,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct GElf_Nhdr {
pub n_namesz: Elf64_Word,
pub n_descsz: Elf64_Word,
pub n_type: Elf64_Word,
}

extern "C" {
pub fn gelf_getclass(__elf: *mut Elf) -> c_int;

pub fn gelf_fsize(
__elf: *mut Elf,
__type: Elf_Type,
__count: size_t,
__version: c_uint,
) -> size_t;

pub fn gelf_getehdr(__elf: *mut Elf, __dest: *mut GElf_Ehdr) -> *mut GElf_Ehdr;

pub fn gelf_update_ehdr(__elf: *mut Elf, __src: *mut GElf_Ehdr) -> c_int;

pub fn gelf_newehdr(__elf: *mut Elf, __class: c_int) -> *mut c_void;

pub fn gelf_offscn(__elf: *mut Elf, __offset: GElf_Off) -> *mut Elf_Scn;

pub fn gelf_getshdr(__scn: *mut Elf_Scn, __dst: *mut GElf_Shdr) -> *mut GElf_Shdr;

pub fn gelf_update_shdr(__scn: *mut Elf_Scn, __src: *mut GElf_Shdr) -> c_int;

pub fn gelf_getphdr(__elf: *mut Elf, __ndx: c_int, __dst: *mut GElf_Phdr) -> *mut GElf_Phdr;

pub fn gelf_update_phdr(__elf: *mut Elf, __ndx: c_int, __src: *mut GElf_Phdr) -> c_int;

pub fn gelf_newphdr(__elf: *mut Elf, __phnum: size_t) -> *mut c_void;

pub fn gelf_getchdr(__scn: *mut Elf_Scn, __dst: *mut GElf_Chdr) -> *mut GElf_Chdr;

pub fn gelf_xlatetom(
__elf: *mut Elf,
__dest: *mut Elf_Data,
__src: *const Elf_Data,
__encode: c_uint,
) -> *mut Elf_Data;

pub fn gelf_xlatetof(
__elf: *mut Elf,
__dest: *mut Elf_Data,
__src: *const Elf_Data,
__encode: c_uint,
) -> *mut Elf_Data;

pub fn gelf_getrel(__data: *mut Elf_Data, __ndx: c_int, __dst: *mut GElf_Rel) -> *mut GElf_Rel;

pub fn gelf_getrela(
__data: *mut Elf_Data,
__ndx: c_int,
__dst: *mut GElf_Rela,
) -> *mut GElf_Rela;

pub fn gelf_update_rel(__dst: *mut Elf_Data, __ndx: c_int, __src: *mut GElf_Rel) -> c_int;

pub fn gelf_update_rela(__dst: *mut Elf_Data, __ndx: c_int, __src: *mut GElf_Rela) -> c_int;

pub fn gelf_getsym(__data: *mut Elf_Data, __ndx: c_int, __dst: *mut GElf_Sym) -> *mut GElf_Sym;

pub fn gelf_update_sym(__data: *mut Elf_Data, __ndx: c_int, __src: *mut GElf_Sym) -> c_int;

pub fn gelf_getsymshndx(
__symdata: *mut Elf_Data,
__shndxdata: *mut Elf_Data,
__ndx: c_int,
__sym: *mut GElf_Sym,
__xshndx: *mut Elf32_Word,
) -> *mut GElf_Sym;

pub fn gelf_update_symshndx(
__symdata: *mut Elf_Data,
__shndxdata: *mut Elf_Data,
__ndx: c_int,
__sym: *mut GElf_Sym,
__xshndx: Elf32_Word,
) -> c_int;

pub fn gelf_getdyn(__data: *mut Elf_Data, __ndx: c_int, __dst: *mut GElf_Dyn) -> *mut GElf_Dyn;

pub fn gelf_update_dyn(__dst: *mut Elf_Data, __ndx: c_int, __src: *mut GElf_Dyn) -> c_int;

pub fn gelf_getversym(
__data: *mut Elf_Data,
__ndx: c_int,
__dst: *mut GElf_Versym,
) -> *mut GElf_Versym;

pub fn gelf_update_versym(
__data: *mut Elf_Data,
__ndx: c_int,
__src: *mut GElf_Versym,
) -> c_int;

pub fn gelf_getnote(
__data: *mut Elf_Data,
__offset: size_t,
__result: *mut GElf_Nhdr,
__name_offset: *mut size_t,
__desc_offset: *mut size_t,
) -> size_t;

pub fn gelf_checksum(__elf: *mut Elf) -> c_long;
}
65 changes: 65 additions & 0 deletions src/dw_sys/elfutils/libdw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub const DWARF_CB_ABORT: c_int = 1;

pub const DW_TAG_invalid: c_int = 0;

pub const LIBDW_CIE_ID: u64 = 0xffffffffffffffff;

pub const DWARF_GETMACROS_START: ptrdiff_t = ptrdiff_t::MIN;

pub type Dwarf_Off = GElf_Off;

pub type Dwarf_Addr = GElf_Addr;
Expand Down Expand Up @@ -177,6 +181,27 @@ extern "C" {
type_offsetp: *mut Dwarf_Off,
) -> c_int;

pub fn dwarf_get_units(
dwarf: *mut Dwarf,
cu: *mut Dwarf_CU,
next_cu: *mut *mut Dwarf_CU,
version: *mut Dwarf_Half,
unit_type: *mut u8,
cudie: *mut Dwarf_Die,
subdie: *mut Dwarf_Die,
) -> c_int;

pub fn dwarf_cu_info(
cu: *mut Dwarf_CU,
version: *mut Dwarf_Half,
unit_type: *mut u8,
cudie: *mut Dwarf_Die,
subdie: *mut Dwarf_Die,
unit_id: *mut u64,
address_size: *mut u8,
offset_size: *mut u8,
) -> c_int;

pub fn dwarf_next_cfi(
e_ident: *const c_uchar,
data: *mut Elf_Data,
Expand Down Expand Up @@ -226,6 +251,12 @@ extern "C" {
type_offsetp: *mut Dwarf_Off,
) -> *mut Dwarf_Die;

pub fn dwarf_die_addr_die(
dbg: *mut Dwarf,
addr: *mut c_void,
result: *mut Dwarf_Die,
) -> *mut Dwarf_Die;

pub fn dwarf_addrdie(
dbg: *mut Dwarf,
addr: Dwarf_Addr,
Expand Down Expand Up @@ -279,6 +310,8 @@ extern "C" {

pub fn dwarf_formaddr(attr: *mut Dwarf_Attribute, return_addr: *mut Dwarf_Addr) -> c_int;

pub fn dwarf_formref(attr: *mut Dwarf_Attribute, return_offset: *mut Dwarf_Off) -> c_int;

pub fn dwarf_formref_die(attr: *mut Dwarf_Attribute, die_mem: *mut Dwarf_Die)
-> *mut Dwarf_Die;

Expand Down Expand Up @@ -343,6 +376,15 @@ extern "C" {
offset: *mut Dwarf_Off,
) -> c_int;

pub fn dwarf_getabbrevattr_data(
abbrev: *mut Dwarf_Abbrev,
idx: size_t,
namep: *mut c_uint,
formp: *mut c_uint,
datap: *mut Dwarf_Sword,
offset: *mut Dwarf_Off,
) -> c_int;

pub fn dwarf_getstring(dbg: *mut Dwarf, offset: Dwarf_Off, lep: *mut size_t) -> *const c_char;

pub fn dwarf_getpubnames(
Expand Down Expand Up @@ -407,19 +449,40 @@ extern "C" {
length: *mut Dwarf_Word,
) -> *const c_char;

pub fn dwarf_linecontext(lines: *mut Dwarf_Lines, line: *mut Dwarf_Line) -> *mut Dwarf_Line;

pub fn dwarf_linefunctionname(dbg: *mut Dwarf, line: *mut Dwarf_Line) -> *const c_char;

pub fn dwarf_filesrc(
file: *mut Dwarf_Files,
idx: size_t,
mtime: *mut Dwarf_Word,
length: *mut Dwarf_Word,
) -> *const c_char;

pub fn dwarf_line_file(
line: *mut Dwarf_Line,
files: *mut *mut Dwarf_Files,
idx: *mut size_t,
) -> c_int;

pub fn dwarf_getsrcdirs(
files: *mut Dwarf_Files,
result: *mut *const *const c_char,
ndirs: *mut size_t,
) -> c_int;

pub fn dwarf_next_lines(
dwarf: *mut Dwarf,
off: Dwarf_Off,
next_off: *mut Dwarf_Off,
cu: *mut *mut Dwarf_CU,
srcfiles: *mut *mut Dwarf_Files,
nfiles: *mut size_t,
srclines: *mut *mut Dwarf_Lines,
nlines: *mut size_t,
) -> c_int;

pub fn dwarf_getlocation(
attr: *mut Dwarf_Attribute,
expr: *mut *mut Dwarf_Op,
Expand Down Expand Up @@ -470,6 +533,8 @@ extern "C" {

pub fn dwarf_aggregate_size(die: *mut Dwarf_Die, size: *mut Dwarf_Word) -> c_int;

pub fn dwarf_default_lower_bound(lang: c_int, result: *mut Dwarf_Sword) -> c_int;

pub fn dwarf_getscopes(
cudie: *mut Dwarf_Die,
pc: Dwarf_Addr,
Expand Down
8 changes: 7 additions & 1 deletion src/dw_sys/elfutils/libdwelf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the License.
//

use libc::{c_char, c_void, size_t, ssize_t};
use libc::{c_char, c_int, c_void, size_t, ssize_t};

use super::super::*;

Expand Down Expand Up @@ -48,5 +48,11 @@ extern "C" {

pub fn dwelf_strent_str(se: *mut Dwelf_Strent) -> *const c_char;

pub fn dwelf_strent_off(se: *mut Dwelf_Strent) -> size_t;

pub fn dwelf_strtab_free(st: *mut Dwelf_Strtab);

pub fn dwelf_elf_begin(fd: c_int) -> *mut Elf;

pub fn dwelf_elf_e_machine_string(machine: c_int) -> *const c_char;
}
32 changes: 32 additions & 0 deletions src/dw_sys/elfutils/libdwfl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub enum Dwfl_Module {}
pub enum Dwfl_Thread {}
pub enum Dwfl_Frame {}
pub enum Dwfl_Line {}
pub enum debuginfod_client {}

#[repr(C)]
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -141,6 +142,14 @@ extern "C" {
fd: c_int,
) -> *mut Dwfl_Module;

pub fn dwfl_report_offline_memory(
dwfl: *mut Dwfl,
name: *const c_char,
file_name: *const c_char,
data: *mut c_char,
size: size_t,
) -> *mut Dwfl_Module;

pub fn dwfl_report_end(
dwfl: *mut Dwfl,
removed: Option<
Expand Down Expand Up @@ -284,6 +293,17 @@ extern "C" {
_: *mut *mut Elf,
) -> c_int;

pub fn dwfl_offline_section_address(
_: *mut Dwfl_Module,
_: *mut *mut c_void,
_: *const c_char,
_: Dwarf_Addr,
_: *const c_char,
_: GElf_Word,
_: *const GElf_Shdr,
addr: *mut Dwarf_Addr,
) -> c_int;

pub fn dwfl_module_relocations(mod_: *mut Dwfl_Module) -> c_int;

pub fn dwfl_module_relocate_address(mod_: *mut Dwfl_Module, address: *mut Dwarf_Addr) -> c_int;
Expand All @@ -294,6 +314,12 @@ extern "C" {
shndxp: *mut GElf_Word,
) -> *const c_char;

pub fn dwfl_validate_address(
dwfl: *mut Dwfl,
address: Dwarf_Addr,
offset: Dwarf_Sword,
) -> c_int;

pub fn dwfl_module_getelf(_: *mut Dwfl_Module, bias: *mut GElf_Addr) -> *mut Elf;

pub fn dwfl_module_getsymtab(mod_: *mut Dwfl_Module) -> c_int;
Expand Down Expand Up @@ -388,6 +414,8 @@ extern "C" {

pub fn dwfl_getsrclines(cudie: *mut Dwarf_Die, nlines: *mut size_t) -> c_int;

pub fn dwfl_onesrcline(cudie: *mut Dwarf_Die, idx: size_t) -> *mut Dwfl_Line;

pub fn dwfl_module_getsrc(mod_: *mut Dwfl_Module, addr: Dwarf_Addr) -> *mut Dwfl_Line;

pub fn dwfl_getsrc(dwfl: *mut Dwfl, addr: Dwarf_Addr) -> *mut Dwfl_Line;
Expand Down Expand Up @@ -501,4 +529,8 @@ extern "C" {
pc: *mut Dwarf_Addr,
isactivation: *mut bool,
) -> bool;

pub fn dwfl_frame_reg(state: *mut Dwfl_Frame, regno: c_uint, val: *mut Dwarf_Word) -> c_int;

pub fn dwfl_get_debuginfod_client(dwfl: *mut Dwfl) -> *mut debuginfod_client;
}
6 changes: 6 additions & 0 deletions src/dw_sys/libelf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ c_enum! {
ELF_T_GNUHASH = 23,
ELF_T_AUXV = 24,
ELF_T_CHDR = 25,
ELF_T_NHDR8 = 26,
ELF_T_RELR = 27,
}
}

Expand Down Expand Up @@ -184,6 +186,8 @@ extern "C" {

pub fn elf_compress(scn: *mut Elf_Scn, type_: c_int, flags: c_uint) -> c_int;

pub fn elf_compress_gnu(scn: *mut Elf_Scn, compress: c_int, flags: c_uint) -> c_int;

pub fn elf_flagelf(__elf: *mut Elf, __cmd: Elf_Cmd, __flags: c_uint) -> c_uint;

pub fn elf_flagehdr(__elf: *mut Elf, __cmd: Elf_Cmd, __flags: c_uint) -> c_uint;
Expand All @@ -209,6 +213,8 @@ extern "C" {
__type: Elf_Type,
) -> *mut Elf_Data;

pub fn elf_strptr(__elf: *mut Elf, __index: size_t, __offset: size_t) -> *mut c_char;

pub fn elf_getarhdr(__elf: *mut Elf) -> *mut Elf_Arhdr;

pub fn elf_getaroff(__elf: *mut Elf) -> i64;
Expand Down
Loading