Skip to content

Commit

Permalink
elf: fix is_lib detection for PIE and static PIE Elf objects. (#366)
Browse files Browse the repository at this point in the history
* Fix `is_lib` detection for PIE and static PIE Elf objects.
* Don't check for an interpreter when detecting is_lib for elf objects.
* Correct PIE detection.

---------

Co-authored-by: Mike Hilgendorf <mike@tangram.dev>
  • Loading branch information
m-hilgendorf and m-hilgendorf committed May 15, 2023
1 parent 6ff43af commit 9f7fb6b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/elf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ if_sylvan! {
strtab = get_strtab(&section_headers, shdr.sh_link as usize)?;
}

let mut is_pie = false;
let mut soname = None;
let mut libraries = vec![];
let mut rpaths = vec![];
Expand All @@ -319,6 +320,8 @@ if_sylvan! {
let dynamic = Dynamic::parse(bytes, &program_headers, ctx)?;
if let Some(ref dynamic) = dynamic {
let dyn_info = &dynamic.info;

is_pie = dyn_info.flags_1 & dynamic::DF_1_PIE != 0;
dynstrtab = Strtab::parse(bytes,
dyn_info.strtab,
dyn_info.strsz,
Expand Down Expand Up @@ -379,6 +382,8 @@ if_sylvan! {
let verdef = symver::VerdefSection::parse(bytes, &section_headers, ctx)?;
let verneed = symver::VerneedSection::parse(bytes, &section_headers, ctx)?;

let is_lib = misc.is_lib && !is_pie;

Ok(Elf {
header,
program_headers,
Expand All @@ -399,7 +404,7 @@ if_sylvan! {
rpaths,
runpaths,
is_64: misc.is_64,
is_lib: misc.is_lib,
is_lib,
entry: misc.entry,
little_endian: misc.little_endian,
ctx: ctx,
Expand Down

0 comments on commit 9f7fb6b

Please sign in to comment.