| 1 |
"""Schema for the JSON produced by llvm-readobj --elf-output-style=JSON.""" |
| 2 |
|
| 3 |
import typing |
| 4 |
|
| 5 |
HoleKind: typing.TypeAlias = typing.Literal[ |
| 6 |
"ARM64_RELOC_BRANCH26", |
| 7 |
"ARM64_RELOC_GOT_LOAD_PAGE21", |
| 8 |
"ARM64_RELOC_GOT_LOAD_PAGEOFF12", |
| 9 |
"ARM64_RELOC_PAGE21", |
| 10 |
"ARM64_RELOC_PAGEOFF12", |
| 11 |
"ARM64_RELOC_UNSIGNED", |
| 12 |
"IMAGE_REL_AMD64_REL32", |
| 13 |
"IMAGE_REL_ARM64_BRANCH26", |
| 14 |
"IMAGE_REL_ARM64_PAGEBASE_REL21", |
| 15 |
"IMAGE_REL_ARM64_PAGEOFFSET_12A", |
| 16 |
"IMAGE_REL_ARM64_PAGEOFFSET_12L", |
| 17 |
"IMAGE_REL_I386_DIR32", |
| 18 |
"IMAGE_REL_I386_REL32", |
| 19 |
"R_AARCH64_ABS64", |
| 20 |
"R_AARCH64_ADR_GOT_PAGE", |
| 21 |
"R_AARCH64_ADR_PREL_PG_HI21", |
| 22 |
"R_AARCH64_CALL26", |
| 23 |
"R_AARCH64_JUMP26", |
| 24 |
"R_AARCH64_ADD_ABS_LO12_NC", |
| 25 |
"R_AARCH64_LD64_GOT_LO12_NC", |
| 26 |
"R_AARCH64_MOVW_UABS_G0_NC", |
| 27 |
"R_AARCH64_MOVW_UABS_G1_NC", |
| 28 |
"R_AARCH64_MOVW_UABS_G2_NC", |
| 29 |
"R_AARCH64_MOVW_UABS_G3", |
| 30 |
"R_X86_64_64", |
| 31 |
"R_X86_64_GOTPCREL", |
| 32 |
"R_X86_64_GOTPCRELX", |
| 33 |
"R_X86_64_PC32", |
| 34 |
"R_X86_64_REX_GOTPCRELX", |
| 35 |
"X86_64_RELOC_BRANCH", |
| 36 |
"X86_64_RELOC_GOT", |
| 37 |
"X86_64_RELOC_GOT_LOAD", |
| 38 |
"X86_64_RELOC_SIGNED", |
| 39 |
"X86_64_RELOC_UNSIGNED", |
| 40 |
] |
| 41 |
|
| 42 |
|
| 43 |
class COFFRelocation(typing.TypedDict): |
| 44 |
"""A COFF object file relocation record.""" |
| 45 |
|
| 46 |
Type: dict[typing.Literal["Value"], HoleKind] |
| 47 |
Symbol: str |
| 48 |
Offset: int |
| 49 |
|
| 50 |
|
| 51 |
class ELFRelocation(typing.TypedDict): |
| 52 |
"""An ELF object file relocation record.""" |
| 53 |
|
| 54 |
Addend: int |
| 55 |
Offset: int |
| 56 |
Symbol: dict[typing.Literal["Value"], str] |
| 57 |
Type: dict[typing.Literal["Value"], HoleKind] |
| 58 |
|
| 59 |
|
| 60 |
class MachORelocation(typing.TypedDict): |
| 61 |
"""A Mach-O object file relocation record.""" |
| 62 |
|
| 63 |
Offset: int |
| 64 |
Section: typing.NotRequired[dict[typing.Literal["Value"], str]] |
| 65 |
Symbol: typing.NotRequired[dict[typing.Literal["Value"], str]] |
| 66 |
Type: dict[typing.Literal["Value"], HoleKind] |
| 67 |
|
| 68 |
|
| 69 |
class _COFFSymbol(typing.TypedDict): |
| 70 |
Name: str |
| 71 |
Value: int |
| 72 |
|
| 73 |
|
| 74 |
class _ELFSymbol(typing.TypedDict): |
| 75 |
Name: dict[typing.Literal["Name"], str] |
| 76 |
Value: int |
| 77 |
|
| 78 |
|
| 79 |
class _MachOSymbol(typing.TypedDict): |
| 80 |
Name: dict[typing.Literal["Name"], str] |
| 81 |
Value: int |
| 82 |
|
| 83 |
|
| 84 |
class COFFSection(typing.TypedDict): |
| 85 |
"""A COFF object file section.""" |
| 86 |
|
| 87 |
Characteristics: dict[ |
| 88 |
typing.Literal["Flags"], list[dict[typing.Literal["Name"], str]] |
| 89 |
] |
| 90 |
Number: int |
| 91 |
RawDataSize: int |
| 92 |
Relocations: list[dict[typing.Literal["Relocation"], COFFRelocation]] |
| 93 |
SectionData: typing.NotRequired[dict[typing.Literal["Bytes"], list[int]]] |
| 94 |
Symbols: list[dict[typing.Literal["Symbol"], _COFFSymbol]] |
| 95 |
|
| 96 |
|
| 97 |
class ELFSection(typing.TypedDict): |
| 98 |
"""An ELF object file section.""" |
| 99 |
|
| 100 |
Flags: dict[typing.Literal["Flags"], list[dict[typing.Literal["Name"], str]]] |
| 101 |
Index: int |
| 102 |
Info: int |
| 103 |
Relocations: list[dict[typing.Literal["Relocation"], ELFRelocation]] |
| 104 |
SectionData: dict[typing.Literal["Bytes"], list[int]] |
| 105 |
Symbols: list[dict[typing.Literal["Symbol"], _ELFSymbol]] |
| 106 |
Type: dict[typing.Literal["Name"], str] |
| 107 |
|
| 108 |
|
| 109 |
class MachOSection(typing.TypedDict): |
| 110 |
"""A Mach-O object file section.""" |
| 111 |
|
| 112 |
Address: int |
| 113 |
Attributes: dict[typing.Literal["Flags"], list[dict[typing.Literal["Name"], str]]] |
| 114 |
Index: int |
| 115 |
Name: dict[typing.Literal["Value"], str] |
| 116 |
Relocations: typing.NotRequired[ |
| 117 |
list[dict[typing.Literal["Relocation"], MachORelocation]] |
| 118 |
] |
| 119 |
SectionData: typing.NotRequired[dict[typing.Literal["Bytes"], list[int]]] |
| 120 |
Symbols: typing.NotRequired[list[dict[typing.Literal["Symbol"], _MachOSymbol]]] |