From 7e7f92f18c38cbb755c6c067e42efa19655cd5b1 Mon Sep 17 00:00:00 2001 From: Rangi Date: Sun, 28 Mar 2021 15:21:17 -0400 Subject: [PATCH] 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 --- src/link/assign.c | 7 +++++++ test/link/load-fragment/b.asm | 3 +-- test/link/load-fragment/out.gb | Bin 5 -> 5 bytes 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/link/assign.c b/src/link/assign.c index bb620446..91908fe1 100644 --- a/src/link/assign.c +++ b/src/link/assign.c @@ -112,6 +112,13 @@ static inline void assignSection(struct Section *section, 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); diff --git a/test/link/load-fragment/b.asm b/test/link/load-fragment/b.asm index c0a63f08..246005c8 100644 --- 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 diff --git a/test/link/load-fragment/out.gb b/test/link/load-fragment/out.gb index 0b5f8c62cc557da6fca1cebc57a0af1fa32df19c..9445df53526eb869193e5e092971678eec3e7c03 100644 GIT binary patch literal 5 Mcmb1OWM04k00GJXy#N3J literal 5 McmZROU|?nd003(M8~^|S