Partially revert "Rework section alignment handling"

It turns out we can't actually
trust mwld to put our alignment
values in the PLF. Sad.
This commit is contained in:
Luke Street 2024-06-10 00:37:17 -06:00
parent 4dd2ebf85a
commit 4ea4ec86d0
1 changed files with 20 additions and 10 deletions

View File

@ -30,7 +30,7 @@ use crate::{
cmd::dol::{ModuleConfig, ProjectConfig}, cmd::dol::{ModuleConfig, ProjectConfig},
obj::{ObjInfo, ObjReloc, ObjRelocKind, ObjSection, ObjSectionKind, ObjSymbol}, obj::{ObjInfo, ObjReloc, ObjRelocKind, ObjSection, ObjSectionKind, ObjSymbol},
util::{ util::{
config::is_auto_symbol, config::{is_auto_symbol, read_splits_sections, SectionDef},
dol::process_dol, dol::process_dol,
elf::{to_obj_reloc_kind, write_elf}, elf::{to_obj_reloc_kind, write_elf},
file::{buf_reader, buf_writer, map_file, process_rsp, verify_hash, FileIterator}, file::{buf_reader, buf_writer, map_file, process_rsp, verify_hash, FileIterator},
@ -170,7 +170,12 @@ fn load_rel(module_config: &ModuleConfig) -> Result<RelInfo> {
let mut reader = file.as_reader(); let mut reader = file.as_reader();
let header = process_rel_header(&mut reader)?; let header = process_rel_header(&mut reader)?;
let sections = process_rel_sections(&mut reader, &header)?; let sections = process_rel_sections(&mut reader, &header)?;
Ok((header, sections)) let section_defs = if let Some(splits_path) = &module_config.splits {
read_splits_sections(splits_path)?
} else {
None
};
Ok((header, sections, section_defs))
} }
fn resolve_relocations( fn resolve_relocations(
@ -186,11 +191,12 @@ fn resolve_relocations(
if !matches!(section.name(), Ok(name) if PERMITTED_SECTIONS.contains(&name)) { if !matches!(section.name(), Ok(name) if PERMITTED_SECTIONS.contains(&name)) {
continue; continue;
} }
let section_index = if let Some((_, sections)) = existing_headers.get(&(module_id as u32)) { let section_index =
match_section_index(module, section.index(), sections)? if let Some((_, sections, _)) = existing_headers.get(&(module_id as u32)) {
} else { match_section_index(module, section.index(), sections)?
section.index().0 } else {
} as u8; section.index().0
} as u8;
for (address, reloc) in section.relocations() { for (address, reloc) in section.relocations() {
let reloc_target = match reloc.target() { let reloc_target = match reloc.target() {
RelocationTarget::Symbol(idx) => { RelocationTarget::Symbol(idx) => {
@ -217,7 +223,7 @@ fn resolve_relocations(
(module_id, reloc_target) (module_id, reloc_target)
}; };
let target_section_index = target_symbol.section_index().unwrap(); let target_section_index = target_symbol.section_index().unwrap();
let target_section = if let Some((_, sections)) = let target_section = if let Some((_, sections, _)) =
existing_headers.get(&(target_module_id as u32)) existing_headers.get(&(target_module_id as u32))
{ {
match_section_index(&modules[target_module_id].0, target_section_index, sections)? match_section_index(&modules[target_module_id].0, target_section_index, sections)?
@ -240,7 +246,7 @@ fn resolve_relocations(
Ok(resolved) Ok(resolved)
} }
type RelInfo = (RelHeader, Vec<RelSectionHeader>); type RelInfo = (RelHeader, Vec<RelSectionHeader>, Option<Vec<SectionDef>>);
fn make(args: MakeArgs) -> Result<()> { fn make(args: MakeArgs) -> Result<()> {
let total = Instant::now(); let total = Instant::now();
@ -341,13 +347,17 @@ fn make(args: MakeArgs) -> Result<()> {
quiet: args.no_warn, quiet: args.no_warn,
section_align: None, section_align: None,
}; };
if let Some((header, _)) = existing_headers.get(&(module_id as u32)) { if let Some((header, _, 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);
info.align = header.align; info.align = header.align;
info.bss_align = header.bss_align; info.bss_align = header.bss_align;
info.section_count = Some(header.num_sections as usize); info.section_count = Some(header.num_sections as usize);
info.section_align = section_defs
.as_ref()
.map(|defs| defs.iter().map(|def| def.align).collect())
.unwrap_or_default();
} }
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)?;