Lay out an output section's members in its module, as mold does

compute_section_sizes in output_sections.rs laid out each output
section's members itself. mold's compute_section_sizes calls
chunks/output_section.rs's layout for each section in parallel and
records the sizes; the per-section layout is now
chunks::output_section::layout here too. It returns the members'
offsets rather than writing them, as an InputSection's offset is no
atomic here, and compute_section_sizes still records them serially.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Rui UeyamaandClaude Opus 5.5 committed 2026-10-08 17:26:53 +09:00
1 parent a45881b068
commit a33b979f3b
2 files changed
+19 -14

No files matched your search

+16
View File
@@ -73,6 +73,22 @@ impl OutputSection {
}
}
/// Lays out an output section's members, each at its alignment after
/// the one before, and returns their offsets, in member order, and the
/// section's size, for compute_section_sizes to record. mold's layout,
/// which records the offsets itself.
pub fn layout<E: Target>(ctx: &Context<E>, osec: &OutputSection) -> (Vec<u64>, u64) {
let mut offs = Vec::with_capacity(osec.members.len());
let mut off = 0;
for &id in &osec.members {
let isec = &ctx.isecs[id];
off = isec.align_offset(off);
offs.push(off);
off += isec.size as u64;
}
(offs, off)
}
/// Runs `f` in parallel on each member's bytes in `buf`, the output
/// section's contents, along with the bytes up to the next member, as
/// mold's for_each_member does: splitting `buf` at member offsets,
+3 -14
View File
@@ -1162,23 +1162,12 @@ fn sort_section_members<E: Target>(ctx: &mut Context<E>) {
/// later, if a branch can be out of reach at all, once the order of the
/// sections is known (see thunks.rs).
fn compute_section_sizes<E: Target>(ctx: &mut Context<E>) {
let offsets: Vec<(usize, Vec<u64>, u64)> = ctx
let layouts: Vec<(Vec<u64>, u64)> = ctx
.output_sections
.par_iter()
.enumerate()
.map(|(i, osec)| {
let mut offs = Vec::with_capacity(osec.members.len());
let mut off = 0;
for &id in &osec.members {
let isec = &ctx.isecs[id];
off = isec.align_offset(off);
offs.push(off);
off += isec.size as u64;
}
(i, offs, off)
})
.map(|osec| chunks::output_section::layout(ctx, osec))
.collect();
for (i, offs, size) in offsets {
for (i, (offs, size)) in layouts.into_iter().enumerate() {
for (&id, off) in ctx.output_sections[i].members.iter().zip(offs) {
ctx.isecs[id].offset = off as u32;
}