Skip to content

Commit

Permalink
Call parse_sections() and parse_dynamic() in SBPF v1 only.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Oct 18, 2024
1 parent 90ddfd0 commit 01b9f1b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ impl<C: ContextObject> Executable<C> {
.as_ref()
.map(|aligned_memory| aligned_memory.as_slice())
.unwrap_or(bytes);
let elf = Elf64::parse(aligned_bytes)?;
let mut elf = Elf64::parse(aligned_bytes)?;

let enabled_sbpf_versions = loader.get_config().enabled_sbpf_versions.clone();
let sbpf_version = if *enabled_sbpf_versions.end() == SBPFVersion::V1 {
Expand All @@ -404,6 +404,8 @@ impl<C: ContextObject> Executable<C> {
}

let mut elf = if sbpf_version == SBPFVersion::V1 {
elf.parse_sections()?;
elf.parse_dynamic()?;
Self::load_with_lenient_parser(&elf, aligned_bytes, loader)?
} else {
let elf: Result<Self, ElfError> =
Expand Down
11 changes: 5 additions & 6 deletions src/elf_parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl<'a> Elf64<'a> {
})
.transpose()?;

let mut parser = Self {
let parser = Self {
elf_bytes,
file_header,
program_header_table,
Expand All @@ -260,9 +260,6 @@ impl<'a> Elf64<'a> {
dynamic_symbol_names_section_header: None,
};

parser.parse_sections()?;
parser.parse_dynamic()?;

Ok(parser)
}

Expand Down Expand Up @@ -291,7 +288,8 @@ impl<'a> Elf64<'a> {
self.dynamic_relocations_table
}

fn parse_sections(&mut self) -> Result<(), ElfParserError> {
/// Parses the section header table.
pub fn parse_sections(&mut self) -> Result<(), ElfParserError> {
macro_rules! section_header_by_name {
($self:expr, $section_header:expr, $section_name:expr,
$($name:literal => $field:ident,)*) => {
Expand Down Expand Up @@ -326,7 +324,8 @@ impl<'a> Elf64<'a> {
Ok(())
}

fn parse_dynamic(&mut self) -> Result<(), ElfParserError> {
/// Parses the dynamic section.
pub fn parse_dynamic(&mut self) -> Result<(), ElfParserError> {
let mut dynamic_table: Option<&[Elf64Dyn]> = None;

// try to parse PT_DYNAMIC
Expand Down

0 comments on commit 01b9f1b

Please sign in to comment.