← 返回命令列表

Linux command

llvm-mc 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Assemble to object file

llvm-mc -filetype=obj [input.s] -o [output.o]

Disassemble hex bytes

echo "0x90" | llvm-mc --disassemble -triple=x86_64

Assemble for a specific target triple

llvm-mc -triple=x86_64-linux-gnu [input.s]

Show instruction encoding

llvm-mc -show-encoding [input.s]

Assemble with Intel syntax

llvm-mc -x86-asm-syntax=intel [input.s]

Assemble for ARM target

llvm-mc -triple=aarch64-linux-gnu -filetype=obj [input.s] -o [output.o]

说明

llvm-mc is the LLVM machine code playground. It assembles assembly source into machine code and disassembles machine code bytes back into assembly for various target architectures. It is useful for testing assembly syntax, examining instruction encodings, verifying assembler behavior, and low-level debugging. Input for assembly mode is an assembly source file. Input for disassembly mode (--disassemble) is hex-encoded bytes, which can be piped from stdin. When no input file is given, stdin is read.

参数

-filetype=_type_
Output file type: asm (assembly listing, default), obj (object file), or null (no output).
-triple=_triple_
Target triple for assembly/disassembly (e.g., x86_64-linux-gnu, aarch64-linux-gnu).
--disassemble, -disassemble
Disassemble hex-encoded input bytes into assembly.
-show-encoding
Print instruction encoding as comments alongside assembly output.
-show-inst
Show internal LLVM instruction representation in output.
-o _file_
Output file name (default: stdout).
-x86-asm-syntax=_syntax_
Assembly syntax for x86: att (default) or intel.
-mcpu=_cpu_
Specify target CPU for instruction selection.
-mattr=_attributes_
Target-specific attributes (e.g., +sse4.2,+avx).
-output-asm-variant=_N_
Select assembly output variant (0 = AT&T, 1 = Intel for x86).
-g
Generate DWARF debug information in object output.

FAQ

What is the llvm-mc command used for?

llvm-mc is the LLVM machine code playground. It assembles assembly source into machine code and disassembles machine code bytes back into assembly for various target architectures. It is useful for testing assembly syntax, examining instruction encodings, verifying assembler behavior, and low-level debugging. Input for assembly mode is an assembly source file. Input for disassembly mode (--disassemble) is hex-encoded bytes, which can be piped from stdin. When no input file is given, stdin is read.

How do I run a basic llvm-mc example?

Run `llvm-mc -filetype=obj [input.s] -o [output.o]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -filetype=_type_ do in llvm-mc?

Output file type: asm (assembly listing, default), obj (object file), or null (no output).