xref: /llvm-project/llvm/docs/CommandGuide/llvm-mc.rst (revision c6ff809ae9acbc90455dc8b58b2dae84a13366cf)
1llvm-mc - LLVM Machine Code Playground
2======================================
3
4.. program:: llvm-mc
5
6SYNOPSIS
7--------
8
9:program:`llvm-mc` [*options*] [*filename*]
10
11DESCRIPTION
12-----------
13
14The :program:`llvm-mc` command takes assembly code for a specified architecture
15as input and generates an object file or executable.
16
17:program:`llvm-mc` provides a set of tools for working with machine code,
18such as encoding instructions and displaying internal representations,
19disassembling strings to bytes, etc.
20
21The choice of architecture for the output assembly code is automatically
22determined from the input file, unless the :option:`--arch` option is used to
23override the default.
24
25OPTIONS
26-------
27
28If the :option:`-o` option is omitted, then :program:`llvm-mc` will send its
29output to standard output if the input is from standard input.  If the
30:option:`-o` option specifies "``-``", then the output will also be sent to
31standard output.
32
33If no :option:`-o` option is specified and an input file other than "``-``" is
34specified, then :program:`llvm-mc` creates the output filename by taking the
35input filename, removing any existing ``.s`` extension, and adding a ``.o``
36suffix.
37
38Other :program:`llvm-mc` options are described below.
39
40End-user Options
41~~~~~~~~~~~~~~~~
42
43.. option:: --help
44
45 Display available options (--help-hidden for more).
46
47.. option:: -o <filename>
48
49 Use ``<filename>`` as the output filename. See the summary above for more
50 details.
51
52.. option:: --arch=<string>
53
54 Target arch to assemble for, see -version for available targets.
55
56.. option:: --as-lex
57
58 Apply the assemblers "lexer" to break the input into tokens and print each of
59 them out. This is intended to help develop and test an assembler
60 implementation.
61
62.. option:: --assemble
63
64 Assemble assembly file (default), and print the result to assembly. This is
65 useful to design and test instruction parsers, and can be a useful tool when
66 combined with other llvm-mc flags. For example, this option may be useful to
67 transcode assembly from different dialects, e.g. on Intel where you can use
68 -output-asm-variant=1 to translate from AT&T to Intel assembly syntax. It can
69 also be combined with --show-encoding to understand how instructions are
70 encoded.
71
72.. option:: --disassemble
73
74 Parse a series of hex bytes, and print the result out as assembly syntax.
75
76.. option:: --mdis
77
78 Marked up disassembly of string of hex bytes.
79
80.. option:: --cdis
81
82 Colored disassembly of string of hex bytes.
83
84.. option:: --filetype=[asm,null,obj]
85
86 Sets the output filetype. Setting this flag to `asm` will make the tool output
87 text assembly. Setting this flag to `obj` will make the tool output an object
88 file. Setting it to `null` causes no output to be created and can be used for
89 timing purposes. The default value is `asm`.
90
91.. option:: -g
92
93 Generate DWARF debugging info for assembly source files.
94
95.. option:: --hex
96
97 Take raw hexadecimal bytes as input for disassembly. Whitespace is ignored.
98
99.. option:: --large-code-model
100
101 Create CFI directives that assume the code might be more than 2 GB.
102
103.. option:: --main-file-name=<string>
104
105 Specify the name we should consider the input file.
106
107
108.. option:: --masm-hexfloats
109
110 Enable MASM-style hex float initializers (3F800000r).
111
112
113.. option:: -mattr=a1,+a2,-a3,...
114 Target specific attributes (-mattr=help for details).
115
116.. option:: --mcpu=<cpu-name>
117
118 Target a specific cpu type (-mcpu=help for details).
119
120.. option::   --triple=<string>
121
122 Target triple to assemble for, see -version for available targets.
123
124.. option::  --split-dwarf-file=<filename>
125
126 DWO output filename.
127
128.. option:: --show-inst-operands
129
130 Show instructions operands as parsed.
131
132.. option:: --show-inst
133
134 Show internal instruction representation.
135
136.. option::  --show-encoding
137
138 Show instruction encodings.
139
140.. option:: --save-temp-labels
141
142 Don't discard temporary labels.
143
144.. option::   --relax-relocations
145
146 Emit R_X86_64_GOTPCRELX instead of R_X86_64_GOTPCREL.
147
148.. option:: --print-imm-hex
149
150 Prefer hex format for immediate values.
151
152.. option::  --preserve-comments
153
154 Preserve Comments in outputted assembly.
155
156.. option:: --output-asm-variant=<uint>
157
158 Syntax variant to use for output printing. For example, on x86 targets
159 --output-asm-variant=0 prints in AT&T syntax, and --output-asm-variant=1
160 prints in Intel/MASM syntax.
161
162.. option:: --compress-debug-sections=[none|zlib|zstd]
163
164 Choose DWARF debug sections compression.
165
166
167EXIT STATUS
168-----------
169
170If :program:`llvm-mc` succeeds, it will exit with 0.  Otherwise, if an error
171occurs, it will exit with a non-zero value.
172
173