Bug 669 - Macro Expansion is broken
Summary: Macro Expansion is broken
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.15
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-14 23:50 UTC by Eric McVicker
Modified: 2005-05-26 14:58 UTC (History)
1 user (show)

See Also:
Host: powerpc-apple-darwin7.6.0
Target: powerpc-elf32-eabi
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric McVicker 2005-01-14 23:50:15 UTC
During a regression build suite (since migrating from 2.14), it was found that 
the macro expansion within gas is not working properly.  The reason being is 
whitespace.

We have a number of assembly source files that get pre-processed by the GCC 
compiler, and it substitutes some #define references into our assembly source 
code.  The assembly is then passed through to gas, and compiled into object 
code.


The error occurs with the following example:

------ source example ------
        .macro  LADDR reg,sym
        lis     \reg,(\sym)@ha
        addi    \reg,\reg,(\sym)@l
        .endm

        LADDR r3, ((((((0x00380000 + 4096) + 256) + 256) + 256) + 49152) + 4096)

------ end source example -------

This same exact code will assemble flawlessly under binutils 2.14
Comment 1 Nick Clifton 2005-02-07 17:26:46 UTC
Subject: Re:  New: Macro Expansion is broken

Hi mcvick_e,

   [The sourceware bugzilla web site appears to be down at the moment, 
so I am emailing this directly to you as well as the mailing list].

> During a regression build suite (since migrating from 2.14), it was found that 
> the macro expansion within gas is not working properly.  The reason being is 
> whitespace.

I am not sure that this is strictly speaking a bug, since GAS macros are 
supposed to use whitespace to separate their arguments.  What has 
happened is that in 2.15 the code has been tightened up to enforce this 
rule whereas in 2.14 the code was more lax.  This may not help you of 
course.

>         LADDR r3, ((((((0x00380000 + 4096) + 256) + 256) + 256) + 49152) + 4096)

Are you able to arrange your macros so that either the white space is 
eliminated or else the entire argument is enclosed within quotations ?  eg:

  LADDR r3, "((((((0x00380000 + 4096) + 256) + 256) + 256) + 49152) + 4096)"

Alternatively can you use a .set directive to cause the expression to be 
evaluated before it is used by the macro ?  ie:

   .set val,((((((0x00380000 + 4096) + 256) + 256) + 256) + 49152) + 4096)
         LADDR r3, val

Cheers
   Nick
Comment 2 emcvicker@earthlink.net 2005-02-07 19:37:20 UTC
Subject: Re:  Macro Expansion is broken

I am not able to do that.  The expansion is done VIA the GNU C compiler, so it adds all of the associated whitespace to the macro expansion.  Unless there's a magical way that I can get the GNU compiler to not pad macro expansions with whitespace it's outside of my hands.

Thanks,
-Eric


-----Original Message-----
From: nickc at redhat dot com <sourceware-bugzilla@sources.redhat.com>
Sent: Feb 7, 2005 10:26 AM
To: mcvick_e@iname.com
Subject: [Bug gas/669] Macro Expansion is broken


------- Additional Comments From nickc at redhat dot com  2005-02-07 17:26 -------
Subject: Re:  New: Macro Expansion is broken

Hi mcvick_e,

   [The sourceware bugzilla web site appears to be down at the moment, 
so I am emailing this directly to you as well as the mailing list].

> During a regression build suite (since migrating from 2.14), it was found that 
> the macro expansion within gas is not working properly.  The reason being is 
> whitespace.

I am not sure that this is strictly speaking a bug, since GAS macros are 
supposed to use whitespace to separate their arguments.  What has 
happened is that in 2.15 the code has been tightened up to enforce this 
rule whereas in 2.14 the code was more lax.  This may not help you of 
course.

>         LADDR r3, ((((((0x00380000 + 4096) + 256) + 256) + 256) + 49152) + 4096)

Are you able to arrange your macros so that either the white space is 
eliminated or else the entire argument is enclosed within quotations ?  eg:

  LADDR r3, "((((((0x00380000 + 4096) + 256) + 256) + 256) + 49152) + 4096)"

Alternatively can you use a .set directive to cause the expression to be 
evaluated before it is used by the macro ?  ie:

   .set val,((((((0x00380000 + 4096) + 256) + 256) + 256) + 49152) + 4096)
         LADDR r3, val

Cheers
   Nick


Comment 3 Eric McVicker 2005-05-26 14:58:08 UTC
The .set notation works well enough.  Just had to change massive amounts of 
assembly (existing code) to work within the new constraints.