An updated reference for the Dlang DMD name mangling ABI.

* At least up to 2026-06-13

Grammar Notation#

This specification uses standard EBNF. Terminal characters are literal characters in the mangled string.

1. The Root Symbol#

MangledName:
    _D QualifiedName [ M ] [ Type ] [ Z ]

Note: M denotes a member function.

2. Names and Symbols#

QualifiedName:
    SymbolFunctionName { SymbolFunctionName }

SymbolFunctionName:
    SymbolName [ M TypeModifier ] [ CallingConvention FuncAttrs (Parameters) ParamClose ]

SymbolName:
    0
    LName
    BackRefSymbol
    TemplateInstanceName

LName:
    Number Name
    0                    // __anonymous
    ___S Number          // Special anonymous symbol

Number:
    Digit { Digit }

BackRefSymbol:
    Q Base26Pos

Base26Pos:
    { UpperCaseAlpha } LowerCaseAlpha  // Upper = A-Z (0-25), Lower = a-z (0-25, terminates)

3. Types and Modifiers#

Type:
    TypeModifiers Type
    BasicType
    DerivedType
    FunctionType
    DelegateType
    VectorType
    BackRefType

BasicType:
    v | g | h | s | t | i | k | l | m | f | d | e | o | p | j | q | r | c | b | a | u | w | n | z i | z k

DerivedType:
    A Type                 // Dynamic Array: Type[]
    P Type                 // Pointer: Type*
    G Number Type          // Static Array: Type[Number]
    H Type Type            // Associative Array: Type[Type]
    I QualifiedName        // Identifier
    C QualifiedName        // Class
    S QualifiedName        // Struct
    E QualifiedName        // Enum
    T QualifiedName        // Typedef
    B (Parameters) Z       // Tuple

VectorType:
    N h Type               // __vector(Type)

BackRefType:
    Q Base26Pos

TypeModifiers:
    x                   // const
    y                   // immutable
    O                   // shared
    O x                 // shared const
    O N g               // shared inout
    O N g x             // shared inout const
    N g                 // inout
    N g x               // inout const

4. Functions and Delegates#

CallingConvention:
    F                   // D
    U                   // C
    W                   // Windows
    R                   // C++
    Y                   // Objective-C

FunctionType:
    CallingConvention FuncAttrs (Parameters) ParamClose Type  // (args) return_type

DelegateType:
    D [ TypeModifiers ] [ CallingConvention ] FuncAttrs (Parameters) ParamClose Type

5. Function Attributes#

FuncAttrs:
    { FuncAttr }

FuncAttr:
    N a                 // pure
    N b                 // nothrow
    N c                 // ref
    N d                 // @property
    N e                 // @trusted
    N f                 // @safe
    N i                 // @nogc
    N j                 // return
    N j N l             // return scope
    N l                 // scope
    N l N j             // scope return
    N m                 // @live

6. Parameters#

Parameters:
    { Parameter }

Parameter:
    [ ParamStorageClass ] Type

ParamStorageClass:
    M N k J             // scope return out
    M N k K             // scope return ref
    N k J               // return out
    N k K               // return ref
    N k M J             // return scope out
    N k M K             // return scope ref
    N k M               // return scope
    M                   // scope
    N k                 // return
    I                   // in
    I K                 // in ref
    J                   // out
    K                   // ref
    L                   // lazy

ParamClose:
    X                   // ...)     (variadic)
    Y                   // , ...)   (C-style variadic)
    Z                   // )        (standard)

7. Templates#

TemplateInstanceName:
    TemplateID SymbolName TemplateArgs [ Z ]

TemplateID:
    __T | __U | T | U

TemplateArgs:
    { [ H ] TemplateArg }

TemplateArg:
    T Type                  // Type argument
    V TypeChar Type Value   // Value argument
    S QualifiedName         // Symbol argument
    S _ D QualifiedName [Z] // Fully qualified symbol
    X Number Name           // Externally linked LName

8. Values and Literals#

Value:
    n                       // null
    i Number                // positive integer
    N Number                // negative integer
    Number                  // positive integer (shorthand)
    b Number                // boolean (0/1)
    e HexFloat              // real
    c HexFloat c HexFloat   // complex real
    a Number _ HexString    // char string
    w Number _ HexString    // wchar string
    d Number _ HexString    // dchar string
    A Number { Value }      // Array
    H Number { Value : Value } // Associative Array
    S Number { Value }      // Struct

HexFloat:
    N A N                   // real.nan
    I N F                   // real.infinity
    N I N F                 // -real.infinity
    [ N ] HexDigits P [ N ] Number // Hexadecimal float (e.g., 0x...p+/-...)

Deviations & Additions from the Official Spec#

  • Parameter Storage Classes: Added complex, undocumented combinations (e.g., M N k J for scope return out, I K for in ref).
  • Type Back References: Specified that Q compresses types (BackRefType), not just symbols.
  • New Attributes: Added @live (N m), return scope (N j N l), and scope return (N l N j).
  • Template Values (V): Added detailed grammar for arrays (A), associative arrays (H), structs (S), and exact hex float configurations (base-16 exponents, N A N, I N F).
  • Vectors & 128-bit Ints: Added __vector(Type) (N h), cent (z i), and ucent (z k).
  • Anonymous Symbols: Included ___S Number for special anonymous scopes.

Implementation#

My C implementation of a demangler based on this DMD specification can be found here: rz-libdemangle.

This parser was developed as part of my GSoC'26 project for the Rizin reverse engineering framework.