Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix align when aligned bug
There was a bug in the linker which caused it to incorrectly
compute the address of labels preceeded by an align directive
that was already aligned, e.g., align 8 on 0x8000, was not
working correctly.  The bug is fixed and a test case has been
added.

Signed-off-by: Mark Ryan <[email protected]>
  • Loading branch information
markdryan committed Jun 17, 2022
commit c75a22f32b5f03c5a9e8cd02acf51b3bb01159ca
3 changes: 2 additions & 1 deletion src/salink.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ static void prv_complete_absolutes_e(void)
align = 1 << label->id;
mask = align - 1;
adjust = (real_off + label->off) & mask;
real_off += align - adjust;
if (adjust > 0)
real_off += align - adjust;
continue;
}
if (label->off > 0xffff - real_off) {
Expand Down
9 changes: 9 additions & 0 deletions tests/test_align_aligned/align_aligned.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.Main
align 8
ld hl, l1
.l1
nop
ld hl, l2
align 8
.l2
ret
21 changes: 21 additions & 0 deletions tests/test_align_aligned/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -e
rm align_aligned 2>/dev/null 1>&2 || true
rm *.x 2>/dev/null 1>&2 || true

../../saimport *.s
../../salink 2>/dev/null 1>&2
offset=`od -An -j1 -t x1 -N2 align_aligned | xargs`
if [ "$offset" != "03 80" ]; then
exit 1
fi

offset=`od -An -j5 -t x1 -N2 align_aligned | xargs`
if [ "$offset" != "08 80" ]; then
exit 1
fi

rm align_aligned
rm *.x