Skip to content

Commit

Permalink
Allow no rodata (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmay authored Dec 21, 2018
1 parent 8107f7c commit 1ca197c
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,19 +286,12 @@ impl EBpfElf {
};
let text_va = text_section.header.addr;

let rodata_section = match self
let rodata_section = self
.elf
.sections
.iter()
.find(|section| section.name == b".rodata")
{
Some(section) => section,
None => Err(Error::new(
ErrorKind::Other,
"Error: No .rodata section found",
))?,
};

.find(|section| section.name == b".rodata");

let symbols = match self.get_section(".dynsym")?.content {
elfkit::SectionContent::Symbols(ref bytes) => bytes.clone(),
_ => Err(Error::new(
Expand All @@ -312,6 +305,14 @@ impl EBpfElf {
Some(BPFRelocationType::R_BPF_64_RELATIVE) => {
// The .text section has a reference to a symbol in the .rodata section

let rodata_section = match rodata_section {
Some(section) => section,
None => Err(Error::new(
ErrorKind::Other,
"Error: No .rodata section found",
))?,
};

// Offset of the instruction in the text section being relocated
let mut imm_offset =
(relocation.addr - text_va) as usize + BYTE_OFFSET_IMMEDIATE;
Expand Down

0 comments on commit 1ca197c

Please sign in to comment.