Skip to content

Commit

Permalink
aya: Support map defs of varying lengths
Browse files Browse the repository at this point in the history
The symbols table contains the necessary information to read the
bpf_map_def at the correct offsets within the symbol data. This is
probably safer than naively chunking the data based on the number of
symbols in the section.

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
  • Loading branch information
dave-tucker committed Apr 28, 2022
1 parent 2e21033 commit 5cbcd5e
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions aya/src/obj/mod.rs
Expand Up @@ -527,16 +527,14 @@ impl Object {
if symbols.is_empty() {
return Err(ParseError::NoSymbolsInMapSection {});
}
let chunk_size = if section.size % symbols.len() as u64 == 0 {
section.size / symbols.len() as u64
} else {
return Err(ParseError::InvalidMapSectionSize {
num_syms: symbols.len(),
});
};
for (i, data) in section.data.chunks(chunk_size as usize).enumerate() {
let s = symbols.get(i).unwrap();
let name = s.name.as_ref().ok_or(ParseError::MapSymbolNotFound { i })?;
for (i, sym) in symbols.iter().enumerate() {
let start = sym.address as usize;
let end = start + sym.size as usize;
let data = &section.data[start..end];
let name = sym
.name
.as_ref()
.ok_or(ParseError::MapSymbolNotFound { i })?;
let def = parse_map_def(name, data)?;
self.maps.insert(
name.to_string(),
Expand Down Expand Up @@ -577,14 +575,14 @@ impl Object {
let symbols: Vec<Symbol> = self
.symbols_by_index
.values()
.cloned()
.filter(|s| {
if let Some(idx) = s.section_index {
idx == section.index.0
} else {
false
}
})
.cloned()
.collect();
self.parse_map_section(&section, symbols)?
}
Expand Down

0 comments on commit 5cbcd5e

Please sign in to comment.