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.
Created attachment 12093 [details] Test case. $ cat pr18918.asm | llvm-mc .text <stdin>:1:1: error: unknown directive .altmacro /* enable alternative macro mode */ ^
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.
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".
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.
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.
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.
Status on this?
There is a new patch currently on review which is designed to fix this issue. http://reviews.llvm.org/D11215
(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?
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
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
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.
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.