[comp.sys.mac.programmer] Interesting Aztec ln bug.

earleh@eleazar.dartmouth.edu (Earle R. Horton) (07/28/89)

     I ran into this interesting bug when adapting Apple Sample Code
12, Signals, to use with Aztec C.  The Aztec linker will not resolve
inter-module short branches in MPW object files correctly.  (What kind
of pervert uses inter-module short branches, you say?  Well, someone
at Apple seems to think they are real neat.)

     Here's an example, the source is in MPW Assembler, and the object
file will be linked into an Aztec C program using "ln."

Junk.a:

FOO	PROC	EXPORT
	IMPORT	BAZ
	NOP
	BRA.S	BAZ
	NOP
	ENDP
FOO2	PROC	EXPORT
	EXPORT	BAZ
	NOP
BAZ	DC.W	$A9FF	;_Debugger
	NOP
	ENDP
	END

     Assemble junk.a with MPW Asm, then link it as follows, then look
at the output.

asm junk.a
ln junk.a.o -o junk
dumpcode junk
...
00000000: 4E71            'Nq'            NOP
00000002: 60FC            '`.'            BRA.S    *-$0002  ;00000000
00000004: 5671 4E71       'VqNq'          ADDQ.W   #$3,$71(A1,D4.L*8)
00000008: A9FF            '..'            _Debugger         ; A9FF
0000000A: 4E71            'Nq'            NOP  

     Apparently, the Aztec linker just doesn't understand how to edit
this type of reference properly, since the resulting code is not
exactly what I had in mind.  The solution is to change all such
branches into word branches, and re-assemble the source file.

     Note that the bad code produced by the linker is in the form of
an infinite loop.  There was a lot of wailing and gnashing of teeth
before I got this debugged, since the body of the bogus loop is not
always a NOP in real code!

Earle R. Horton