bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

as: .ifdef treats undefined symbols as defined


From: Miroslav Tichy
Subject: as: .ifdef treats undefined symbols as defined
Date: Thu, 18 Jul 2002 18:14:19 +0200
User-agent: Mutt/1.2.5.1i

BUGREPORT FOR GNU as
--------------------

I have encountered a bug in the following version of GNU as:

GNU assembler 2.11.90
Copyright 2001 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License.  This program has absolutely no warranty.
This assembler was configured for a target of `i686-pc-cygwin'.

alias = i686-pc-cygwin
canonical = i686-pc-cygwin
cpu-type = i686
bfd-target = pe-i386

GNU assembler 2.11.90
Copyright 2001 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License.  This program has absolutely no warranty.
This assembler was configured for a target of `x86_64-unknown-linux-gnu'.

alias = x86_64-unknown-linux-gnu
canonical = x86_64-unknown-linux-gnu
cpu-type = x86_64
bfd-target = elf64-x86-64

in the first case it is a precompiled version,
whereas in the second case it was compiled with
gcc 2.95.3-5 (Cygwin distribution)

tested with latest release (2.12.1 i686-unknown-linux-gnu) the bug is still
there ant he patch still works
coompiled with gcc 2.96


DESCRIPTION
-----------

in the info file you describe:

`.equiv SYMBOL, EXPRESSION'
===========================

   The `.equiv' directive is like `.equ' and `.set', except that the
assembler will signal an error if SYMBOL is already defined.

   Except for the contents of the error message, this is roughly
equivalent to
     .ifdef SYM
     .err
     .endif
     .equ SYM,VAL


while in fact:

$ as << END
jmp A
.equiv A, .
END

assembles ok, while

$ as << END
jmp A
.ifdef A
.err
.endif
.equ A, .
END

fails with:
{standard input}: Assembler messages:
{standard input}:3: Error: .err encountered

there is therefore a bug (a) in the info file, or (b) in the assembler
it depends whether the ``already defined'' in definition of `.equiv'
is different from ``has been defined''  in the definition of `.ifdef' and
`.ifndef'
The info files are not clear in this matter:

> File: as.info,  Node: Symbol Attributes,.......
> ....
>    If you use a symbol without defining it, `as' assumes zero for all
> these attributes, and probably won't warn you.  This makes the symbol
> an externally defined symbol, which is generally what you would want.

Therefore mentioned symbol is defined albeit externally.  Moreover we
externally define a symbol that we do not define. (sic).

> File: as.info,  Node: Symbol Value, .......
> ..........
>   The value of an undefined symbol is treated in a special way.  If it
> is 0 then the symbol is not defined in this assembler source file, and
> `ld' tries to determine its value from other files linked into the same
> program.  You make this kind of symbol simply by mentioning a symbol
> name without defining it.  A non-zero value represents a `.comm' common
> declaration.  The value is how much common storage to reserve, in bytes
> (addresses).  The symbol refers to the first address of the allocated
> storage.

Now when we mention a symbol we do not define it, therefore it is an undefined
symbol.  Or do we define it as being undefined symbol?  In this case we would
then have defined undefined symbol.  Right?

let's assume `foo SYMBOL' is a valid instruction:

then after assembling the following input:
        .text
A:
        foo B
B:
        foo C
        .end
the symbols will be thus:
A       undefined defined OR defined defined
B       defined defined
C       defined undefined
D       undefined undefined
where the first (un)defined means actually (un)mentioned



PATCH
-----

this patch makes .ifdef use the same test as .equiv (mostly)

this patch makes possible to use:
.ifndef label
label:
.endif
to make sure ``label'' is defined.

--- cond.c2     Thu Jul 18 17:57:23 2002
+++ cond.c      Thu Jul 18 18:01:51 2002
@@ -89,7 +89,11 @@
       *input_line_pointer = c;
 
       initialize_cframe (&cframe);
-      cframe.ignoring = cframe.dead_tree || !((symbolP != 0) ^ arg);
+      /* modified to reflect the ``undefinedness'' test in `read.c'
+       during handling of ``.equiv'' directive */
+      cframe.ignoring = cframe.dead_tree
+         || !( ((symbolP != 0) && S_IS_DEFINED (symbolP)
+             && (S_GET_SEGMENT (symbolP) != reg_section)) ^ arg);
       current_cframe = ((struct conditional_frame *)
                        obstack_copy (&cond_obstack, &cframe,
                                      sizeof (cframe)));



reply via email to

[Prev in Thread] Current Thread [Next in Thread]