Skip to content

Commit f44731d

Browse files
committed
aya-obj: restore text_sections filter in relocation
The previous kfunc relocation changes inadvertently removed the filter that only considers text relocations (data relocations are handled in relocate_maps()). This caused non-text relocations to fall through and hit the todo!() branch. Restore the filter that checks for SymbolKind::Text or symbols whose section_index is in text_sections.
1 parent bcec8ef commit f44731d

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

aya-obj/src/relocation.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,15 @@ impl Object {
151151
/// to the BTF type ID.
152152
pub fn relocate_calls(
153153
&mut self,
154-
_text_sections: &HashSet<usize>,
154+
text_sections: &HashSet<usize>,
155155
kernel_btf: Option<&Btf>,
156156
) -> Result<(), EbpfRelocationError> {
157157
for (name, program) in self.programs.iter() {
158158
let linker = FunctionLinker::new(
159159
&self.functions,
160160
&self.relocations,
161161
&self.symbol_table,
162+
text_sections,
162163
kernel_btf,
163164
);
164165

@@ -286,6 +287,7 @@ struct FunctionLinker<'a> {
286287
linked_functions: HashMap<u64, usize>,
287288
relocations: &'a HashMap<SectionIndex, HashMap<u64, Relocation>>,
288289
symbol_table: &'a HashMap<usize, Symbol>,
290+
text_sections: &'a HashSet<usize>,
289291
kernel_btf: Option<&'a Btf>,
290292
}
291293

@@ -294,13 +296,15 @@ impl<'a> FunctionLinker<'a> {
294296
functions: &'a BTreeMap<(usize, u64), Function>,
295297
relocations: &'a HashMap<SectionIndex, HashMap<u64, Relocation>>,
296298
symbol_table: &'a HashMap<usize, Symbol>,
299+
text_sections: &'a HashSet<usize>,
297300
kernel_btf: Option<&'a Btf>,
298301
) -> Self {
299302
Self {
300303
functions,
301304
linked_functions: HashMap::new(),
302305
relocations,
303306
symbol_table,
307+
text_sections,
304308
kernel_btf,
305309
}
306310
}
@@ -408,6 +412,16 @@ impl<'a> FunctionLinker<'a> {
408412
}
409413
}
410414

415+
// Filter to only consider text relocations - data relocations are
416+
// handled in relocate_maps()
417+
let rel = rel.filter(|(_rel, sym)| {
418+
sym.kind == SymbolKind::Text
419+
|| sym
420+
.section_index
421+
.map(|section_index| self.text_sections.contains(&section_index))
422+
.unwrap_or(false)
423+
});
424+
411425
// not a call and not a text relocation, we don't need to do anything
412426
if !is_call && rel.is_none() {
413427
continue;

0 commit comments

Comments
 (0)