* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_LD_ELH_PRI_H
#define _LOS_LD_ELH_PRI_H
#include "los_base.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
#define LD_EI_NIDENT 16
typedef struct {
UINT8 elfIdent[LD_EI_NIDENT];
UINT16 elfType;
UINT16 elfMachine;
UINT32 elfVersion;
UINT32 elfEntry;
UINT32 elfPhoff;
UINT32 elfShoff;
UINT32 elfFlags;
UINT16 elfHeadSize;
UINT16 elfPhEntSize;
UINT16 elfPhNum;
UINT16 elfShEntSize;
UINT16 elfShNum;
UINT16 elfShStrIndex;
} LDElf32Ehdr;
typedef struct {
UINT8 elfIdent[LD_EI_NIDENT];
UINT16 elfType;
UINT16 elfMachine;
UINT32 elfVersion;
UINT64 elfEntry;
UINT64 elfPhoff;
UINT64 elfShoff;
UINT32 elfFlags;
UINT16 elfHeadSize;
UINT16 elfPhEntSize;
UINT16 elfPhNum;
UINT16 elfShEntSize;
UINT16 elfShNum;
UINT16 elfShStrIndex;
} LDElf64Ehdr;
#ifdef LOSCFG_AARCH64
#define LD_ELF_EHDR LDElf64Ehdr
#else
#define LD_ELF_EHDR LDElf32Ehdr
#endif
#define LD_EI_MAG0 0
#define LD_EI_MAG1 1
#define LD_EI_MAG2 2
#define LD_EI_MAG3 3
#define LD_EI_CLASS 4
#define LD_EI_DATA 5
#define LD_EI_VERSION 6
#define LD_EI_PAD 7
#define LD_ELFMAG0 0x7f
#define LD_ELFMAG1 'E'
#define LD_ELFMAG2 'L'
#define LD_ELFMAG3 'F'
#define LD_ELFMAG "\177ELF"
#define LD_SELFMAG 4
#define LD_ELF_CLASS_NONE 0
#define LD_ELF_CLASS32 1
#define LD_ELF_CLASS64 2
#ifdef LOSCFG_AARCH64
#define LD_ELF_CLASS LD_ELF_CLASS64
#else
#define LD_ELF_CLASS LD_ELF_CLASS32
#endif
#define LD_ELF_DATA_NONE 0
#define LD_ELF_DATA2LSB 1
#define LD_ELF_DATA2MSB 2
#define LD_ET_NONE 0
#define LD_ET_REL 1
#define LD_ET_EXEC 2
#define LD_ET_DYN 3
#define LD_ET_CORE 4
#define LD_ET_LOPROC 0xff00
#define LD_ET_HIPROC 0xffff
#define LD_EM_NONE 0
#define LD_EM_M32 1
#define LD_EM_SPARC 2
#define LD_EM_386 3
#define LD_EM_68K 4
#define LD_EM_88K 5
#define LD_EM_486 6
#define LD_EM_860 7
#define LD_EM_MIPS 8
#define LD_EM_MIPS_RS4_BE 10
#define LD_EM_PPC_OLD 17
#define LD_EM_PPC 20
#define LD_EM_RCE_OLD 25
#define LD_EM_RCE 39
#define LD_EM_MCORE 39
#define LD_EM_SH 42
#define LD_EM_M32R 36929
#define LD_EM_NEC 36992
#define LD_EM_NEC_830 36
#define LD_EM_SC 58
#define LD_EM_ARM 40
#define LD_EM_XTENSA 0x5E
#define LD_EM_AARCH64 183
#ifdef LOSCFG_AARCH64
#define LD_EM_TYPE LD_EM_AARCH64
#else
#define LD_EM_TYPE LD_EM_ARM
#endif
#define LD_EF_PPC_EMB 0x80000000
#define LD_EF_MIPS_NOREORDER 0x00000001
#define LD_EF_MIPS_PIC 0x00000002
#define LD_EF_MIPS_CPIC 0x00000004
#define LD_EF_MIPS_ARCH 0xf0000000
#define LD_EF_MIPS_ARCH_MIPS_2 0x10000000
#define LD_EF_MIPS_ARCH_MIPS_3 0x20000000
#define LD_PT_NULL 0
#define LD_PT_LOAD 1
#define LD_PT_DYNAMIC 2
#define LD_PT_INTERP 3
#define LD_PT_NOTE 4
#define LD_PT_SHLIB 5
#define LD_PT_PHDR 6
#define LD_PT_GNU_STACK 0x6474e551
#define LD_EV_NONE 0
#define LD_EV_CURRENT 1
typedef struct {
UINT32 type;
UINT32 offset;
UINT32 vAddr;
UINT32 phyAddr;
UINT32 fileSize;
UINT32 memSize;
UINT32 flags;
UINT32 align;
} LDElf32Phdr;
typedef struct {
UINT32 type;
UINT32 flags;
UINT64 offset;
UINT64 vAddr;
UINT64 phyAddr;
UINT64 fileSize;
UINT64 memSize;
UINT64 align;
} LDElf64Phdr;
#ifdef LOSCFG_AARCH64
#define LD_ELF_PHDR LDElf64Phdr
#else
#define LD_ELF_PHDR LDElf32Phdr
#endif
#define LD_SHN_UNDEF 0
#define LD_SHN_LORESERVE 0xff00
#define LD_SHN_LOPROC 0xff00
#define LD_SHN_HIPROC 0xff1f
#define LD_SHN_ABS 0xfff1
#define LD_SHN_COMMON 0xfff2
#define LD_SHN_HIRESERVE 0xffff
#define LD_SHN_GHCOMMON 0xff00
typedef struct {
UINT32 shName;
UINT32 shType;
UINT32 shFlags;
UINT32 shAddr;
UINT32 shOffset;
UINT32 shSize;
UINT32 shLink;
UINT32 shInfo;
UINT32 shAddrAlign;
UINT32 shEntSize;
} LDElf32Shdr;
typedef struct {
UINT32 shName;
UINT32 shType;
UINT64 shFlags;
UINT64 shAddr;
UINT64 shOffset;
UINT64 shSize;
UINT32 shLink;
UINT32 shInfo;
UINT64 shAddrAlign;
UINT64 shEntSize;
} LDElf64Shdr;
#ifdef LOSCFG_AARCH64
#define LD_ELF_SHDR LDElf64Shdr
#else
#define LD_ELF_SHDR LDElf32Shdr
#endif
#define LD_SHT_NULL 0U
#define LD_SHT_PROGBITS 1U
#define LD_SHT_SYMTAB 2U
#define LD_SHT_STRTAB 3U
#define LD_SHT_RELA 4U
#define LD_SHT_HASH 5U
#define LD_SHT_DYNAMIC 6U
#define LD_SHT_NOTE 7U
#define LD_SHT_NOBITS 8U
#define LD_SHT_REL 9U
#define LD_SHT_SHLIB 10U
#define LD_SHT_DYNSYM 11U
#define LD_SHT_COMDAT 12U
#define LD_SHT_LOPROC 0x70000000U
#define LD_SHT_HIPROC 0x7fffffffU
#define LD_SHT_LOUSER 0x80000000U
#define LD_SHT_HIUSER 0xffffffffU
#define LD_SHF_WRITE 0x1U
#define LD_SHF_ALLOC 0x2U
#define LD_SHF_EXECINSTR 0x4U
#define LD_SHF_MASKPROC 0xf0000000U
typedef struct {
UINT32 stName;
UINT32 stValue;
UINT32 stSize;
UINT8 stInfo;
UINT8 stOther;
UINT16 stShndx;
} LDElf32Sym;
typedef struct {
UINT32 stName;
UINT8 stInfo;
UINT8 stOther;
UINT16 stShndx;
UINT64 stValue;
UINT64 stSize;
} LDElf64Sym;
#ifdef LOSCFG_AARCH64
#define LD_ELF_SYM LDElf64Sym
#else
#define LD_ELF_SYM LDElf32Sym
#endif
#define LD_STN_UNDEF 0U
#define LD_STB_LOCAL 0U
#define LD_STB_GLOBAL 1U
#define LD_STB_WEAK 2U
#define LD_STB_LOPROC 13U
#define LD_STB_HIPROC 15U
#define LD_STT_NOTYPE 0U
#define LD_STT_OBJECT 1U
#define LD_STT_FUNC 2U
#define LD_STT_SECTION 3U
#define LD_STT_FILE 4U
#define LD_STT_LOPROC 13U
#define LD_STT_HIPROC 15U
#define LD_STT_THUMB 0x80U
#define LD_ELF_ST_BIND(info) ((info) >> 4)
#define LD_ELF_ST_TYPE(info) ((info) & 0xFU)
#define LD_ELF_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xFU))
typedef struct {
UINT32 dynTag;
union {
UINT32 val;
UINT32 ptr;
} dyn;
} LDElf32Dyn;
typedef struct {
UINT64 dynTag;
union {
UINT64 val;
UINT64 ptr;
} dyn;
} LDElf64Dyn;
#ifdef LOSCFG_AARCH64
#define LD_ELF_DYN LDElf64Dyn
#else
#define LD_ELF_DYN LDElf32Dyn
#endif
#define LD_DT_NULL 0
#define LD_DT_NEEDED 1
#define LD_DT_PLTRELSZ 2
#define LD_DT_PLTGOT 3
#define LD_DT_HASH 4
#define LD_DT_STRTAB 5
#define LD_DT_SYMTAB 6
#define LD_DT_RELA 7
#define LD_DT_RELASZ 8
#define LD_DT_RELAENT 9
#define LD_DT_STRSZ 10
#define LD_DT_SYMENT 11
#define LD_DT_INIT 12
#define LD_DT_FINI 13
#define LD_DT_SONAME 14
#define LD_DT_RPATH 15
#define LD_DT_SYMBOLIC 16
#define LD_DT_REL 17
#define LD_DT_RELSZ 18
#define LD_DT_RELENT 19
#define LD_DT_PLTREL 20
#define LD_DT_DEBUG 21
#define LD_DT_TEXTREL 22
#define LD_DT_JMPREL 23
#define LD_DT_ENCODING 32
typedef struct {
UINT32 offset;
UINT32 info;
} LDElf32Rel;
typedef struct {
UINT32 offset;
UINT32 info;
INT32 addend;
} LDElf32Rela;
typedef struct {
UINT64 offset;
UINT64 info;
} LDElf64Rel;
typedef struct {
UINT64 offset;
UINT64 info;
INT64 addend;
} LDElf64Rela;
#ifdef LOSCFG_AARCH64
#define LD_ELF_REL LDElf64Rel
#define LD_ELF_RELA LDElf64Rela
#else
#define LD_ELF_REL LDElf32Rel
#define LD_ELF_RELA LDElf32Rela
#endif
#ifdef LOSCFG_AARCH64
#define LD_ELF_R_SYM(info) ((info) >> 32)
#define LD_ELF_R_TYPE(info) ((info) & 0xFFFFFFFFUL)
#define LD_ELF_R_INFO(sym, type) ((((UINT64)(sym)) << 32) + (type))
#else
#define LD_ELF_R_SYM(info) ((info) >> 8)
#define LD_ELF_R_TYPE(info) ((info) & 0xFFU)
#define LD_ELF_R_INFO(sym, type) (((sym) << 8) + (UINT8)(type))
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif