xref: /llvm-project/llvm/docs/CommandGuide/llvm-mc.rst (revision c6ff809ae9acbc90455dc8b58b2dae84a13366cf)
15686364dSaabhinavgllvm-mc - LLVM Machine Code Playground
25686364dSaabhinavg======================================
35686364dSaabhinavg
45686364dSaabhinavg.. program:: llvm-mc
55686364dSaabhinavg
65686364dSaabhinavgSYNOPSIS
75686364dSaabhinavg--------
85686364dSaabhinavg
95686364dSaabhinavg:program:`llvm-mc` [*options*] [*filename*]
105686364dSaabhinavg
115686364dSaabhinavgDESCRIPTION
125686364dSaabhinavg-----------
135686364dSaabhinavg
14f802fed2SJacob LambertThe :program:`llvm-mc` command takes assembly code for a specified architecture
15f802fed2SJacob Lambertas input and generates an object file or executable.
165686364dSaabhinavg
17f802fed2SJacob Lambert:program:`llvm-mc` provides a set of tools for working with machine code,
18f802fed2SJacob Lambertsuch as encoding instructions and displaying internal representations,
19f802fed2SJacob Lambertdisassembling strings to bytes, etc.
205686364dSaabhinavg
215686364dSaabhinavgThe choice of architecture for the output assembly code is automatically
225686364dSaabhinavgdetermined from the input file, unless the :option:`--arch` option is used to
235686364dSaabhinavgoverride the default.
245686364dSaabhinavg
255686364dSaabhinavgOPTIONS
265686364dSaabhinavg-------
275686364dSaabhinavg
28932a6187SJonas DevlieghereIf the :option:`-o` option is omitted, then :program:`llvm-mc` will send its
29932a6187SJonas Devlieghereoutput to standard output if the input is from standard input.  If the
30932a6187SJonas Devlieghere:option:`-o` option specifies "``-``", then the output will also be sent to
31932a6187SJonas Devliegherestandard output.
325686364dSaabhinavg
335686364dSaabhinavgIf no :option:`-o` option is specified and an input file other than "``-``" is
34932a6187SJonas Devliegherespecified, then :program:`llvm-mc` creates the output filename by taking the
35932a6187SJonas Devlieghereinput filename, removing any existing ``.s`` extension, and adding a ``.o``
36932a6187SJonas Devliegheresuffix.
375686364dSaabhinavg
385686364dSaabhinavgOther :program:`llvm-mc` options are described below.
395686364dSaabhinavg
405686364dSaabhinavgEnd-user Options
415686364dSaabhinavg~~~~~~~~~~~~~~~~
425686364dSaabhinavg
435686364dSaabhinavg.. option:: --help
445686364dSaabhinavg
455686364dSaabhinavg Display available options (--help-hidden for more).
465686364dSaabhinavg
475686364dSaabhinavg.. option:: -o <filename>
485686364dSaabhinavg
495686364dSaabhinavg Use ``<filename>`` as the output filename. See the summary above for more
505686364dSaabhinavg details.
515686364dSaabhinavg
525686364dSaabhinavg.. option:: --arch=<string>
535686364dSaabhinavg
545686364dSaabhinavg Target arch to assemble for, see -version for available targets.
555686364dSaabhinavg
565686364dSaabhinavg.. option:: --as-lex
575686364dSaabhinavg
58932a6187SJonas Devlieghere Apply the assemblers "lexer" to break the input into tokens and print each of
59932a6187SJonas Devlieghere them out. This is intended to help develop and test an assembler
60932a6187SJonas Devlieghere implementation.
615686364dSaabhinavg
625686364dSaabhinavg.. option:: --assemble
635686364dSaabhinavg
64932a6187SJonas Devlieghere Assemble assembly file (default), and print the result to assembly. This is
65932a6187SJonas Devlieghere useful to design and test instruction parsers, and can be a useful tool when
66932a6187SJonas Devlieghere combined with other llvm-mc flags. For example, this option may be useful to
67932a6187SJonas Devlieghere transcode assembly from different dialects, e.g. on Intel where you can use
68932a6187SJonas Devlieghere -output-asm-variant=1 to translate from AT&T to Intel assembly syntax. It can
69932a6187SJonas Devlieghere also be combined with --show-encoding to understand how instructions are
70932a6187SJonas Devlieghere encoded.
715686364dSaabhinavg
725686364dSaabhinavg.. option:: --disassemble
735686364dSaabhinavg
745686364dSaabhinavg Parse a series of hex bytes, and print the result out as assembly syntax.
755686364dSaabhinavg
765686364dSaabhinavg.. option:: --mdis
775686364dSaabhinavg
785686364dSaabhinavg Marked up disassembly of string of hex bytes.
795686364dSaabhinavg
8077d10325SJonas Devlieghere.. option:: --cdis
8177d10325SJonas Devlieghere
8277d10325SJonas Devlieghere Colored disassembly of string of hex bytes.
8377d10325SJonas Devlieghere
847bda9ffbSAiden Grossman.. option:: --filetype=[asm,null,obj]
857bda9ffbSAiden Grossman
86932a6187SJonas Devlieghere Sets the output filetype. Setting this flag to `asm` will make the tool output
87932a6187SJonas Devlieghere text assembly. Setting this flag to `obj` will make the tool output an object
88932a6187SJonas Devlieghere file. Setting it to `null` causes no output to be created and can be used for
89932a6187SJonas Devlieghere timing purposes. The default value is `asm`.
907bda9ffbSAiden Grossman
915686364dSaabhinavg.. option:: -g
925686364dSaabhinavg
935686364dSaabhinavg Generate DWARF debugging info for assembly source files.
945686364dSaabhinavg
95*c6ff809aSFangrui Song.. option:: --hex
96*c6ff809aSFangrui Song
97*c6ff809aSFangrui Song Take raw hexadecimal bytes as input for disassembly. Whitespace is ignored.
98*c6ff809aSFangrui Song
995686364dSaabhinavg.. option:: --large-code-model
1005686364dSaabhinavg
1015686364dSaabhinavg Create CFI directives that assume the code might be more than 2 GB.
1025686364dSaabhinavg
1035686364dSaabhinavg.. option:: --main-file-name=<string>
1045686364dSaabhinavg
1055686364dSaabhinavg Specify the name we should consider the input file.
1065686364dSaabhinavg
1075686364dSaabhinavg
1085686364dSaabhinavg.. option:: --masm-hexfloats
1095686364dSaabhinavg
1105686364dSaabhinavg Enable MASM-style hex float initializers (3F800000r).
1115686364dSaabhinavg
1125686364dSaabhinavg
1135686364dSaabhinavg.. option:: -mattr=a1,+a2,-a3,...
1145686364dSaabhinavg Target specific attributes (-mattr=help for details).
1155686364dSaabhinavg
1165686364dSaabhinavg.. option:: --mcpu=<cpu-name>
1175686364dSaabhinavg
1185686364dSaabhinavg Target a specific cpu type (-mcpu=help for details).
1195686364dSaabhinavg
1205686364dSaabhinavg.. option::   --triple=<string>
1215686364dSaabhinavg
1225686364dSaabhinavg Target triple to assemble for, see -version for available targets.
1235686364dSaabhinavg
1245686364dSaabhinavg.. option::  --split-dwarf-file=<filename>
1255686364dSaabhinavg
1265686364dSaabhinavg DWO output filename.
1275686364dSaabhinavg
1285686364dSaabhinavg.. option:: --show-inst-operands
1295686364dSaabhinavg
1305686364dSaabhinavg Show instructions operands as parsed.
1315686364dSaabhinavg
1325686364dSaabhinavg.. option:: --show-inst
1335686364dSaabhinavg
1345686364dSaabhinavg Show internal instruction representation.
1355686364dSaabhinavg
1365686364dSaabhinavg.. option::  --show-encoding
1375686364dSaabhinavg
1385686364dSaabhinavg Show instruction encodings.
1395686364dSaabhinavg
1405686364dSaabhinavg.. option:: --save-temp-labels
1415686364dSaabhinavg
1425686364dSaabhinavg Don't discard temporary labels.
1435686364dSaabhinavg
1445686364dSaabhinavg.. option::   --relax-relocations
1455686364dSaabhinavg
1465686364dSaabhinavg Emit R_X86_64_GOTPCRELX instead of R_X86_64_GOTPCREL.
1475686364dSaabhinavg
1485686364dSaabhinavg.. option:: --print-imm-hex
1495686364dSaabhinavg
1505686364dSaabhinavg Prefer hex format for immediate values.
1515686364dSaabhinavg
1525686364dSaabhinavg.. option::  --preserve-comments
1535686364dSaabhinavg
1545686364dSaabhinavg Preserve Comments in outputted assembly.
1555686364dSaabhinavg
1565686364dSaabhinavg.. option:: --output-asm-variant=<uint>
1575686364dSaabhinavg
1588f7496b0SAiden Grossman Syntax variant to use for output printing. For example, on x86 targets
159932a6187SJonas Devlieghere --output-asm-variant=0 prints in AT&T syntax, and --output-asm-variant=1
160932a6187SJonas Devlieghere prints in Intel/MASM syntax.
1615686364dSaabhinavg
1625686364dSaabhinavg.. option:: --compress-debug-sections=[none|zlib|zstd]
1635686364dSaabhinavg
1645686364dSaabhinavg Choose DWARF debug sections compression.
1655686364dSaabhinavg
1665686364dSaabhinavg
1675686364dSaabhinavgEXIT STATUS
1685686364dSaabhinavg-----------
1695686364dSaabhinavg
1705686364dSaabhinavgIf :program:`llvm-mc` succeeds, it will exit with 0.  Otherwise, if an error
1715686364dSaabhinavgoccurs, it will exit with a non-zero value.
1725686364dSaabhinavg
173