- General Assembly Syntax
- Machine-specific Assembly Syntax
- Target Specific Behaviour
This document describes extensions to tools and formats LLVM seeks compatibility with.
The following additional relocation types are supported:
@IMGREL (AT&T syntax only) generates an image-relative relocation that
corresponds to the COFF relocation types
IMAGE_REL_I386_DIR32NB (32-bit) or
.text fun: mov foo@IMGREL(%ebx, %ecx, 4), %eax .section .pdata .long fun@IMGREL .long (fun@imgrel + 0x3F) .long $unwind$fun@imgrel
.secrel32 generates a relocation that corresponds to the COFF relocation
IMAGE_REL_I386_SECREL (32-bit) or
.secidx relocation generates an index of the section that contains
the target. It corresponds to the COFF relocation types
IMAGE_REL_I386_SECTION (32-bit) or
.section .debug$S,"rn" .long 4 .long 242 .long 40 .secrel32 _function_name + 0 .secidx _function_name ...
MC supports passing the information in
.linkonce at the end of
.section. For example, these two codes are equivalent
.section secName, "dr", discard, "Symbol1" .globl Symbol1 Symbol1: .long 1
.section secName, "dr" .linkonce discard .globl Symbol1 Symbol1: .long 1
Note that in the combined form the COMDAT symbol is explicit. This extension exists to support multiple sections with the same name in different COMDATs:
.section secName, "dr", discard, "Symbol1" .globl Symbol1 Symbol1: .long 1 .section secName, "dr", discard, "Symbol2" .globl Symbol2 Symbol2: .long 1
In addition to the types allowed with
.section also accepts
associative. The meaning is that the section is linked if a certain other
COMDAT section is linked. This other section is indicated by the comdat symbol
in this directive. It can be any symbol defined in the associated section, but
is usually the associated section’s comdat.
The following restrictions apply to the associated section:
- It must be a COMDAT section.
- It cannot be another associative COMDAT section.
In the following example the symobl
sym is the comdat symbol of
.bar is associated to
.section .foo,"bw",discard, "sym" .section .bar,"rd",associative, "sym"
MC supports these flags in the COFF
b: BSS section (
d: Data section (
n: Section is not loaded (
s: Shared section
x: Executable section
y: Not readable
D: Discardable (
These flags are all compatible with gas, with the exception of the
which gnu as does not support. For gas compatibility, sections with a name
starting with ”.debug” are implicitly discardable.
In order to support creating multiple sections with the same name and comdat,
it is possible to add an unique number at the end of the
For example, the following code creates two sections named
.section .text,"ax",@progbits,unique,1 nop .section .text,"ax",@progbits,unique,2 nop
The unique number is not present in the resulting object at all. It is just used in the assembler to differentiate the sections.
The ‘m’ flag is mapped to SHF_LINK_ORDER. If it is present, a symbol must be given that identifies the section to be placed is the .sh_link.
.section .foo,"a",@progbits .Ltmp: .section .bar,"am",@progbits,.Ltmp
which is equivalent to just
.section .foo,"a",@progbits .section .bar,"am",@progbits,.foo
@ABS8 can be applied to symbols which appear as immediate operands to
instructions that have an 8-bit immediate form for that operand. It causes
the assembler to use the 8-bit form and an 8-bit relocation (e.g.
R_X86_64_8) for the symbol.
cmpq $foo@ABS8, %rdi
This causes the assembler to select the form of the 64-bit
that takes an 8-bit immediate operand that is sign extended to 64 bits, as
cmpq $foo, %rdi which takes a 32-bit immediate operand. This
is also not the same as
cmpb $foo, %dil, which is an 8-bit comparison.
The reference implementation (Microsoft Visual Studio 2012) emits stack probes in the following fashion:
movw r4, #constant bl __chkstk sub.w sp, sp, r4
However, this has the limitation of 32 MiB (±16MiB). In order to accommodate
larger binaries, LLVM supports the use of
-mcode-model=large to allow a 4GiB
range via a slight deviation. It will generate an indirect jump as follows:
movw r4, #constant movw r12, :lower16:__chkstk movt r12, :upper16:__chkstk blx r12 sub.w sp, sp, r4
The reference implementation (Microsoft Visual Studio 2012) does not permit the emission of Variable Length Arrays (VLAs).
The Windows ARM Itanium ABI extends the base ABI by adding support for emitting
a dynamic stack allocation. When emitting a variable stack allocation, a call
__chkstk is emitted unconditionally to ensure that guard pages are setup
properly. The emission of this stack probe emission is handled similar to the
standard stack probe emission.
The MSVC environment does not emit code for VLAs currently.