From c56a6b16aa3fdafeb531c280c7a5d8dae7a4612a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=C2=A0Decina?= Date: Fri, 17 Sep 2021 12:47:18 +0000 Subject: [PATCH] aya: only consider Text symbols as relocatable functions --- aya/src/obj/mod.rs | 9 +++++---- aya/src/obj/relocation.rs | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/aya/src/obj/mod.rs b/aya/src/obj/mod.rs index 3d84c6d3..8e2efecb 100644 --- a/aya/src/obj/mod.rs +++ b/aya/src/obj/mod.rs @@ -3,7 +3,7 @@ mod relocation; use object::{ read::{Object as ElfObject, ObjectSection, Section as ObjSection}, - Endianness, ObjectSymbol, ObjectSymbolTable, RelocationTarget, SectionIndex, + Endianness, ObjectSymbol, ObjectSymbolTable, RelocationTarget, SectionIndex, SymbolKind, }; use std::{ collections::HashMap, @@ -181,6 +181,7 @@ impl Object { address: symbol.address(), size: symbol.size(), is_definition: symbol.is_definition(), + is_text: symbol.kind() == SymbolKind::Text, }; bpf_obj .symbols_by_index @@ -242,7 +243,7 @@ impl Object { let mut symbols_by_address = HashMap::new(); for sym in self.symbols_by_index.values() { - if sym.is_definition && sym.section_index == Some(section.index) { + if sym.is_definition && sym.is_text && sym.section_index == Some(section.index) { if symbols_by_address.contains_key(&sym.address) { return Err(ParseError::SymbolTableConflict { section_index: section.index.0, @@ -381,10 +382,10 @@ pub enum ParseError { #[error("error parsing map `{name}`")] InvalidMapDefinition { name: String }, - #[error("two or more symbols in section `{section_index}` have the same address {address:x}")] + #[error("two or more symbols in section `{section_index}` have the same address {address:#X}")] SymbolTableConflict { section_index: usize, address: u64 }, - #[error("unknown symbol in section `{section_index}` at address {address:x}")] + #[error("unknown symbol in section `{section_index}` at address {address:#X}")] UnknownSymbol { section_index: usize, address: u64 }, #[error("invalid symbol, index `{index}` name: {}", .name.as_ref().unwrap_or(&"[unknown]".into()))] diff --git a/aya/src/obj/relocation.rs b/aya/src/obj/relocation.rs index d6b40448..eb001523 100644 --- a/aya/src/obj/relocation.rs +++ b/aya/src/obj/relocation.rs @@ -20,8 +20,8 @@ enum RelocationError { #[error("unknown symbol, index `{index}`")] UnknownSymbol { index: usize }, - #[error("section `{section_index}` not found, referenced by symbol `{}`", - .symbol_name.clone().unwrap_or_else(|| .symbol_index.to_string()))] + #[error("section `{section_index}` not found, referenced by symbol `{}` #{symbol_index}", + .symbol_name.clone().unwrap_or_else(|| "".to_string()))] SectionNotFound { section_index: usize, symbol_index: usize, @@ -57,6 +57,7 @@ pub(crate) struct Symbol { pub(crate) address: u64, pub(crate) size: u64, pub(crate) is_definition: bool, + pub(crate) is_text: bool, } impl Object {