Bug 1070 - Assembler error: too many positional arguments
Summary: Assembler error: too many positional arguments
Status: RESOLVED WONTFIX
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.16
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-14 16:24 UTC by Earl Olsen
Modified: 2016-12-21 04:10 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Support parenthesis enclosed macro arguments (889 bytes, patch)
2005-07-19 12:31 UTC, Nick Clifton
Details | Diff
preserve round parentheses (642 bytes, patch)
2005-08-09 15:46 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Earl Olsen 2005-07-14 16:24:04 UTC
Either cpp or the assembler is at fault in this problem.

Using gcc on the following code causes the assembler to issue
the error "too many positional arguments"

# Load immediate word, has to be done with 2 instructions 
    .macro lwi reg,val 
    lis \reg,\val@H 
    ori \reg,\reg,\val@L 
    .endm 
#define SOME_ADDR 0x80000000
#define SOME_OFFSET 0x0068
    lwi r25,(SOME_ADDR+SOME_OFFSET) 

Using the gcc -E option reveals:

    lwi 25,(0x80000000 +0x0068) 

Hard coding the lwi statement as follows so that cpp does not 
touch it fixes the problem:

    lwi 25,(0x80000000+0x0068)

This occured with binutils 2.15 and 2.16.1
Comment 1 Nick Clifton 2005-07-19 12:30:12 UTC
Hi Earl,

  I would like to blame the C pre-processor here since it is inserting the
unrequested space into the output, but you could also argue that the assembler's
macro code ought to understand the use of parentheses to enclose an entire
expression.  (Using single or double quotes does not work because this prevents
the C pre-processor from performing its substitions).

  There is a workaround for the particular test case you supplied, by using the
:vararg qualifier to the last macro argument.  ie 

    .macro lwi reg,val:vararg

This should allow the macro to work.

I am also attaching a patch however which improves the macro handling code so
that it will accept expressions enclosed in parentheses as a single argument. 
Please could you try this out and let me know if it works for you.

Cheers
  Nick
Comment 2 Nick Clifton 2005-07-19 12:31:17 UTC
Created attachment 558 [details]
Support parenthesis enclosed macro arguments
Comment 3 Nick Clifton 2005-08-08 11:16:40 UTC
I have not heard back from Earl but I believe that the patch does the right
thing, so Iam going to check it in along with this ChangeLog entry:

Nick

gas/ChangeLog
2005-08-08  Nick Clifton  <nickc@redhat.com>

	PR 1070
	* macro.c (getstring): Treat round parentheses in the same way as
	angle brackets.
	(get_any_string): Likewise.

Comment 4 Nick Clifton 2005-08-09 15:45:48 UTC
The patch introduces a new failure in the i386 "32-bit SVME" tests because the
round parentheses that enclose a macro's argument are being stripped.
Comment 5 Nick Clifton 2005-08-09 15:46:36 UTC
Created attachment 586 [details]
preserve round parentheses

Do not strip round parentheses when parsing arguments to a macro
Comment 6 Nick Clifton 2005-08-09 15:47:09 UTC
Second patch applied to preserve the round parentheses.
Comment 7 Earl Olsen 2005-08-23 17:24:21 UTC
(In reply to comment #6)
> Second patch applied to preserve the round parentheses.
> 

Sorry for the delay, and sorry to report it did not fix things here.
I tried patch #1 and then patch #2 (on top of #1).
I got the same result.
I'm fairly certain I did the rebuild correctly.
Comment 8 Jan Beulich 2006-02-17 09:58:14 UTC
The two patches also break when using macro arguments like

	m (x)/(y)

because parsing stops after the closing parenthesis (another needed difference
in behavior from processing of angle brackets).

Further, the code is still unable to deal with things like

	m 1+(2 + 3)

Finally, even though I didn't experience problems with that, I would suspect
that providing standalone (or otherwise unmatched) parentheses as macro
arguments gets broken by this patch.
Comment 9 Alan Modra 2016-12-21 04:10:44 UTC
I doubt anyone cares enough to spend effort on fixing the issues raised in comment #8.  Re comment #7, Nick's patches did fix the original testcase.