Chapter 3. Assembler Command-Line Options

If you are invoking the assembler via the compiler, you can use the -Wa option to pass arguments through to the assembler. The assembler arguments must be separated from each other (and the -Wa) by commas. For example:

$ prefix-gcc -c -g -O -Wa,-alhd,-L file.c

emits a listing to standard output with high-level and assembly source.

Usually you do not need to use this -Wa mechanism, since many compiler command-line options are automatically passed to the assembler by the compiler. (You can call the GNU compiler driver with the -v option to see precisely what options it passes to each compilation pass, including the assembler.)

Enable Listings: -a[cdhlns]

These options enable listing output from the assembler. By itself, -a requests high-level, assembly, and symbols listing. You can use other letters to select specific options for the list: -ah requests a high-level language listing, -al requests an output-program assembly listing, and -as requests a symbol table listing. High-level listings require that a compiler debugging option like -g be used, and that assembly listings (-al) be requested also.

Use the -ac option to omit false conditionals from a listing. Any lines that are not assembled because of a false .if (or .ifdef, or any other conditional), or a true .if followed by an .else, will be omitted from the listing.

Use the -ad option to omit debugging directives from the listing.

Once you have specified one of these options, you can further control listing output and its appearance using the directives .list, .nolist, .psize, .eject, .term, and .sbttl. The -an option turns off all forms processing. If you do not request listing output with one of the -a options, the listing-control directives have no effect.

The letters after -a may be combined into one option, e.g., -aln.

-D

This option has no effect whatsoever, but it is accepted to make it more likely that scripts written for other assemblers also work with the assembler.

Work Faster: -f

-f should only be used when assembling programs written by a (trusted) compiler. -f stops the assembler from doing white-space and comment preprocessing on the input file(s) before assembling them. See Section 4.1.

Warning. If you use -f when the files actually need to be pre-processed (if they contain comments, for example), the assembler does not work correctly.

.include search path: -I path

Use this option to add a path to the list of directories the assembler searches for files specified in .include directives (see .include). You may use -I as many times as necessary to include a variety of paths. The current working directory is always searched first; after that, the assembler searches any -I directories in the same order as they were specified (left to right) on the command line.

Difference Tables: -K

The assembler sometimes alters the code emitted for directives of the form ".word sym1-sym2"; see .word. You can use the -K option if you want a warning issued when this is done.

Include Local Labels: -L

Labels beginning with "L" (upper case only) are called local labels. See Section 6.3. Normally you do not see such labels when debugging, because they are intended for the use of programs (like compilers) that compose assembler programs, not for your notice. Normally both the assembler and the linker discard such labels, so you do not normally debug with them.

This option tells the assembler to retain those "L..." symbols in the object file. Usually if you do this you also tell the linker to preserve symbols whose names begin with "L".

By default, a local label is any label beginning with "L", but each target is allowed to redefine the local label prefix.

Name the Object File: -o

There is always one object file output when you run the assembler. By default it has the name a.out. You use this option (which takes exactly one filename) to give the object file a different name.

Whatever the object file is called, the assembler overwrites any existing file of the same name.

Join Data and Text Sections: -R

-R tells the assembler to write the object file as if all data-section data lives in the text section. This is only done at the very last moment: your binary data are the same, but data section parts are relocated differently. The data section part of your object file is zero bytes long because all its bytes are appended to the text section. (See Chapter 5.)

When you specify -R it would be possible to generate shorter address displacements (because we do not have to cross between text and data section). We refrain from doing this simply for compatibility with older versions of the assembler. In future, -R may work this way.

When the assembler is configured for COFF output, this option is only useful if you use sections named ".text" and ".data".

Display Assembly Statistics: --statistics

Use --statistics to display two statistics about the resources used by the assembler: the maximum amount of space allocated during the assembly (in bytes), and the total execution time taken for the assembly (in cpu seconds).

Announce Version: -v

You can find out what version of the assembler is running by including the option -v (which you can also spell as --version) on the command line.

Suppress Warnings: -W

The assembler should never give a warning or error message when assembling compiler output. But programs written by people often cause the assembler to give a warning that a particular assumption was made. All such warnings are directed to the standard error file. If you use this option, no warnings are issued. This option only affects the warning messages: it does not change any particular of how the assembler assembles your file. Errors, which stop the assembly, are still reported.

Generate Object File in Spite of Errors: -Z

After an error message, the assembler normally produces no output. If for some reason you are interested in object file output even after the assembler gives an error message on your program, use the -Z option. If there are any errors, the assembler continues anyway, and writes an object file after a final warning message of the form:

n errors, m warnings, generating bad object file.