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 0b5f8c62..9445df53 100644 Binary files a/test/link/load-fragment/out.gb and b/test/link/load-fragment/out.gb differ