Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
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 /* 32-bit ELF base types. */
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 /* 64-bit ELF base types. */
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 /* These constants are for the segment types stored in the image headers */
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               /* Thread local storage segment */
0034 #define PT_LOOS    0x60000000      /* OS-specific */
0035 #define PT_HIOS    0x6fffffff      /* OS-specific */
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 /* ARM MTE memory tag segment type */
0045 #define PT_AARCH64_MEMTAG_MTE   (PT_LOPROC + 0x2)
0046 
0047 /*
0048  * Extended Numbering
0049  *
0050  * If the real number of program header table entries is larger than
0051  * or equal to PN_XNUM(0xffff), it is set to sh_info field of the
0052  * section header at index 0, and PN_XNUM is set to e_phnum
0053  * field. Otherwise, the section header at index 0 is zero
0054  * initialized, if it exists.
0055  *
0056  * Specifications are available in:
0057  *
0058  * - Oracle: Linker and Libraries.
0059  *   Part No: 817–1984–19, August 2011.
0060  *   https://docs.oracle.com/cd/E18752_01/pdf/817-1984.pdf
0061  *
0062  * - System V ABI AMD64 Architecture Processor Supplement
0063  *   Draft Version 0.99.4,
0064  *   January 13, 2010.
0065  *   http://www.cs.washington.edu/education/courses/cse351/12wi/supp-docs/abi.pdf
0066  */
0067 #define PN_XNUM 0xffff
0068 
0069 /* These constants define the different elf file types */
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 /* This is the info that is needed to parse the dynamic section of the file */
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 /* This info is needed when parsing the symbol table */
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;       /* entry tag value */
0153   union {
0154     Elf64_Xword d_val;
0155     Elf64_Addr d_ptr;
0156   } d_un;
0157 } Elf64_Dyn;
0158 
0159 /* The following are used with relocations */
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;  /* Location at which to apply the action */
0173   Elf64_Xword r_info;   /* index and type of relocation */
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;  /* Location at which to apply the action */
0184   Elf64_Xword r_info;   /* index and type of relocation */
0185   Elf64_Sxword r_addend;    /* Constant addend used to compute value */
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;       /* Symbol name, index in string tbl */
0199   unsigned char st_info;    /* Type and binding attributes */
0200   unsigned char st_other;   /* No defined meaning, 0 */
0201   Elf64_Half st_shndx;      /* Associated section index */
0202   Elf64_Addr st_value;      /* Value of the symbol */
0203   Elf64_Xword st_size;      /* Associated symbol 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;  /* Entry point */
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]; /* ELF "magic number" */
0228   Elf64_Half e_type;
0229   Elf64_Half e_machine;
0230   Elf64_Word e_version;
0231   Elf64_Addr e_entry;       /* Entry point virtual address */
0232   Elf64_Off e_phoff;        /* Program header table file offset */
0233   Elf64_Off e_shoff;        /* Section header table file offset */
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 /* These constants define the permissions on sections in the program
0244    header, p_flags. */
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;       /* Segment file offset */
0264   Elf64_Addr p_vaddr;       /* Segment virtual address */
0265   Elf64_Addr p_paddr;       /* Segment physical address */
0266   Elf64_Xword p_filesz;     /* Segment size in file */
0267   Elf64_Xword p_memsz;      /* Segment size in memory */
0268   Elf64_Xword p_align;      /* Segment alignment, file & memory */
0269 } Elf64_Phdr;
0270 
0271 /* sh_type */
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 /* sh_flags */
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 /* special section indexes */
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;       /* Section name, index in string tbl */
0323   Elf64_Word sh_type;       /* Type of section */
0324   Elf64_Xword sh_flags;     /* Miscellaneous section attributes */
0325   Elf64_Addr sh_addr;       /* Section virtual addr at execution */
0326   Elf64_Off sh_offset;      /* Section file offset */
0327   Elf64_Xword sh_size;      /* Size of section in bytes */
0328   Elf64_Word sh_link;       /* Index of another section */
0329   Elf64_Word sh_info;       /* Additional section information */
0330   Elf64_Xword sh_addralign; /* Section alignment */
0331   Elf64_Xword sh_entsize;   /* Entry size if section holds table */
0332 } Elf64_Shdr;
0333 
0334 #define EI_MAG0     0       /* e_ident[] indexes */
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        /* EI_MAG */
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       /* EI_CLASS */
0352 #define ELFCLASS32  1
0353 #define ELFCLASS64  2
0354 #define ELFCLASSNUM 3
0355 
0356 #define ELFDATANONE 0       /* e_ident[EI_DATA] */
0357 #define ELFDATA2LSB 1
0358 #define ELFDATA2MSB 2
0359 
0360 #define EV_NONE     0       /* e_version, EI_VERSION */
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  * Notes used in ET_CORE. Architectures export some of the arch register sets
0373  * using the corresponding note types via the PTRACE_GETREGSET and
0374  * PTRACE_SETREGSET requests.
0375  * The note name for all these is "LINUX".
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  * Note to userspace developers: size of NT_SIGINFO note may increase
0384  * in the future to accomodate more fields, don't assume it is fixed!
0385  */
0386 #define NT_SIGINFO      0x53494749
0387 #define NT_FILE         0x46494c45
0388 #define NT_PRXFPREG     0x46e62b7f      /* copied from gdb5.1/include/elf/common.h */
0389 #define NT_PPC_VMX  0x100       /* PowerPC Altivec/VMX registers */
0390 #define NT_PPC_SPE  0x101       /* PowerPC SPE/EVR registers */
0391 #define NT_PPC_VSX  0x102       /* PowerPC VSX registers */
0392 #define NT_PPC_TAR  0x103       /* Target Address Register */
0393 #define NT_PPC_PPR  0x104       /* Program Priority Register */
0394 #define NT_PPC_DSCR 0x105       /* Data Stream Control Register */
0395 #define NT_PPC_EBB  0x106       /* Event Based Branch Registers */
0396 #define NT_PPC_PMU  0x107       /* Performance Monitor Registers */
0397 #define NT_PPC_TM_CGPR  0x108       /* TM checkpointed GPR Registers */
0398 #define NT_PPC_TM_CFPR  0x109       /* TM checkpointed FPR Registers */
0399 #define NT_PPC_TM_CVMX  0x10a       /* TM checkpointed VMX Registers */
0400 #define NT_PPC_TM_CVSX  0x10b       /* TM checkpointed VSX Registers */
0401 #define NT_PPC_TM_SPR   0x10c       /* TM Special Purpose Registers */
0402 #define NT_PPC_TM_CTAR  0x10d       /* TM checkpointed Target Address Register */
0403 #define NT_PPC_TM_CPPR  0x10e       /* TM checkpointed Program Priority Register */
0404 #define NT_PPC_TM_CDSCR 0x10f       /* TM checkpointed Data Stream Control Register */
0405 #define NT_PPC_PKEY 0x110       /* Memory Protection Keys registers */
0406 #define NT_386_TLS  0x200       /* i386 TLS slots (struct user_desc) */
0407 #define NT_386_IOPERM   0x201       /* x86 io permission bitmap (1=deny) */
0408 #define NT_X86_XSTATE   0x202       /* x86 extended state using xsave */
0409 #define NT_S390_HIGH_GPRS   0x300   /* s390 upper register halves */
0410 #define NT_S390_TIMER   0x301       /* s390 timer register */
0411 #define NT_S390_TODCMP  0x302       /* s390 TOD clock comparator register */
0412 #define NT_S390_TODPREG 0x303       /* s390 TOD programmable register */
0413 #define NT_S390_CTRS    0x304       /* s390 control registers */
0414 #define NT_S390_PREFIX  0x305       /* s390 prefix register */
0415 #define NT_S390_LAST_BREAK  0x306   /* s390 breaking event address */
0416 #define NT_S390_SYSTEM_CALL 0x307   /* s390 system call restart data */
0417 #define NT_S390_TDB 0x308       /* s390 transaction diagnostic block */
0418 #define NT_S390_VXRS_LOW    0x309   /* s390 vector registers 0-15 upper half */
0419 #define NT_S390_VXRS_HIGH   0x30a   /* s390 vector registers 16-31 */
0420 #define NT_S390_GS_CB   0x30b       /* s390 guarded storage registers */
0421 #define NT_S390_GS_BC   0x30c       /* s390 guarded storage broadcast control block */
0422 #define NT_S390_RI_CB   0x30d       /* s390 runtime instrumentation */
0423 #define NT_S390_PV_CPU_DATA 0x30e   /* s390 protvirt cpu dump data */
0424 #define NT_ARM_VFP  0x400       /* ARM VFP/NEON registers */
0425 #define NT_ARM_TLS  0x401       /* ARM TLS register */
0426 #define NT_ARM_HW_BREAK 0x402       /* ARM hardware breakpoint registers */
0427 #define NT_ARM_HW_WATCH 0x403       /* ARM hardware watchpoint registers */
0428 #define NT_ARM_SYSTEM_CALL  0x404   /* ARM system call number */
0429 #define NT_ARM_SVE  0x405       /* ARM Scalable Vector Extension registers */
0430 #define NT_ARM_PAC_MASK     0x406   /* ARM pointer authentication code masks */
0431 #define NT_ARM_PACA_KEYS    0x407   /* ARM pointer authentication address keys */
0432 #define NT_ARM_PACG_KEYS    0x408   /* ARM pointer authentication generic key */
0433 #define NT_ARM_TAGGED_ADDR_CTRL 0x409   /* arm64 tagged address control (prctl()) */
0434 #define NT_ARM_PAC_ENABLED_KEYS 0x40a   /* arm64 ptr auth enabled keys (prctl()) */
0435 #define NT_ARM_SSVE 0x40b       /* ARM Streaming SVE registers */
0436 #define NT_ARM_ZA   0x40c       /* ARM SME ZA registers */
0437 #define NT_ARC_V2   0x600       /* ARCv2 accumulator/extra registers */
0438 #define NT_VMCOREDD 0x700       /* Vmcore Device Dump Note */
0439 #define NT_MIPS_DSP 0x800       /* MIPS DSP ASE registers */
0440 #define NT_MIPS_FP_MODE 0x801       /* MIPS floating-point mode */
0441 #define NT_MIPS_MSA 0x802       /* MIPS SIMD registers */
0442 #define NT_LOONGARCH_CPUCFG 0xa00   /* LoongArch CPU config registers */
0443 #define NT_LOONGARCH_CSR    0xa01   /* LoongArch control and status registers */
0444 #define NT_LOONGARCH_LSX    0xa02   /* LoongArch Loongson SIMD Extension registers */
0445 #define NT_LOONGARCH_LASX   0xa03   /* LoongArch Loongson Advanced SIMD Extension registers */
0446 #define NT_LOONGARCH_LBT    0xa04   /* LoongArch Loongson Binary Translation registers */
0447 
0448 /* Note types with note name "GNU" */
0449 #define NT_GNU_PROPERTY_TYPE_0  5
0450 
0451 /* Note header in a PT_NOTE section */
0452 typedef struct elf32_note {
0453   Elf32_Word    n_namesz;   /* Name size */
0454   Elf32_Word    n_descsz;   /* Content size */
0455   Elf32_Word    n_type;     /* Content type */
0456 } Elf32_Nhdr;
0457 
0458 /* Note header in a PT_NOTE section */
0459 typedef struct elf64_note {
0460   Elf64_Word n_namesz;  /* Name size */
0461   Elf64_Word n_descsz;  /* Content size */
0462   Elf64_Word n_type;    /* Content type */
0463 } Elf64_Nhdr;
0464 
0465 /* .note.gnu.property types for EM_AARCH64: */
0466 #define GNU_PROPERTY_AARCH64_FEATURE_1_AND  0xc0000000
0467 
0468 /* Bits for GNU_PROPERTY_AARCH64_FEATURE_1_BTI */
0469 #define GNU_PROPERTY_AARCH64_FEATURE_1_BTI  (1U << 0)
0470 
0471 #endif /* _UAPI_LINUX_ELF_H */