ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1992/04/02/05:20:59

Date: Thu, 2 Apr 92 20:07 +1000
From: Bill Metzenthen <APM233M AT vaxc DOT cc DOT monash DOT edu DOT au>
Subject: Aaarrrgh, gas features!
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Status: O

Fellow netters,
               after several hours of bug-hunting assembler code, I
thought that I would share the results of my experiences.

Here is a little file which I call gasbugs.doc:

-------------------------- snip, snip -----------------------------------
gas, the GNU "as" assembler is a very simple assembler.
Its prime use is as an assembler stage for GNU C.
It can be used as a stand alone assembler. However, unless some care
is taken, many hours can lost while one attempts to track down
bugs in code only to find that the "bugs" were due to "features"
of gas!

Here are some of the dangerous features:

(1) There is very little checking of labels.
  (a) Almost any label which is defined in a module will automatically
      become globally visible. If you are in the habit of using similar
      labels in all of your modules (who doesn't do this?), then be prepared
      for the linker to start barfing!
  (b) Any reference which is not defined in a module will automatically
      become an "extern". Thus you only become aware of undefined references
      at the linking stage. Worse still, it may happen that your undefined
      reference is actually defined as an unrelated object in some other
      module; happy bug hunting!!
  (c) Any identifer which begins with the character 'L' is treated differently.
      It is not globally visible (unless declared ???). If a reference is
      made to such a label which does not actually exist in the current
      module, its value will remain zero; e.g.
                              jmp Label_one
      will generate code to jump to the start of the current module if
      Label_one is not defined in the current module. This can cause severe
      hair loss!

(2) gas uses the classical "C" method for comments. Comments do not nest.
    You can live with non-nesting comments in most "C" code because many
    errors which you make with comments will lead to syntax errors in "C".
    Assembler code is much less sensitive, and because of the properties in
    (1) above, gas is particularly bad for the state of your hair! Consider
    the following:
                      mov $1,%eax
                      /*-----------------------+
                       | An important comment  |
                       +-----------------------+
          Label_one   addl $1,(%ecx)
                      adcl $0,4(%ecx)        /* Widget count incremented */

    See the problem? Two lines of code are actually inside a comment, and
    Label_one will not be defined in the current module!
(3) gas has at least one code-generation bug. Specifically, if the target
    of a "jcxz" is out of range then gas will emit a jcxz to an incorrect
    location without issuing any warning message.


---------------
W. Metzenthen
apm233m AT vaxc DOT cc DOT monash DOT edu DOT au
30th March 1992
-------------------------- snip, snip -----------------------------------

Happy bug hunting,
         Bill

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019