From 9d5807c2ecfc0070da16c0c44fd7227dfaf59831 Mon Sep 17 00:00:00 2001 From: angie Date: Sun, 5 May 2024 09:40:59 -0400 Subject: [PATCH] Fix some sections not being emitted if there's overlap between the keys and values of section_order --- slinky/src/linker_writer.rs | 12 ++++++------ tests/test_cases/section_order_reorder.ld | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/slinky/src/linker_writer.rs b/slinky/src/linker_writer.rs index 5896a7c..613c788 100644 --- a/slinky/src/linker_writer.rs +++ b/slinky/src/linker_writer.rs @@ -669,12 +669,12 @@ impl LinkerWriter<'_> { // Keys specify the section and value specify where it will be put // For example: `section_order: { .data: .rodata }`, meaning the `.data` of the file should be put within its `.rodata` - // This section should be placed somewhere else - if file.section_order.contains_key(section) { - continue; - } - - let mut sections_to_emit_here = vec![section]; + let mut sections_to_emit_here = if file.section_order.contains_key(section) { + // This section should be placed somewhere else + vec![] + } else { + vec![section] + }; // Check if any other section should be placed be placed here for (k, v) in &file.section_order { diff --git a/tests/test_cases/section_order_reorder.ld b/tests/test_cases/section_order_reorder.ld index f607513..a15b437 100644 --- a/tests/test_cases/section_order_reorder.ld +++ b/tests/test_cases/section_order_reorder.ld @@ -11,6 +11,7 @@ SECTIONS FILL(0x00000000); code_TEXT_START = .; build/src/code/main.o(.text*); + build/src/code/engine.o(.sdata*); build/src/code/entities.o(.text*); build/src/code/background.o(.text*); build/src/code/music.o(.text*); @@ -23,6 +24,7 @@ SECTIONS code_DATA_START = .; build/src/code/main.o(.data*); + build/src/code/engine.o(.text*); build/src/code/background.o(.data*); build/src/code/background.o(.rodata*); . = ALIGN(., 0x10); @@ -31,6 +33,7 @@ SECTIONS code_RODATA_START = .; build/src/code/main.o(.rodata*); + build/src/code/engine.o(.data*); build/src/code/entities.o(.data*); build/src/code/entities.o(.rodata*); build/src/code/sfx.o(.text*); @@ -43,6 +46,7 @@ SECTIONS code_SDATA_START = .; build/src/code/main.o(.sdata*); + build/src/code/engine.o(.rodata*); build/src/code/entities.o(.sdata*); build/src/code/background.o(.sdata*); . = ALIGN(., 0x10);