Skip to content

Commit

Permalink
liblink: fix the alignement of large code blocks
Browse files Browse the repository at this point in the history
Previously, we aligned 8-byte ops to 8 bytes. This is wrong, only DWORDs
need to be 8-byte alligned. 8-byte code sequences (i.e. 2 instructions)
need to follow one another without padding.

This code used to be misassembled like this:

	TEXT foo(SB),7,$-8
		MOV	$bar(SB), R4
		MOV	bar(SB), R5
		RET

	0x0000 c4 00 00 58 00 00 00 00 e1 00 00 58 25 00 40 f9  ...X.......X%.@.
	0x0010 c0 03 5f d6 00 00 00 14 00 00 00 00 00 00 00 00  .._.............
	0x0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................

Notice the 4 zero bytes at 0x4. Now it's:

	0x0000 c4 00 00 58 e1 00 00 58 25 00 40 f9 c0 03 5f d6  ...X...X%.@..._.
	0x0010 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00  ................
	0x0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  • Loading branch information
4ad committed Jan 8, 2015
1 parent a1eefef commit b6e15ed
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/liblink/asm7.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ span7(Link *ctxt, LSym *cursym)
o = oplook(ctxt, p);
// need to align DWORDs on 8-byte boundary. The ISA doesn't
// require it, but the various 64-bit loads we generate assume it.
if(o->size == 8 && psz % 8 != 0) {
if(o->as == ADWORD && psz % 8 != 0) {
*(int32*)bp = 0;
bp += 4;
psz += 4;
Expand Down

0 comments on commit b6e15ed

Please sign in to comment.