Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Show macro expansions in GNU Assembler – AS – listing. Preprocess only?

I can’t seem to find any command switch to show me the expansions of my macro definitions.

Is there a way to do this with the GNU Assembler?

For example, if I have a macro like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.macro MACROA a
    mov \a,%rax
.endm

MACROA $10

I’d like to see the expansions of this like so:

; MACROA 10
mov $10, %rax

I vaguely remember seeing this but don’t know where anymore.

I tried the -a switch but it doesn’t generate expansions, only opcodes are printed next to the macro

> as x.s -a
GAS LISTING x.s             page 1


   1                
   2                
   3                .text
   4                
   5                .macro MACROA a
   6                    mov \a, %rax
   7                .endm
   8                
   9                _start:
  10 0000 48C7C00A      MACROA $10
  10      000000

GAS LISTING x.s             page 2


DEFINED SYMBOLS
                 x.s:9      .text:0000000000000000 _start

NO UNDEFINED SYMBOLS

>Solution :

as -a -am enables listings with macro expansion.

...
   5                    MACROA 10
   5 0000 488B0425      >  mov 10,%rax
   5      0A000000 
       # load from absolute address 10, not mov $10, %rax.
       # That's why as -Os doesn't optimize it to a 5-byte mov to eax
...

The man page implies that -am alone would turn on listings, as well as set the listing style to include macro expansion. But in current versions of GAS (e.g. Binutils 2.36.1 on my system), that is not the case. A separate listing option like bare -a is necessary to actually turn on listings.

This is a bug in GAS’s option parsing; feel free to report it. I think they use https://sourceware.org/bugzilla/

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading