diff --git a/src/elf.rs b/src/elf.rs index bb3ee1cc..10ee349d 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -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( @@ -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;