Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!crackers!m2c!jjmhome!acestes!paradis From: paradis@acestes.UUCP (Jim Paradis) Newsgroups: comp.os.minix Subject: Re: bcc, goto and address out of bound Message-ID: <168@acestes.UUCP> Date: 28 Mar 91 19:49:53 GMT References: <157@petruz.sublink.ORG> <159@petruz.sublink.ORG> Reply-To: paradis@acestes.UUCP (Jim Paradis) Organization: Alberichs Rings & Things Lines: 43 In article <159@petruz.sublink.ORG> root@petruz.sublink.ORG (root) writes: >I got some pieces of code with many , really many , goto's ... it seems >that bcc gets lost with them , It produces a good assembler output but >"as" tells me that there is an address out of bound :-( > >I used also -j option for As , all works fine ... 'till crash ! > > ... what can I do ? ( please don't tell me to clean goto's ... I can't ! ) Ah yes... turns out this is a bug in Bruce's compiler 8-( You see, there are two flavors of conditional jump instructions on the 386; byte displacement and longword displacement. The byte displacement opcodes are of the form 7x, where x codes for the condition you're branching on. The longword displacement instructions use two-byte opcodes: 0f 8x. Thing is, the "x" is the same in both cases, so you can see how it would be really easy to implement the "-j" flag in the compiler; take the original jump instruction, add 0x10, and paste "0f" in front. The bug is that this does NOT work for the UNconditional relative jump instruction, but the assembler tries this trick anyway. The unconditional relative jump byte displacement opcode is "eb"; apply the above trick to it and you get 0f fb. This is an illegal instruction, and your program crashes. How to get around this? The easiest way would be to switch compilers until Bruce can come up with a bug fix. Next easiest would be to port mdb (so you can look at the core dump) and a binary editor (so you can fix the problem). Where the core dump says the illegal instruction occurred, see if you have the offending "0f fb" sequence there. If you do, then replace it with "90 e9". The 90 is a nop, and the e9 is the correct opcode for a longword-relative jump. Since jumps are relative to the start of the instruction FOLLOWING the jump, you don't have to play games with the jump offset. Or you could just get rid of the goto's 8-) 8-) 8-) [sorry, couldn't resist!] Have fun! -- Jim Paradis UUCP: harvard!m2c!jjmhome!acestes!paradis 9 Carlstad St. AT&T: (508) 792-3810 Worcester, MA 01607-1569 ICBM: 42deg 13' 52", 71deg 47' 51"