This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Re: gas .macro quirks, and an ARM bug
- To: ulfc at calypso dot engr dot sgi dot com
- Subject: Re: gas .macro quirks, and an ARM bug
- From: Nick Clifton <nickc at cygnus dot com>
- Date: Thu, 8 Jun 2000 11:33:22 -0700
- CC: andrewm at netwinder dot org, binutils at sourceware dot cygnus dot com
Hi Andrew, Hi Ulf,
: > I don't know if these are bugs, features, or coding errors on my part.
: > The first two apply to x86 and ARM, the third applies to ARM alone and
: > looks like a genuine bug. The version of "as" doesn't seem to matter.
: >
: > 1) String arguments passed to macros have their quoting removed.
:
: I'm not sure, but I think this is controlled by the macro_alternate variable
: that is true if TC_A29K is defined.
Well really it is whether AS or GASP is doing the pre-processing. The
A29K just happens to chose an laternative syntax for AS macros.
Anyway as it stands this is not a bug, but a feature. Of course you
should be able to override the removal of quotes by escaping them,
which leads on to..
: > 2) Cannot pass a string argument with escaped characters to macros.
:
: I agree that this is weird. The macros don't support expansion of escaped
: characters in arguments to macros. Escaped characters are just passed on,
: with one exception for the quote character itself. I think the correct
: behaviour would be to pass '\"' and '\'' on as an escaped character and not
: treat them as argument delimiters.
:
: 2000-06-07 Ulf Carlsson <ulfc@engr.sgi.com>
:
: * macro.c (getstring): Make it possible to escape the quote character.
:
: Index: macro.c
: ===================================================================
: RCS file: /cvs/src/src/gas/macro.c,v
: retrieving revision 1.7
: diff -u -p -r1.7 macro.c
: --- macro.c 2000/05/01 14:01:06 1.7
: +++ macro.c 2000/06/07 21:49:26
: @@ -312,6 +312,12 @@ getstring (idx, in, acc)
: idx++ ;
: sb_add_char (acc, in->ptr[idx++]);
: }
: + else if (in->ptr[idx] == '\\' && in->ptr[idx+1] == tchar)
: + {
: + sb_add_char (acc, '\\');
: + sb_add_char (acc, tchar);
: + idx += 2;
: + }
: else
: {
: if (in->ptr[idx] == tchar)
Actually this does not work since it leaves the \ character in the
input stream rather than stripping it out. This causes the error
message:
Error: Rest of line ignored. First ignored character is `\'.
to be emitted. A better fix might be:
Index: macro.c
===================================================================
RCS file: /cvs/src//src/gas/macro.c,v
retrieving revision 1.7
diff -p -r1.7 macro.c
*** macro.c 2000/05/01 14:01:06 1.7
--- macro.c 2000/06/08 18:32:34
*************** getstring (idx, in, acc)
*** 307,313 ****
idx++;
while (idx < in->len)
{
! if (macro_alternate && in->ptr[idx] == '!')
{
idx++ ;
sb_add_char (acc, in->ptr[idx++]);
--- 307,321 ----
idx++;
while (idx < in->len)
{
! if (in->ptr[idx] == '\\')
! {
! idx++;
! if (idx < in->len)
! sb_add_char (acc, in->ptr[idx++]);
! if (idx >= in->len)
! break;
! }
! else if (macro_alternate && in->ptr[idx] == '!')
{
idx++ ;
sb_add_char (acc, in->ptr[idx++]);
So that only the escaped character is added.
: 3) Cannot pass a string argument ending in "=". The "=" cannot be
: escaped with "\=" either.
:
: Example:
: .macro hello arg1
: .data
: .ascii "\arg1"
: .endm
: answer "answer ="
:
: bug3.s: Assembler messages:
: bug3.s:5: Error: bad instruction `answer "answer ="'
This is just a typo in your example. The macro's name is 'hello' not
'answer' so the assembler is correct in saying that there is no such
instruction called 'answer'.
: 4) ARM Specific: The .byte directive causes a long to be assembled
: instead of a byte.
:
: Example:
: .macro hello arg1
: .data
: .byte (2f - 1f)
: 1: .ascii "\arg1"
: 2:
: .endm
: hello "hello world"
:
: a.out: file format elf32-littlearm
: Contents of section .text:
: Contents of section .data:
: 0000 0b000000 6c6f2077 6f726c64 ....lo world
: Disassembly of section .text:
:
: Notice how the "hel" bytes have been overwritten.
This is a bug. I am currently investigating and will post an answer
shortly.
Cheers
Nick