LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 18918 - [RFE]: Missing altmacro support in integrated assembler
Summary: [RFE]: Missing altmacro support in integrated assembler
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: MC (show other bugs)
Version: trunk
Hardware: PC Linux
: P enhancement
Assignee: Saleem Abdulrasool
URL:
Keywords:
Depends on: 9248
Blocks: 4068 21420 21691 24345 33405
  Show dependency tree
 
Reported: 2014-02-20 20:45 PST by Edward O'Callaghan
Modified: 2017-09-09 15:29 PDT (History)
16 users (show)

See Also:
Fixed By Commit(s):


Attachments
Test case. (179 bytes, text/x-asm)
2014-02-20 20:50 PST, Edward O'Callaghan
Details
Extended Test Case (389 bytes, text/x-asm)
2014-02-20 21:07 PST, Edward O'Callaghan
Details
Work in Progress Patch (4.39 KB, patch)
2014-02-21 02:45 PST, Edward O'Callaghan
Details
.altmacro wip (53.25 KB, patch)
2014-03-05 20:50 PST, Saleem Abdulrasool
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Edward O'Callaghan 2014-02-20 20:45:01 PST
Hi,

While compiling coreboot, AMD's AGESA vendor assembler code blows up with the following macro expansion:

src/vendorcode/amd/agesa/f14/gcccar.inc:38:1: error: unknown directive
.altmacro
^
<instantiation>:4:5: error: invalid instruction mnemonic 'local'
LOCAL SetupStack
~~~~^~~~~~~~~~~~~~~~
./src/cpu/amd/agesa/cache_as_ram.inc:67:3: note: while in macro instantiation
AMD_ENABLE_STACK
^
<instantiation>:5:5: error: invalid instruction mnemonic 'local'
LOCAL Real16bMode
~~~~^~~~~~~~~~~~~~~~~

This apears to be due to missing Altmacro support in LLVM's Assembler,
cite: https://sourceware.org/binutils/docs/as/Altmacro.html

Cheers,
Edward O'Callaghan.
Comment 1 Edward O'Callaghan 2014-02-20 20:50:50 PST
Created attachment 12093 [details]
Test case.

$ cat pr18918.asm | llvm-mc
	.text
<stdin>:1:1: error: unknown directive
.altmacro   /* enable alternative macro mode */
^
Comment 2 Edward O'Callaghan 2014-02-20 21:07:19 PST
Created attachment 12094 [details]
Extended Test Case

$ as -o pr18918_extended.o pr18918_extended.asm
$ nm -n pr18918_extended.o
0000000000000000 r bar1
0000000000000004 r bar9
0000000000000008 r foobar7
000000000000000c r foobar5
0000000000000010 r foobar3

In this test case we efine two macros, mksym and __mksym. Here mksym is a wrapper around __mksym. mksym evaluates the expression in it’s second argument number by not referencing it via \number but %number instead. So __mksym gets called with the computed value given for it’s possible complex argument number. Within __mksym the label gets created by just putting the two arguments \name and \number together. The preceding \() before the : is just needed to terminate the token \number.
Comment 3 Edward O'Callaghan 2014-02-21 02:45:00 PST
Created attachment 12097 [details]
Work in Progress Patch

Work needed to implement correct logic. When %number is seen the token '%' should indicate the evalutation of the passed expression into a constant. If noaltmacro is on then a warning should be issued when such a token is seen informing that "perhaps altmacro should be enabled".
Comment 4 Edward O'Callaghan 2014-02-28 10:53:04 PST
Documentation derived from the GAS documentation:

7.4 .altmacro

Enable alternate macro mode, enabling:

LOCAL name [ , … ]
One additional directive, LOCAL, is available. It is used to generate a string replacement for each of the name arguments, and replace any instances of name in each macro expansion. The replacement string is unique in the assembly, and different for each separate macro expansion. LOCAL allows you to write macros that define symbols, without fear of conflict between separate macro expansions.
String delimiters
You can write strings delimited in these other ways besides “string”:

’string’
You can delimit strings with single-quote characters.

You can delimit strings with matching angle brackets.

single-character string escape
To include any single character literally in a string (even if the character would otherwise have some special meaning), you can prefix the character with `!’ (an exclamation mark). For example, you can write `<4.3 !> 5.4!!>’ to get the literal text `4.3 > 5.4!’.
Expression results as strings
You can write `%expr’ to evaluate the expression expr and use the result as a string.
Comment 5 Saleem Abdulrasool 2014-03-02 14:46:26 PST
I was able to hack something together which is able to properly process the "extended test case".  However, that is more to figure out how to implement it.  It seems that the problem with formalising the support requires splitting out the expression parser.  We need to be able to switch the token stream from the lexer to a pre-tokenised stream.
Comment 6 Saleem Abdulrasool 2014-03-05 20:50:05 PST
Created attachment 12197 [details]
.altmacro wip

This is a WIP patch that I wrote while trying to see if I could formalise the change.  It really is two changes squashed into one: the first being the separation of the expression parser to support an alternate input token stream, which still has some issues that I need to work out.

The second is the actual beginnings of an altmacro parser support which is sufficient to get the basic test shown here to pass.

Im posting this here at the request of functorfun over IRC.
Comment 7 Edward O'Callaghan 2014-11-29 08:48:57 PST
Status on this?
Comment 8 Egor Kochetov 2015-08-05 07:22:23 PDT
There is a new patch currently on review which is designed to fix this issue.
http://reviews.llvm.org/D11215
Comment 9 İsmail Dönmez 2016-03-11 04:04:58 PST
(In reply to comment #8)
> There is a new patch currently on review which is designed to fix this issue.
> http://reviews.llvm.org/D11215

Any chance of reviving the patch?
Comment 10 Renato Golin 2016-03-15 05:31:24 PDT
Hi Ismail,

Have you seen Jim's comment that the docs are vague? I honestly don't understand myself what altmacro does, and that snippet helps nothing.

His suggestion was to start a thread in the mailing list, trying to gather as much information as possible (examples, other docs, threads) that will support the case for implementing the feature in the exact way it's being proposed.

Not that it's wrong, I have no way of asserting that, but we just need to know what exactly it is before reviewing code.

cheers,
--renato
Comment 11 emaste 2017-06-11 05:41:43 PDT
One FreeBSD source file (skein implementation) cannot be assembled with the integrated assembler, due to the lack of .altmacro (and some other issues).

Source is here: https://svnweb.freebsd.org/base/head/sys/crypto/skein/amd64/skein_block_asm.s?view=markup
Comment 12 Coby Tayree 2017-09-09 11:58:21 PDT
support for all alternate macro mode ('.altmacro') documented features but 'LOCAL' was recently introduced to llvm by Michael Zuckerman (this one introduces the ability to evaluate compound absolute expressions: https://reviews.llvm.org/rL301797, for example).
'LOCAL' is expected to be done in the nearest future.
please re-assess the relevance of this ticket.
Comment 13 Renato Golin 2017-09-09 15:29:42 PDT
This was created for a bug that has been fixed, but the description is too broad.

I'm closing it, and if someone needs something else to do with macros, they should create a new, specific bug.