Skip to content

Commit 07f28a6

Browse files
committed
fix: emit .bss section directive before .skip in elf_to_asm_source
1 parent 1a43d14 commit 07f28a6

1 file changed

Lines changed: 25 additions & 14 deletions

File tree

src/ui/view/disasm.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -441,22 +441,33 @@ pub fn elf_to_asm_source(
441441
}
442442

443443
// ── Data sections ────────────────────────────────────────────────────
444-
if !sections.is_empty() {
445-
let _ = writeln!(out);
446-
let _ = writeln!(out, ".data");
447-
for sec in sections {
444+
// Group sections: .bss-like (no file bytes) need ".bss" context;
445+
// others need ".data" context. Track which section we're currently in.
446+
let mut cur_section: Option<&str> = None;
447+
for sec in sections {
448+
let is_bss = sec.bytes.is_empty();
449+
let needed = if is_bss { ".bss" } else { ".data" };
450+
if cur_section != Some(needed) {
448451
let _ = writeln!(out);
449-
let _ = writeln!(
450-
out,
451-
"# --- {} (0x{:08x}, {} bytes) ---",
452-
sec.name, sec.addr, sec.size
453-
);
454-
if sec.bytes.is_empty() {
455-
// .bss: emit placeholder comment; actual zeroing is done by the linker
456-
let _ = writeln!(out, " .skip {}", sec.size);
457-
} else {
458-
emit_data_words(&mut out, &sec.bytes, sec.addr, symbols);
452+
let _ = writeln!(out, "{needed}");
453+
cur_section = Some(needed);
454+
}
455+
let _ = writeln!(out);
456+
let _ = writeln!(
457+
out,
458+
"# --- {} (0x{:08x}, {} bytes) ---",
459+
sec.name, sec.addr, sec.size
460+
);
461+
if is_bss {
462+
// Symbol labels at the bss base, then .skip for size
463+
if let Some(names) = symbols.get(&sec.addr) {
464+
for name in names {
465+
let _ = writeln!(out, "{name}:");
466+
}
459467
}
468+
let _ = writeln!(out, " .skip {}", sec.size);
469+
} else {
470+
emit_data_words(&mut out, &sec.bytes, sec.addr, symbols);
460471
}
461472
}
462473

0 commit comments

Comments
 (0)