Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!utcsri!gclark From: gclark@utcsri.UUCP Newsgroups: comp.sys.amiga Subject: Bug in Manx 3.40 linker Message-ID: <4545@utcsri.UUCP> Date: Thu, 9-Apr-87 13:17:45 EST Article-I.D.: utcsri.4545 Posted: Thu Apr 9 13:17:45 1987 Date-Received: Sat, 11-Apr-87 10:49:09 EST Reply-To: gclark@utcsri.UUCP (Graeme Clark) Organization: CSRI, University of Toronto Lines: 26 Keywords: Manx 3.40 ln bug Summary: Short programs may fail 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