Semi-working REL analysis & splitting

This commit is contained in:
2023-08-25 00:54:29 -04:00
parent 3f63f1ef47
commit a2374e4fa0
21 changed files with 1072 additions and 709 deletions

View File

@@ -151,8 +151,9 @@ impl AnalysisPass for FindRelCtorsDtors {
let possible_sections = obj
.sections
.iter()
.filter(|&(_, section)| {
.filter(|&(index, section)| {
if section.section_known
|| state.known_sections.contains_key(&index)
|| !matches!(section.kind, ObjSectionKind::Data | ObjSectionKind::ReadOnlyData)
|| section.size < 4
{
@@ -283,3 +284,40 @@ impl AnalysisPass for FindRelCtorsDtors {
Ok(())
}
}
pub struct FindRelRodataData {}
impl AnalysisPass for FindRelRodataData {
fn execute(state: &mut AnalyzerState, obj: &ObjInfo) -> Result<()> {
ensure!(obj.kind == ObjKind::Relocatable);
match (obj.sections.by_name(".rodata")?, obj.sections.by_name(".data")?) {
(None, None) => {}
_ => return Ok(()),
}
let possible_sections = obj
.sections
.iter()
.filter(|&(index, section)| {
!section.section_known
&& !state.known_sections.contains_key(&index)
&& matches!(section.kind, ObjSectionKind::Data | ObjSectionKind::ReadOnlyData)
})
.collect_vec();
if possible_sections.len() != 2 {
log::warn!("Failed to find .rodata and .data");
return Ok(());
}
log::debug!("Found .rodata and .data: {:?}", possible_sections);
let rodata_section_index = possible_sections[0].0;
state.known_sections.insert(rodata_section_index, ".rodata".to_string());
let data_section_index = possible_sections[1].0;
state.known_sections.insert(data_section_index, ".data".to_string());
Ok(())
}
}