home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / minix / 5273 < prev    next >
Encoding:
Text File  |  1993-01-27  |  8.5 KB  |  183 lines

  1. Newsgroups: comp.os.minix
  2. Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!emory!sol.ctr.columbia.edu!ira.uka.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!sun4nl!relay.philips.nl!philce!meulenbr
  3. From: meulenbr@ce.philips.nl (Frans Meulenbroeks)
  4. Subject: Re: ACK ANSI Compiler
  5. Message-ID: <1993Jan26.123007.12062@philce.ce.philips.nl>
  6. Sender: usenet@philce.ce.philips.nl (USENET post news)
  7. Organization: Philips Consumer Electronics, Eindhoven
  8. References: <1993Jan21.075806.29635@philce.ce.philips.nl> <93012418390@monty.apana.org.au>
  9. Date: Tue, 26 Jan 1993 12:30:07 GMT
  10. Lines: 171
  11.  
  12. newton@monty.apana.org.au (Mark Newton) writes:
  13.  
  14. >meulenbr@ce.philips.nl (Frans Meulenbroeks) writes:
  15. >> newton@monty.apana.org.au (Mark Newton) writes:
  16. >> [...]
  17. >> >The 68000 ACK compiler has bugs - BAD bugs. [...]
  18. >> 
  19. >> ...
  20. >> 
  21. >> I challenge you to send a bug list to the net to prove your statement!
  22.  
  23. >Oh dear.  He wants me to enumerate them <sigh>
  24.  
  25. >A large number of MINIX programs which wouldn't work with the ACK
  26. >compiler have compiled flawlessly on my system (and a number of other
  27. >68000 MINIX systems which I am acquainted with) with c68.
  28.  
  29. >I'm not talking about programs that came with the MINIX distribution;
  30. >they'd be expected to work properly when compiled with ACK.  But, third
  31. >party packages like Minicom 1.2, FvK's UUCP, Nethack 1.2e, the curses
  32. >package on plains, and parts of Elm 2.4 wouldn't work correctly with
  33. >ACK on any of the Amiga MINIX systems I know.  And fixing them was as
  34. >simple as unarchiving the sources and recompiling them with c68.
  35.  
  36. This is not necessary the fault of the compiler. I've compiled a lot of
  37. programs using the K&R compiler, and if the programs do not run then 
  38. almost always this ast because the code is sloppy, not because the
  39. compiler is bad.
  40.  
  41. The basic problem is that with ACK for 68000 the assumption that
  42. sizeof(int)==sizeof(char *) does not hold. With ACK/68000 ints are 2
  43. bytes and pointers are 4. There is a lot code floating around which
  44. thinks it is safe to stuff an pointer into an int. Heck even the unix v7
  45. nroff which I ported to 68000 about 9 years ago suffered from this
  46. problem.
  47.  
  48. Note however that C never ever requires ints and pointers to be of the
  49. same size.
  50.  
  51. The following things typically cause problems:
  52. 1) the source code does not include a forward declaration for a function
  53.    returning a pointer (e.g. malloc). If you call such a function and
  54.    the compiler hasn't seen a declaration for the function, it assumes
  55.    that it is a function returning int. With K&R ack this means that you
  56.    get a 16 bit value, not a 32 bit one. Even if you assign this value
  57.    to a pointer it still has the wrong contents. If you use this pointer
  58.    you are not writing into the memory you allocated, but into low
  59.    memory, thus destroying the operating system code (which is caused by
  60.    the fact that 68000 systems do not tend to have an MMU, which can
  61.    give protection for this).
  62.    If c68 has 16 bits int and still returns a 32 bit value if no
  63.    prototype is present c68 is broken (although it does by accident what
  64.    you wanted it to do).
  65. 2) parameters are not passed properly. If, with a K&R compiler you pass
  66.    0 as a parameter to a function on a place where a pointer is expected,
  67.    then only 2 bytes are pushed onto the stack while for passing a
  68.    pointer 4 bytes are pushed. If the caller only gives 2 bytes, while
  69.    the callee expects 4, then the callee is going to get faulty data.
  70.    possible fixes are: add an explicit cast to the pointer
  71.                use an ansi compiler an prototypes
  72.                use a compiler where sizeof(pointer)==sizeof(int)
  73. 3) The program uses arrays > 64k. Out of my head I'm not sure if a K&R
  74.    compiler may limit the size of an array. I believe ansi will.
  75.    anyway, this is the most irritating limitation I encountered.
  76. 4) dereferencing NULL pointers. On an amiga maybe this is possible, but
  77.    on an atari it definitely isn't. Code which dereferences a NULL
  78.    pointer IMHO is broken.
  79.  
  80. If c68 does not have problems with this then either pointers and ints
  81. have the same size, or it is an ansi compiler.
  82.  
  83. >When I say "they didn't work correctly," I don't mean that they'd just
  84. >dump core and squirt an error message onto the console.  I mean that
  85. >they'd crash the entire machine and necessitate a reboot.
  86.  
  87. The fact that the machine crashes is because there is no protection
  88. hardware. Any job can write everywhere in memory causing other programs
  89. or the kernel to crash.
  90.  
  91. >The most common kind of constructs which would cause such crashes were
  92. >operations on strings declared with constant initializers:
  93.  
  94. >  char *foo = "this will crash my computer when I use strcpy() on it!";
  95.  
  96. >(no, it wouldn't do it in every situation; it was most insidious, and
  97. >spending time with debuggers to work out the exact sequence of instructions
  98. >that would cause a crash didn't do a whole lot of good for this little
  99. >black duck.  I've never claimed to be an assembly language guru anyway
  100. >:-)
  101.  
  102. It depends on how you strcpy it. If you use the return value of strcpy
  103. and didn't declare the function, then, on a 68000 system without mmu, 
  104. it is highly likely that the system crashes. The compiler is not to
  105. blame for the fact that your code is wrong.
  106. If you still think the compiler is doing something wrong there then
  107. please mail me a *small* program demonstrating the problem. 
  108.  
  109. >I spent many an evening going through errant sources and changing them
  110. >to something like this:
  111.  
  112. >   char foo[size_of_the_damned_string];
  113. >   strcpy(foo, "this will not crash my computer...");
  114.  
  115. >to prevent lockups.
  116.  
  117. >(not to mention the lockups that bar = time() would cause when time()
  118. >would try to write its current timer value to a pointer argument that
  119. >hadn't been supplied - bar = time(NULL) was the simple fix for that.
  120. >bar = time() doesn't crash at all when c68 is used over the same source
  121. >code).
  122.  
  123. If bar = time() does not crash under c68, then you have been lucky.
  124. Time is a function with a pointer as parameter. So calling 
  125. bar=time() is just not valid. The time function still gets a parameter
  126. from the stack (which is not there so essentially it is getting garbage).
  127. By sheer luck your code works with c68.
  128. By the way:
  129. bar = time(0) also won't do the job with a K&R compiler since 0 is not a
  130. pointer and time requires a pointer argument. 
  131. bar = time((char *)0) is ok, since then 0 is casted to a pointer.
  132. If you have full ansi include files, the proper way to do this
  133. is bar = time((time_t)0) or probably bar = time_t(NULL).
  134.  
  135. >Now, I acknowledge that the problem was as much with the kernel as with
  136. >the compiler, but all of those hassles dried up the instant I stopped
  137. >using ACK and switched to c68.  Magic, eh?  Now my system stays up for
  138. >days on end without problems, even when I'm doing heavy development work.
  139.  
  140. >Even now, if I accidentally type "cc" instead of "cc68" to compile
  141. >something I've been working on, and run it without realizing it, crashes
  142. >occur.  Compile it with c68 and bingo!  Flawless operation.
  143.  
  144. Hm. I'm still not convinced that K&R ACK is that broken.
  145.  
  146. >Everyone who's been in this newsgroup for more than a few months knows
  147. >that the K&R ACK compiler had bugs, and the 680x0 version was worse than
  148. >the Intel version.  As far as I can tell, the only reason it isn't talked
  149. >about much these days is because all the people who know what has been
  150. >causing their system crashes for all these years have switched over to
  151. >c68.  I'm not sure if the Walker brothers realize what a godsend that
  152. >compiler has been to me and every other MINIX user I know.
  153.  
  154. I've been around more often than most of you, but I haven't seen that
  155. much bug reports of the K&R/68000 compiler. I've seen a lot of sloppy
  156. code though.
  157.  
  158. >End of diatribe.
  159.  
  160. >For corrobative purposes, could anyone out there running stock-standard
  161. >v1.5.10.1 or 1.5.10.2 Amiga MINIX please try an experiment for me?  ftp
  162. >the curses package from plains (I _think_ it's on plains!), compile it
  163. >up, and try to run the demo that comes with it.  I'd recommend that you
  164. >type "sync" before you try it out; The system won't stay alive for long
  165. >enough to flush your buffer cache :-)
  166.  
  167. I can't ftp so I cannot test this. However, most implementations of
  168. curses I've seen were sloppy. Long ago I posted some diffs for BSD
  169. curses to allow using them with ack cc.
  170.  
  171. >Then rebuild it with c68 v4.x and run the demo again.  Magic!
  172.  
  173. >(then compile your kernel with it - does the 30k decrease in size
  174. >surprise you?)
  175.  
  176. No. I don't think anyone on the net ever said that ACK/68000 did 
  177. produce compact code. If you want compact code and have some
  178. megabytes to spare go for gcc.
  179.  
  180. --
  181. Frans Meulenbroeks        Philips Research Laboratories
  182. preferred email address:     meulenbr@prl.philips.nl
  183.