summaryrefslogtreecommitdiffstats
path: root/Tools/jit/_schema.py
blob: 045fd502a03c12b0bcb76e92b6ee4b97a5b38257 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""Schema for the JSON produced by llvm-readobj --elf-output-style=JSON."""
import typing

HoleKind: typing.TypeAlias = typing.Literal[
    "ARM64_RELOC_GOT_LOAD_PAGE21",
    "ARM64_RELOC_GOT_LOAD_PAGEOFF12",
    "ARM64_RELOC_PAGE21",
    "ARM64_RELOC_PAGEOFF12",
    "ARM64_RELOC_UNSIGNED",
    "IMAGE_REL_AMD64_REL32",
    "IMAGE_REL_ARM64_BRANCH26",
    "IMAGE_REL_ARM64_PAGEBASE_REL21",
    "IMAGE_REL_ARM64_PAGEOFFSET_12A",
    "IMAGE_REL_ARM64_PAGEOFFSET_12L",
    "IMAGE_REL_I386_DIR32",
    "IMAGE_REL_I386_REL32",
    "R_AARCH64_ABS64",
    "R_AARCH64_ADR_GOT_PAGE",
    "R_AARCH64_CALL26",
    "R_AARCH64_JUMP26",
    "R_AARCH64_LD64_GOT_LO12_NC",
    "R_AARCH64_MOVW_UABS_G0_NC",
    "R_AARCH64_MOVW_UABS_G1_NC",
    "R_AARCH64_MOVW_UABS_G2_NC",
    "R_AARCH64_MOVW_UABS_G3",
    "R_X86_64_64",
    "R_X86_64_GOTPCREL",
    "R_X86_64_GOTPCRELX",
    "R_X86_64_PC32",
    "R_X86_64_REX_GOTPCRELX",
    "X86_64_RELOC_BRANCH",
    "X86_64_RELOC_GOT",
    "X86_64_RELOC_GOT_LOAD",
    "X86_64_RELOC_SIGNED",
    "X86_64_RELOC_UNSIGNED",
]


class COFFRelocation(typing.TypedDict):
    """A COFF object file relocation record."""

    Type: dict[typing.Literal["Value"], HoleKind]
    Symbol: str
    Offset: int


class ELFRelocation(typing.TypedDict):
    """An ELF object file relocation record."""

    Addend: int
    Offset: int
    Symbol: dict[typing.Literal["Value"], str]
    Type: dict[typing.Literal["Value"], HoleKind]


class MachORelocation(typing.TypedDict):
    """A Mach-O object file relocation record."""

    Offset: int
    Section: typing.NotRequired[dict[typing.Literal["Value"], str]]
    Symbol: typing.NotRequired[dict[typing.Literal["Value"], str]]
    Type: dict[typing.Literal["Value"], HoleKind]


class _COFFSymbol(typing.TypedDict):
    Name: str
    Value: int


class _ELFSymbol(typing.TypedDict):
    Name: dict[typing.Literal["Value"], str]
    Value: int


class _MachOSymbol(typing.TypedDict):
    Name: dict[typing.Literal["Value"], str]
    Value: int


class COFFSection(typing.TypedDict):
    """A COFF object file section."""

    Characteristics: dict[
        typing.Literal["Flags"], list[dict[typing.Literal["Name"], str]]
    ]
    Number: int
    RawDataSize: int
    Relocations: list[dict[typing.Literal["Relocation"], COFFRelocation]]
    SectionData: typing.NotRequired[dict[typing.Literal["Bytes"], list[int]]]
    Symbols: list[dict[typing.Literal["Symbol"], _COFFSymbol]]


class ELFSection(typing.TypedDict):
    """An ELF object file section."""

    Flags: dict[typing.Literal["Flags"], list[dict[typing.Literal["Name"], str]]]
    Index: int
    Info: int
    Relocations: list[dict[typing.Literal["Relocation"], ELFRelocation]]
    SectionData: dict[typing.Literal["Bytes"], list[int]]
    Symbols: list[dict[typing.Literal["Symbol"], _ELFSymbol]]
    Type: dict[typing.Literal["Value"], str]


class MachOSection(typing.TypedDict):
    """A Mach-O object file section."""

    Address: int
    Attributes: dict[typing.Literal["Flags"], list[dict[typing.Literal["Name"], str]]]
    Index: int
    Name: dict[typing.Literal["Value"], str]
    Relocations: typing.NotRequired[
        list[dict[typing.Literal["Relocation"], MachORelocation]]
    ]
    SectionData: typing.NotRequired[dict[typing.Literal["Bytes"], list[int]]]
    Symbols: typing.NotRequired[list[dict[typing.Literal["Symbol"], _MachOSymbol]]]