0001
0002 #ifndef _UAPI_LINUX_ELF_H
0003 #define _UAPI_LINUX_ELF_H
0004
0005 #include <linux/types.h>
0006 #include <linux/elf-em.h>
0007
0008
0009 typedef __u32 Elf32_Addr;
0010 typedef __u16 Elf32_Half;
0011 typedef __u32 Elf32_Off;
0012 typedef __s32 Elf32_Sword;
0013 typedef __u32 Elf32_Word;
0014
0015
0016 typedef __u64 Elf64_Addr;
0017 typedef __u16 Elf64_Half;
0018 typedef __s16 Elf64_SHalf;
0019 typedef __u64 Elf64_Off;
0020 typedef __s32 Elf64_Sword;
0021 typedef __u32 Elf64_Word;
0022 typedef __u64 Elf64_Xword;
0023 typedef __s64 Elf64_Sxword;
0024
0025
0026 #define PT_NULL 0
0027 #define PT_LOAD 1
0028 #define PT_DYNAMIC 2
0029 #define PT_INTERP 3
0030 #define PT_NOTE 4
0031 #define PT_SHLIB 5
0032 #define PT_PHDR 6
0033 #define PT_TLS 7
0034 #define PT_LOOS 0x60000000
0035 #define PT_HIOS 0x6fffffff
0036 #define PT_LOPROC 0x70000000
0037 #define PT_HIPROC 0x7fffffff
0038 #define PT_GNU_EH_FRAME (PT_LOOS + 0x474e550)
0039 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
0040 #define PT_GNU_RELRO (PT_LOOS + 0x474e552)
0041 #define PT_GNU_PROPERTY (PT_LOOS + 0x474e553)
0042
0043
0044
0045 #define PT_AARCH64_MEMTAG_MTE (PT_LOPROC + 0x2)
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 #define PN_XNUM 0xffff
0068
0069
0070 #define ET_NONE 0
0071 #define ET_REL 1
0072 #define ET_EXEC 2
0073 #define ET_DYN 3
0074 #define ET_CORE 4
0075 #define ET_LOPROC 0xff00
0076 #define ET_HIPROC 0xffff
0077
0078
0079 #define DT_NULL 0
0080 #define DT_NEEDED 1
0081 #define DT_PLTRELSZ 2
0082 #define DT_PLTGOT 3
0083 #define DT_HASH 4
0084 #define DT_STRTAB 5
0085 #define DT_SYMTAB 6
0086 #define DT_RELA 7
0087 #define DT_RELASZ 8
0088 #define DT_RELAENT 9
0089 #define DT_STRSZ 10
0090 #define DT_SYMENT 11
0091 #define DT_INIT 12
0092 #define DT_FINI 13
0093 #define DT_SONAME 14
0094 #define DT_RPATH 15
0095 #define DT_SYMBOLIC 16
0096 #define DT_REL 17
0097 #define DT_RELSZ 18
0098 #define DT_RELENT 19
0099 #define DT_PLTREL 20
0100 #define DT_DEBUG 21
0101 #define DT_TEXTREL 22
0102 #define DT_JMPREL 23
0103 #define DT_ENCODING 32
0104 #define OLD_DT_LOOS 0x60000000
0105 #define DT_LOOS 0x6000000d
0106 #define DT_HIOS 0x6ffff000
0107 #define DT_VALRNGLO 0x6ffffd00
0108 #define DT_VALRNGHI 0x6ffffdff
0109 #define DT_ADDRRNGLO 0x6ffffe00
0110 #define DT_ADDRRNGHI 0x6ffffeff
0111 #define DT_VERSYM 0x6ffffff0
0112 #define DT_RELACOUNT 0x6ffffff9
0113 #define DT_RELCOUNT 0x6ffffffa
0114 #define DT_FLAGS_1 0x6ffffffb
0115 #define DT_VERDEF 0x6ffffffc
0116 #define DT_VERDEFNUM 0x6ffffffd
0117 #define DT_VERNEED 0x6ffffffe
0118 #define DT_VERNEEDNUM 0x6fffffff
0119 #define OLD_DT_HIOS 0x6fffffff
0120 #define DT_LOPROC 0x70000000
0121 #define DT_HIPROC 0x7fffffff
0122
0123
0124 #define STB_LOCAL 0
0125 #define STB_GLOBAL 1
0126 #define STB_WEAK 2
0127
0128 #define STT_NOTYPE 0
0129 #define STT_OBJECT 1
0130 #define STT_FUNC 2
0131 #define STT_SECTION 3
0132 #define STT_FILE 4
0133 #define STT_COMMON 5
0134 #define STT_TLS 6
0135
0136 #define ELF_ST_BIND(x) ((x) >> 4)
0137 #define ELF_ST_TYPE(x) ((x) & 0xf)
0138 #define ELF32_ST_BIND(x) ELF_ST_BIND(x)
0139 #define ELF32_ST_TYPE(x) ELF_ST_TYPE(x)
0140 #define ELF64_ST_BIND(x) ELF_ST_BIND(x)
0141 #define ELF64_ST_TYPE(x) ELF_ST_TYPE(x)
0142
0143 typedef struct dynamic{
0144 Elf32_Sword d_tag;
0145 union{
0146 Elf32_Sword d_val;
0147 Elf32_Addr d_ptr;
0148 } d_un;
0149 } Elf32_Dyn;
0150
0151 typedef struct {
0152 Elf64_Sxword d_tag;
0153 union {
0154 Elf64_Xword d_val;
0155 Elf64_Addr d_ptr;
0156 } d_un;
0157 } Elf64_Dyn;
0158
0159
0160 #define ELF32_R_SYM(x) ((x) >> 8)
0161 #define ELF32_R_TYPE(x) ((x) & 0xff)
0162
0163 #define ELF64_R_SYM(i) ((i) >> 32)
0164 #define ELF64_R_TYPE(i) ((i) & 0xffffffff)
0165
0166 typedef struct elf32_rel {
0167 Elf32_Addr r_offset;
0168 Elf32_Word r_info;
0169 } Elf32_Rel;
0170
0171 typedef struct elf64_rel {
0172 Elf64_Addr r_offset;
0173 Elf64_Xword r_info;
0174 } Elf64_Rel;
0175
0176 typedef struct elf32_rela{
0177 Elf32_Addr r_offset;
0178 Elf32_Word r_info;
0179 Elf32_Sword r_addend;
0180 } Elf32_Rela;
0181
0182 typedef struct elf64_rela {
0183 Elf64_Addr r_offset;
0184 Elf64_Xword r_info;
0185 Elf64_Sxword r_addend;
0186 } Elf64_Rela;
0187
0188 typedef struct elf32_sym{
0189 Elf32_Word st_name;
0190 Elf32_Addr st_value;
0191 Elf32_Word st_size;
0192 unsigned char st_info;
0193 unsigned char st_other;
0194 Elf32_Half st_shndx;
0195 } Elf32_Sym;
0196
0197 typedef struct elf64_sym {
0198 Elf64_Word st_name;
0199 unsigned char st_info;
0200 unsigned char st_other;
0201 Elf64_Half st_shndx;
0202 Elf64_Addr st_value;
0203 Elf64_Xword st_size;
0204 } Elf64_Sym;
0205
0206
0207 #define EI_NIDENT 16
0208
0209 typedef struct elf32_hdr{
0210 unsigned char e_ident[EI_NIDENT];
0211 Elf32_Half e_type;
0212 Elf32_Half e_machine;
0213 Elf32_Word e_version;
0214 Elf32_Addr e_entry;
0215 Elf32_Off e_phoff;
0216 Elf32_Off e_shoff;
0217 Elf32_Word e_flags;
0218 Elf32_Half e_ehsize;
0219 Elf32_Half e_phentsize;
0220 Elf32_Half e_phnum;
0221 Elf32_Half e_shentsize;
0222 Elf32_Half e_shnum;
0223 Elf32_Half e_shstrndx;
0224 } Elf32_Ehdr;
0225
0226 typedef struct elf64_hdr {
0227 unsigned char e_ident[EI_NIDENT];
0228 Elf64_Half e_type;
0229 Elf64_Half e_machine;
0230 Elf64_Word e_version;
0231 Elf64_Addr e_entry;
0232 Elf64_Off e_phoff;
0233 Elf64_Off e_shoff;
0234 Elf64_Word e_flags;
0235 Elf64_Half e_ehsize;
0236 Elf64_Half e_phentsize;
0237 Elf64_Half e_phnum;
0238 Elf64_Half e_shentsize;
0239 Elf64_Half e_shnum;
0240 Elf64_Half e_shstrndx;
0241 } Elf64_Ehdr;
0242
0243
0244
0245 #define PF_R 0x4
0246 #define PF_W 0x2
0247 #define PF_X 0x1
0248
0249 typedef struct elf32_phdr{
0250 Elf32_Word p_type;
0251 Elf32_Off p_offset;
0252 Elf32_Addr p_vaddr;
0253 Elf32_Addr p_paddr;
0254 Elf32_Word p_filesz;
0255 Elf32_Word p_memsz;
0256 Elf32_Word p_flags;
0257 Elf32_Word p_align;
0258 } Elf32_Phdr;
0259
0260 typedef struct elf64_phdr {
0261 Elf64_Word p_type;
0262 Elf64_Word p_flags;
0263 Elf64_Off p_offset;
0264 Elf64_Addr p_vaddr;
0265 Elf64_Addr p_paddr;
0266 Elf64_Xword p_filesz;
0267 Elf64_Xword p_memsz;
0268 Elf64_Xword p_align;
0269 } Elf64_Phdr;
0270
0271
0272 #define SHT_NULL 0
0273 #define SHT_PROGBITS 1
0274 #define SHT_SYMTAB 2
0275 #define SHT_STRTAB 3
0276 #define SHT_RELA 4
0277 #define SHT_HASH 5
0278 #define SHT_DYNAMIC 6
0279 #define SHT_NOTE 7
0280 #define SHT_NOBITS 8
0281 #define SHT_REL 9
0282 #define SHT_SHLIB 10
0283 #define SHT_DYNSYM 11
0284 #define SHT_NUM 12
0285 #define SHT_LOPROC 0x70000000
0286 #define SHT_HIPROC 0x7fffffff
0287 #define SHT_LOUSER 0x80000000
0288 #define SHT_HIUSER 0xffffffff
0289
0290
0291 #define SHF_WRITE 0x1
0292 #define SHF_ALLOC 0x2
0293 #define SHF_EXECINSTR 0x4
0294 #define SHF_RELA_LIVEPATCH 0x00100000
0295 #define SHF_RO_AFTER_INIT 0x00200000
0296 #define SHF_MASKPROC 0xf0000000
0297
0298
0299 #define SHN_UNDEF 0
0300 #define SHN_LORESERVE 0xff00
0301 #define SHN_LOPROC 0xff00
0302 #define SHN_HIPROC 0xff1f
0303 #define SHN_LIVEPATCH 0xff20
0304 #define SHN_ABS 0xfff1
0305 #define SHN_COMMON 0xfff2
0306 #define SHN_HIRESERVE 0xffff
0307
0308 typedef struct elf32_shdr {
0309 Elf32_Word sh_name;
0310 Elf32_Word sh_type;
0311 Elf32_Word sh_flags;
0312 Elf32_Addr sh_addr;
0313 Elf32_Off sh_offset;
0314 Elf32_Word sh_size;
0315 Elf32_Word sh_link;
0316 Elf32_Word sh_info;
0317 Elf32_Word sh_addralign;
0318 Elf32_Word sh_entsize;
0319 } Elf32_Shdr;
0320
0321 typedef struct elf64_shdr {
0322 Elf64_Word sh_name;
0323 Elf64_Word sh_type;
0324 Elf64_Xword sh_flags;
0325 Elf64_Addr sh_addr;
0326 Elf64_Off sh_offset;
0327 Elf64_Xword sh_size;
0328 Elf64_Word sh_link;
0329 Elf64_Word sh_info;
0330 Elf64_Xword sh_addralign;
0331 Elf64_Xword sh_entsize;
0332 } Elf64_Shdr;
0333
0334 #define EI_MAG0 0
0335 #define EI_MAG1 1
0336 #define EI_MAG2 2
0337 #define EI_MAG3 3
0338 #define EI_CLASS 4
0339 #define EI_DATA 5
0340 #define EI_VERSION 6
0341 #define EI_OSABI 7
0342 #define EI_PAD 8
0343
0344 #define ELFMAG0 0x7f
0345 #define ELFMAG1 'E'
0346 #define ELFMAG2 'L'
0347 #define ELFMAG3 'F'
0348 #define ELFMAG "\177ELF"
0349 #define SELFMAG 4
0350
0351 #define ELFCLASSNONE 0
0352 #define ELFCLASS32 1
0353 #define ELFCLASS64 2
0354 #define ELFCLASSNUM 3
0355
0356 #define ELFDATANONE 0
0357 #define ELFDATA2LSB 1
0358 #define ELFDATA2MSB 2
0359
0360 #define EV_NONE 0
0361 #define EV_CURRENT 1
0362 #define EV_NUM 2
0363
0364 #define ELFOSABI_NONE 0
0365 #define ELFOSABI_LINUX 3
0366
0367 #ifndef ELF_OSABI
0368 #define ELF_OSABI ELFOSABI_NONE
0369 #endif
0370
0371
0372
0373
0374
0375
0376
0377 #define NT_PRSTATUS 1
0378 #define NT_PRFPREG 2
0379 #define NT_PRPSINFO 3
0380 #define NT_TASKSTRUCT 4
0381 #define NT_AUXV 6
0382
0383
0384
0385
0386 #define NT_SIGINFO 0x53494749
0387 #define NT_FILE 0x46494c45
0388 #define NT_PRXFPREG 0x46e62b7f
0389 #define NT_PPC_VMX 0x100
0390 #define NT_PPC_SPE 0x101
0391 #define NT_PPC_VSX 0x102
0392 #define NT_PPC_TAR 0x103
0393 #define NT_PPC_PPR 0x104
0394 #define NT_PPC_DSCR 0x105
0395 #define NT_PPC_EBB 0x106
0396 #define NT_PPC_PMU 0x107
0397 #define NT_PPC_TM_CGPR 0x108
0398 #define NT_PPC_TM_CFPR 0x109
0399 #define NT_PPC_TM_CVMX 0x10a
0400 #define NT_PPC_TM_CVSX 0x10b
0401 #define NT_PPC_TM_SPR 0x10c
0402 #define NT_PPC_TM_CTAR 0x10d
0403 #define NT_PPC_TM_CPPR 0x10e
0404 #define NT_PPC_TM_CDSCR 0x10f
0405 #define NT_PPC_PKEY 0x110
0406 #define NT_386_TLS 0x200
0407 #define NT_386_IOPERM 0x201
0408 #define NT_X86_XSTATE 0x202
0409 #define NT_S390_HIGH_GPRS 0x300
0410 #define NT_S390_TIMER 0x301
0411 #define NT_S390_TODCMP 0x302
0412 #define NT_S390_TODPREG 0x303
0413 #define NT_S390_CTRS 0x304
0414 #define NT_S390_PREFIX 0x305
0415 #define NT_S390_LAST_BREAK 0x306
0416 #define NT_S390_SYSTEM_CALL 0x307
0417 #define NT_S390_TDB 0x308
0418 #define NT_S390_VXRS_LOW 0x309
0419 #define NT_S390_VXRS_HIGH 0x30a
0420 #define NT_S390_GS_CB 0x30b
0421 #define NT_S390_GS_BC 0x30c
0422 #define NT_S390_RI_CB 0x30d
0423 #define NT_S390_PV_CPU_DATA 0x30e
0424 #define NT_ARM_VFP 0x400
0425 #define NT_ARM_TLS 0x401
0426 #define NT_ARM_HW_BREAK 0x402
0427 #define NT_ARM_HW_WATCH 0x403
0428 #define NT_ARM_SYSTEM_CALL 0x404
0429 #define NT_ARM_SVE 0x405
0430 #define NT_ARM_PAC_MASK 0x406
0431 #define NT_ARM_PACA_KEYS 0x407
0432 #define NT_ARM_PACG_KEYS 0x408
0433 #define NT_ARM_TAGGED_ADDR_CTRL 0x409
0434 #define NT_ARM_PAC_ENABLED_KEYS 0x40a
0435 #define NT_ARM_SSVE 0x40b
0436 #define NT_ARM_ZA 0x40c
0437 #define NT_ARC_V2 0x600
0438 #define NT_VMCOREDD 0x700
0439 #define NT_MIPS_DSP 0x800
0440 #define NT_MIPS_FP_MODE 0x801
0441 #define NT_MIPS_MSA 0x802
0442 #define NT_LOONGARCH_CPUCFG 0xa00
0443 #define NT_LOONGARCH_CSR 0xa01
0444 #define NT_LOONGARCH_LSX 0xa02
0445 #define NT_LOONGARCH_LASX 0xa03
0446 #define NT_LOONGARCH_LBT 0xa04
0447
0448
0449 #define NT_GNU_PROPERTY_TYPE_0 5
0450
0451
0452 typedef struct elf32_note {
0453 Elf32_Word n_namesz;
0454 Elf32_Word n_descsz;
0455 Elf32_Word n_type;
0456 } Elf32_Nhdr;
0457
0458
0459 typedef struct elf64_note {
0460 Elf64_Word n_namesz;
0461 Elf64_Word n_descsz;
0462 Elf64_Word n_type;
0463 } Elf64_Nhdr;
0464
0465
0466 #define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000
0467
0468
0469 #define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0)
0470
0471 #endif