Match original "exec" for REL sections
mwld writes empty code sections as NULL type in the PLF, but sometimes the original REL has the exec flag set for these sections. Match the original value.
This commit is contained in:
parent
3841004947
commit
761a940f9e
|
@ -346,8 +346,11 @@ fn make(args: MakeArgs) -> Result<()> {
|
||||||
section_count: None,
|
section_count: None,
|
||||||
quiet: args.no_warn,
|
quiet: args.no_warn,
|
||||||
section_align: None,
|
section_align: None,
|
||||||
|
section_exec: None,
|
||||||
};
|
};
|
||||||
if let Some((header, _, section_defs)) = existing_headers.get(&(module_id as u32)) {
|
if let Some((header, section_headers, section_defs)) =
|
||||||
|
existing_headers.get(&(module_id as u32))
|
||||||
|
{
|
||||||
info.version = header.version;
|
info.version = header.version;
|
||||||
info.name_offset = Some(header.name_offset);
|
info.name_offset = Some(header.name_offset);
|
||||||
info.name_size = Some(header.name_size);
|
info.name_size = Some(header.name_size);
|
||||||
|
@ -358,6 +361,7 @@ fn make(args: MakeArgs) -> Result<()> {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|defs| defs.iter().map(|def| def.align).collect())
|
.map(|defs| defs.iter().map(|def| def.align).collect())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
info.section_exec = Some(section_headers.iter().map(|s| s.exec()).collect());
|
||||||
}
|
}
|
||||||
let rel_path = path.with_extension("rel");
|
let rel_path = path.with_extension("rel");
|
||||||
let mut w = buf_writer(&rel_path)?;
|
let mut w = buf_writer(&rel_path)?;
|
||||||
|
|
|
@ -688,6 +688,10 @@ pub struct RelWriteInfo {
|
||||||
pub quiet: bool,
|
pub quiet: bool,
|
||||||
/// Override individual section alignment in the file.
|
/// Override individual section alignment in the file.
|
||||||
pub section_align: Option<Vec<u32>>,
|
pub section_align: Option<Vec<u32>>,
|
||||||
|
/// Override individual section executable status in the file.
|
||||||
|
/// This is used to match empty sections: mwld will emit them with
|
||||||
|
/// NULL type, but the original REL may have them marked executable.
|
||||||
|
pub section_exec: Option<Vec<bool>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const PERMITTED_SECTIONS: [&str; 7] =
|
pub const PERMITTED_SECTIONS: [&str; 7] =
|
||||||
|
@ -1006,12 +1010,12 @@ where
|
||||||
offset = current_data_offset;
|
offset = current_data_offset;
|
||||||
current_data_offset += section.size() as u32;
|
current_data_offset += section.size() as u32;
|
||||||
}
|
}
|
||||||
RelSectionHeader::new(
|
let exec = info
|
||||||
offset,
|
.section_exec
|
||||||
section.size() as u32,
|
.as_ref()
|
||||||
section.kind() == object::SectionKind::Text,
|
.and_then(|m| m.get(section_index as usize).copied())
|
||||||
)
|
.unwrap_or(section.kind() == object::SectionKind::Text);
|
||||||
.to_writer(w, Endian::Big)?;
|
RelSectionHeader::new(offset, section.size() as u32, exec).to_writer(w, Endian::Big)?;
|
||||||
permitted_section_idx += 1;
|
permitted_section_idx += 1;
|
||||||
} else {
|
} else {
|
||||||
RelSectionHeader::new(0, 0, false).to_writer(w, Endian::Big)?;
|
RelSectionHeader::new(0, 0, false).to_writer(w, Endian::Big)?;
|
||||||
|
|
Loading…
Reference in New Issue