[comp.sys.amiga] Bug in Manx 3.40 linker

gclark@utcsri.UUCP (04/09/87)

Believe it or not, the following program is not compiled correctly
by Manx C version 3.40 (using "cc hello.c", "ln hello.o -lc").

main()
{
printf("Hello there everyone out there today.\n");
printf("this is just a simple program which does a few printfs.\n");
}

It appears that the bug is actually in the linker.  At the beginning
of the first code hunk of an executable, the linker places a jump or 
branch instruction to the label ".begin".  Whether a jmp or a bra
instruction is generated depends on the offset between the start of
the hunk and .begin.  If this offset is less than 126, a two-byte bra 
instruction is generated, while if it is greater than 126 a 4-byte
jump instruction is generated.  However, when the offset is exactly
126, the linker goofs, generating a sort of a "brump" instruction.

This problem occurs when the program to be linked has just the right
number of bytes in it, and this number is less than or equal to 126,
so normal-sized programs should not encounter it, but the short programs
one writes occasionally to test some uncertain feature of the language
or the system are at risk.

Graeme Clark -- Dept. of Computer Science, Univ. of Toronto, Canada M5S 1A4
{allegra,cornell,decvax,ihnp4,linus,utzoo}!utcsri!gclark