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

Add rpaths and runpaths to ELF #294

Merged
merged 2 commits into from
Dec 9, 2021
Merged
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
23 changes: 23 additions & 0 deletions src/elf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ if_sylvan! {
pub interpreter: Option<&'a str>,
/// A list of this binary's dynamic libraries it uses, if there are any
pub libraries: Vec<&'a str>,
/// A list of runtime search paths for this binary's dynamic libraries it uses, if there
/// are any. (deprecated)
pub rpaths: Vec<&'a str>,
/// A list of runtime search paths for this binary's dynamic libraries it uses, if there
/// are any.
pub runpaths: Vec<&'a str>,
/// Whether this is a 64-bit elf or not
pub is_64: bool,
/// Whether this is a shared object or not
Expand Down Expand Up @@ -239,6 +245,8 @@ if_sylvan! {
soname: None,
interpreter: None,
libraries: vec![],
rpaths: vec![],
runpaths: vec![],
is_64: misc.is_64,
is_lib: misc.is_lib,
entry: misc.entry,
Expand Down Expand Up @@ -296,6 +304,8 @@ if_sylvan! {

let mut soname = None;
let mut libraries = vec![];
let mut rpaths = vec![];
let mut runpaths = vec![];
let mut dynsyms = Symtab::default();
let mut dynrelas = RelocSection::default();
let mut dynrels = RelocSection::default();
Expand All @@ -316,6 +326,17 @@ if_sylvan! {
if dyn_info.needed_count > 0 {
libraries = dynamic.get_libraries(&dynstrtab);
}
for dyn_ in &dynamic.dyns {
if dyn_.d_tag == dynamic::DT_RPATH {
if let Some(path) = dynstrtab.get_at(dyn_.d_val as usize) {
rpaths.push(path);
}
} else if dyn_.d_tag == dynamic::DT_RUNPATH {
if let Some(path) = dynstrtab.get_at(dyn_.d_val as usize) {
runpaths.push(path);
}
}
}
// parse the dynamic relocations
dynrelas = RelocSection::parse(bytes, dyn_info.rela, dyn_info.relasz, true, ctx)?;
dynrels = RelocSection::parse(bytes, dyn_info.rel, dyn_info.relsz, false, ctx)?;
Expand Down Expand Up @@ -370,6 +391,8 @@ if_sylvan! {
soname,
interpreter,
libraries,
rpaths,
runpaths,
is_64: misc.is_64,
is_lib: misc.is_lib,
entry: misc.entry,
Expand Down