From a91d26192d1bdc8757ce7e2913e22fd600a99f50 Mon Sep 17 00:00:00 2001 From: Rangi Date: Tue, 6 Jan 2026 17:53:47 -0500 Subject: [PATCH] Fix `SECTION UNION` alignment depending on piece order --- src/link/section.cpp | 1 + test/link/section-union/compat/a.asm | 4 ++++ test/link/section-union/compat/b.asm | 17 +++++++++++++++++ test/link/section-union/compat/ref.out.bin | Bin 0 -> 16384 bytes test/link/section-union/compat/script.link | 5 +++++ test/link/test.sh | 9 +++++++++ 6 files changed, 36 insertions(+) create mode 100644 test/link/section-union/compat/a.asm create mode 100644 test/link/section-union/compat/b.asm create mode 100644 test/link/section-union/compat/ref.out.bin create mode 100644 test/link/section-union/compat/script.link diff --git a/src/link/section.cpp b/src/link/section.cpp index 10146714..5abccdd8 100644 --- a/src/link/section.cpp +++ b/src/link/section.cpp @@ -96,6 +96,7 @@ static void checkSectUnionCompat(Section &target, Section &other) { if (checkAgainstFixedAlign(target, other, other.alignOfs)) { target.isAlignFixed = true; target.alignMask = other.alignMask; + target.alignOfs = other.alignOfs; } } } diff --git a/test/link/section-union/compat/a.asm b/test/link/section-union/compat/a.asm new file mode 100644 index 00000000..d7b901a0 --- /dev/null +++ b/test/link/section-union/compat/a.asm @@ -0,0 +1,4 @@ +SECTION "ROM", ROM0 +LOAD UNION "U", WRAM0 + ds 1 +ENDL diff --git a/test/link/section-union/compat/b.asm b/test/link/section-union/compat/b.asm new file mode 100644 index 00000000..7428f1fb --- /dev/null +++ b/test/link/section-union/compat/b.asm @@ -0,0 +1,17 @@ +SECTION "R1", WRAM0 + ds $77 + +SECTION "R2", WRAM0 + ds $ef + +SECTION UNION "U", WRAM0 + ds $52e + +SECTION UNION "U", WRAM0 +wStart:: + ds $89 + assert @ & $FF == 0, "wContent must be 8-bit aligned" + align 8 +wContent:: + ds $111 +wEnd:: diff --git a/test/link/section-union/compat/ref.out.bin b/test/link/section-union/compat/ref.out.bin new file mode 100644 index 0000000000000000000000000000000000000000..294f4016d05bdd696670c4840f1f36a71f9239de GIT binary patch literal 16384 zcmeIuF#!Mo0K%a4Pi+hzh(KY$fB^#r3>YwAz<>b*1`HT5V8DO@0|pEjFkrxd0RsjM q7%*VKfB^#r3>YwAz<>b*1`HT5V8DO@0|pEjFkrxd0RsjMyaxtA00031 literal 0 HcmV?d00001 diff --git a/test/link/section-union/compat/script.link b/test/link/section-union/compat/script.link new file mode 100644 index 00000000..bb3b77c7 --- /dev/null +++ b/test/link/section-union/compat/script.link @@ -0,0 +1,5 @@ +WRAM0 + align 8 + "R1" + "U" + "R2" diff --git a/test/link/test.sh b/test/link/test.sh index 78533e7f..d098efa0 100755 --- a/test/link/test.sh +++ b/test/link/test.sh @@ -390,6 +390,15 @@ rgblinkQuiet "$otemp" "$gbtemp" 2>"$outtemp" tryDiff "$test"/out.err "$outtemp" evaluateTest +test="section-union/compat" +startTest +"$RGBASM" -o "$otemp" "$test"/a.asm +"$RGBASM" -o "$gbtemp2" "$test"/b.asm +continueTest +rgblinkQuiet -o "$gbtemp" -l "$test"/script.link "$otemp" "$gbtemp2" +tryCmpRom "$test"/ref.out.bin +evaluateTest + test="section-union/good" startTest "$RGBASM" -o "$otemp" "$test"/a.asm