Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elf gnu symbol versioning #280

Merged
merged 20 commits into from Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0ab34dc
elf.dynamic: Parse DT_VERDEF + DT_VERDEFNUM dynamic tags into Dynamic…
johannst Aug 10, 2021
7a1a6e6
elf.symver: add struct definitions and reading part for .gnu.version_…
johannst Aug 13, 2021
dc1e26b
elf.symver: add tests for parsing .gnu.version_r section
johannst Aug 13, 2021
85ed28d
elf.symver: make structs used by user more ergonomic by using usize
johannst Aug 13, 2021
de9a4e7
elf.symver: API updates
johannst Aug 14, 2021
61c00ef
elf.symver: add struct definitions and reading part for .gnu.version_…
johannst Aug 15, 2021
753ad13
elf.symver: Use sub-module as feature guard
johannst Aug 15, 2021
8b882af
add tests for parsing .gnu.version_d section
johannst Aug 15, 2021
89697c4
elf.symver: add struct definitions and reading part for .gnu.version …
johannst Aug 15, 2021
b472420
elf.symver: add tests for parsing .gnu.version section
johannst Aug 15, 2021
fa03ec3
elf.symver: fix clippy warnings
johannst Aug 15, 2021
8bd8bc8
elf.symver: added some convenience methods to Verdef
johannst Aug 15, 2021
097d6e5
elf.symver: apply review feedback
johannst Aug 16, 2021
b2d780f
elf.symver: apply review feedback
johannst Aug 16, 2021
7c41301
elf.symver: apply review feedback
johannst Aug 17, 2021
8dad2eb
elf.symver: add doc comments to constants and move field doc comments…
johannst Aug 17, 2021
49d2b38
elf.symver: fix comments in test
johannst Sep 5, 2021
74e6fb0
elf.symver: move cfg guard globally on module
johannst Sep 6, 2021
f029db3
elf.symver: apply review feedback
johannst Sep 8, 2021
5bc5c52
elf.symver: apply review feedback
johannst Sep 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/elf/dynamic.rs
Expand Up @@ -614,6 +614,8 @@ macro_rules! elf_dynamic_info_std_impl {
pub pltrelsz: usize,
pub pltrel: $size,
pub jmprel: usize,
pub verdef: $size,
pub verdefnum: $size,
pub verneed: $size,
pub verneednum: $size,
pub versym: $size,
Expand Down Expand Up @@ -658,6 +660,8 @@ macro_rules! elf_dynamic_info_std_impl {
DT_JMPREL => {
self.jmprel = vm_to_offset(phdrs, dynamic.d_val).unwrap_or(0) as usize
} // .rela.plt
DT_VERDEF => self.verdef = vm_to_offset(phdrs, dynamic.d_val).unwrap_or(0),
DT_VERDEFNUM => self.verdefnum = vm_to_offset(phdrs, dynamic.d_val).unwrap_or(0),
DT_VERNEED => self.verneed = vm_to_offset(phdrs, dynamic.d_val).unwrap_or(0),
DT_VERNEEDNUM => self.verneednum = dynamic.d_val as _,
DT_VERSYM => self.versym = vm_to_offset(phdrs, dynamic.d_val).unwrap_or(0),
Expand Down Expand Up @@ -750,6 +754,8 @@ macro_rules! elf_dynamic_info_std_impl {
.field("pltrelsz", &self.pltrelsz)
.field("pltrel", &self.pltrel)
.field("jmprel", &format_args!("0x{:x}", self.jmprel))
.field("verdef", &format_args!("0x{:x}", self.verdef))
.field("verdefnum", &self.verdefnum)
.field("verneed", &format_args!("0x{:x}", self.verneed))
.field("verneednum", &self.verneednum)
.field("versym", &format_args!("0x{:x}", self.versym))
Expand Down
21 changes: 21 additions & 0 deletions src/elf/mod.rs
Expand Up @@ -53,6 +53,7 @@ pub mod dynamic;
#[macro_use]
pub mod reloc;
pub mod note;
pub mod symver;

macro_rules! if_sylvan {
($($i:item)*) => ($(
Expand All @@ -78,6 +79,7 @@ if_sylvan! {
pub use dynamic::Dynamic;
pub use reloc::Reloc;
pub use reloc::RelocSection;
pub use symver::{VersymSection, VerdefSection, VerneedSection};

pub type ProgramHeaders = Vec<ProgramHeader>;
pub type SectionHeaders = Vec<SectionHeader>;
Expand Down Expand Up @@ -130,6 +132,15 @@ if_sylvan! {
pub entry: u64,
/// Whether the binary is little endian or not
pub little_endian: bool,
/// Contains the symbol version information from the optional section
/// [`SHT_GNU_VERSYM`][section_header::SHT_GNU_VERSYM] (GNU extenstion).
pub versym : Option<VersymSection<'a>>,
/// Contains the version definition information from the optional section
/// [`SHT_GNU_VERDEF`][section_header::SHT_GNU_VERDEF] (GNU extenstion).
pub verdef : Option<VerdefSection<'a>>,
/// Contains the version needed information from the optional section
/// [`SHT_GNU_VERNEED`][section_header::SHT_GNU_VERNEED] (GNU extenstion).
pub verneed : Option<VerneedSection<'a>>,
ctx: Ctx,
}

Expand Down Expand Up @@ -232,6 +243,9 @@ if_sylvan! {
entry: misc.entry,
little_endian: misc.little_endian,
ctx: misc.ctx,
versym: None,
verdef: None,
verneed: None,
})
}

Expand Down Expand Up @@ -334,6 +348,10 @@ if_sylvan! {
}
}

let versym = symver::VersymSection::parse(bytes, &section_headers, ctx)?;
let verdef = symver::VerdefSection::parse(bytes, &section_headers, ctx)?;
let verneed = symver::VerneedSection::parse(bytes, &section_headers, ctx)?;

Ok(Elf {
header,
program_headers,
Expand All @@ -356,6 +374,9 @@ if_sylvan! {
entry: misc.entry,
little_endian: misc.little_endian,
ctx: ctx,
versym,
verdef,
verneed,
})
}
}
Expand Down