ref: 7e7f92f18c38cbb755c6c067e42efa19655cd5b1
parent: 746117095688be84f9f4611f14d42644bf761776
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Sun Mar 28 11:21:17 EDT 2021
Assign section locations to all UNIONs/FRAGMENTs Fixes the test case from #800 The `out.gb` output was corrected, since the two "test" fragments have a different order in ROM than in SRAM. It is effectively: ; ROM0[$0000], fragments ordered by size jr Label dw Label db 0 ; SRAM[$a000], fragments ordered by .o order ds 1 ; db 0 ds 2 ; jr Label Label: ; $a003 ds 2 ; dw Label
--- a/src/link/assign.c
+++ b/src/link/assign.c
@@ -112,6 +112,13 @@
section->org = location->address;
section->bank = location->bank;
+ // Propagate the assigned location to all UNIONs/FRAGMENTs
+ // so `jr` patches in them will have the correct offset
+ for (struct Section *next = section->nextu; next != NULL; next = next->nextu) {
+ next->org = section->org;
+ next->bank = section->bank;
+ }
+
nbSectionsToAssign--;
out_AddSection(section);
--- a/test/link/load-fragment/b.asm
+++ b/test/link/load-fragment/b.asm
@@ -1,7 +1,6 @@
-
SECTION "SECTION2", ROM0
LOAD FRAGMENT "test", SRAM
- jr Label
+ jr Label
Label:
dw Label
ENDL
binary files a/test/link/load-fragment/out.gb b/test/link/load-fragment/out.gb differ