Browse Source

aya: only consider Text symbols as relocatable functions

Alessandro Decina 3 years ago
parent
commit
c56a6b16aa
2 changed files with 8 additions and 6 deletions
  1. 5 4
      aya/src/obj/mod.rs
  2. 3 2
      aya/src/obj/relocation.rs

+ 5 - 4
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()))]

+ 3 - 2
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 {