|
|
@ -108,9 +108,20 @@ impl Object {
|
|
|
|
&mut self,
|
|
|
|
&mut self,
|
|
|
|
maps: I,
|
|
|
|
maps: I,
|
|
|
|
text_sections: &HashSet<usize>,
|
|
|
|
text_sections: &HashSet<usize>,
|
|
|
|
|
|
|
|
ignored_maps: &HashMap<String, Map>,
|
|
|
|
) -> Result<(), EbpfRelocationError> {
|
|
|
|
) -> Result<(), EbpfRelocationError> {
|
|
|
|
let mut maps_by_section = HashMap::new();
|
|
|
|
let mut maps_by_section = HashMap::new();
|
|
|
|
let mut maps_by_symbol = HashMap::new();
|
|
|
|
let mut maps_by_symbol = HashMap::new();
|
|
|
|
|
|
|
|
let mut ignored_by_section = HashSet::new();
|
|
|
|
|
|
|
|
let mut ignored_by_symbol = HashSet::new();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for map in ignored_maps.values() {
|
|
|
|
|
|
|
|
ignored_by_section.insert(map.section_index());
|
|
|
|
|
|
|
|
if let Some(index) = map.symbol_index() {
|
|
|
|
|
|
|
|
ignored_by_symbol.insert(index);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (name, fd, map) in maps {
|
|
|
|
for (name, fd, map) in maps {
|
|
|
|
maps_by_section.insert(map.section_index(), (name, fd, map));
|
|
|
|
maps_by_section.insert(map.section_index(), (name, fd, map));
|
|
|
|
if let Some(index) = map.symbol_index() {
|
|
|
|
if let Some(index) = map.symbol_index() {
|
|
|
@ -127,6 +138,8 @@ impl Object {
|
|
|
|
&maps_by_symbol,
|
|
|
|
&maps_by_symbol,
|
|
|
|
&self.symbol_table,
|
|
|
|
&self.symbol_table,
|
|
|
|
text_sections,
|
|
|
|
text_sections,
|
|
|
|
|
|
|
|
&ignored_by_section,
|
|
|
|
|
|
|
|
&ignored_by_symbol,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.map_err(|error| EbpfRelocationError {
|
|
|
|
.map_err(|error| EbpfRelocationError {
|
|
|
|
function: function.name.clone(),
|
|
|
|
function: function.name.clone(),
|
|
|
@ -176,6 +189,7 @@ impl Object {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
fn relocate_maps<'a, I: Iterator<Item = &'a Relocation>>(
|
|
|
|
fn relocate_maps<'a, I: Iterator<Item = &'a Relocation>>(
|
|
|
|
fun: &mut Function,
|
|
|
|
fun: &mut Function,
|
|
|
|
relocations: I,
|
|
|
|
relocations: I,
|
|
|
@ -183,6 +197,8 @@ fn relocate_maps<'a, I: Iterator<Item = &'a Relocation>>(
|
|
|
|
maps_by_symbol: &HashMap<usize, (&str, std::os::fd::RawFd, &Map)>,
|
|
|
|
maps_by_symbol: &HashMap<usize, (&str, std::os::fd::RawFd, &Map)>,
|
|
|
|
symbol_table: &HashMap<usize, Symbol>,
|
|
|
|
symbol_table: &HashMap<usize, Symbol>,
|
|
|
|
text_sections: &HashSet<usize>,
|
|
|
|
text_sections: &HashSet<usize>,
|
|
|
|
|
|
|
|
ignored_by_section: &HashSet<usize>,
|
|
|
|
|
|
|
|
ignored_by_symbol: &HashSet<usize>,
|
|
|
|
) -> Result<(), RelocationError> {
|
|
|
|
) -> Result<(), RelocationError> {
|
|
|
|
let section_offset = fun.section_offset;
|
|
|
|
let section_offset = fun.section_offset;
|
|
|
|
let instructions = &mut fun.instructions;
|
|
|
|
let instructions = &mut fun.instructions;
|
|
|
@ -222,7 +238,9 @@ fn relocate_maps<'a, I: Iterator<Item = &'a Relocation>>(
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let (_name, fd, map) = if let Some(m) = maps_by_symbol.get(&rel.symbol_index) {
|
|
|
|
let (_name, fd, map) = if ignored_by_symbol.contains(&rel.symbol_index) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
} else if let Some(m) = maps_by_symbol.get(&rel.symbol_index) {
|
|
|
|
let map = &m.2;
|
|
|
|
let map = &m.2;
|
|
|
|
debug!(
|
|
|
|
debug!(
|
|
|
|
"relocating map by symbol index {:?}, kind {:?} at insn {ins_index} in section {}",
|
|
|
|
"relocating map by symbol index {:?}, kind {:?} at insn {ins_index} in section {}",
|
|
|
@ -232,6 +250,8 @@ fn relocate_maps<'a, I: Iterator<Item = &'a Relocation>>(
|
|
|
|
);
|
|
|
|
);
|
|
|
|
debug_assert_eq!(map.symbol_index().unwrap(), rel.symbol_index);
|
|
|
|
debug_assert_eq!(map.symbol_index().unwrap(), rel.symbol_index);
|
|
|
|
m
|
|
|
|
m
|
|
|
|
|
|
|
|
} else if ignored_by_section.contains(§ion_index) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let Some(m) = maps_by_section.get(§ion_index) else {
|
|
|
|
let Some(m) = maps_by_section.get(§ion_index) else {
|
|
|
|
debug!("failed relocating map by section index {}", section_index);
|
|
|
|
debug!("failed relocating map by section index {}", section_index);
|
|
|
@ -580,6 +600,8 @@ mod test {
|
|
|
|
&maps_by_symbol,
|
|
|
|
&maps_by_symbol,
|
|
|
|
&symbol_table,
|
|
|
|
&symbol_table,
|
|
|
|
&HashSet::new(),
|
|
|
|
&HashSet::new(),
|
|
|
|
|
|
|
|
&HashSet::new(),
|
|
|
|
|
|
|
|
&HashSet::new(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
@ -636,6 +658,8 @@ mod test {
|
|
|
|
&maps_by_symbol,
|
|
|
|
&maps_by_symbol,
|
|
|
|
&symbol_table,
|
|
|
|
&symbol_table,
|
|
|
|
&HashSet::new(),
|
|
|
|
&HashSet::new(),
|
|
|
|
|
|
|
|
&HashSet::new(),
|
|
|
|
|
|
|
|
&HashSet::new(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
@ -675,6 +699,8 @@ mod test {
|
|
|
|
&maps_by_symbol,
|
|
|
|
&maps_by_symbol,
|
|
|
|
&symbol_table,
|
|
|
|
&symbol_table,
|
|
|
|
&HashSet::new(),
|
|
|
|
&HashSet::new(),
|
|
|
|
|
|
|
|
&HashSet::new(),
|
|
|
|
|
|
|
|
&HashSet::new(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
@ -731,6 +757,8 @@ mod test {
|
|
|
|
&maps_by_symbol,
|
|
|
|
&maps_by_symbol,
|
|
|
|
&symbol_table,
|
|
|
|
&symbol_table,
|
|
|
|
&HashSet::new(),
|
|
|
|
&HashSet::new(),
|
|
|
|
|
|
|
|
&HashSet::new(),
|
|
|
|
|
|
|
|
&HashSet::new(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|