2009-03-04 04:28:35 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * 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.
|
|
|
|
*
|
|
|
|
* 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 OWNER 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.
|
|
|
|
*/
|
2016-07-22 23:56:18 +02:00
|
|
|
|
2020-01-24 23:36:10 +01:00
|
|
|
#pragma once
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2016-11-08 03:27:16 +01:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
2014-02-11 02:46:57 +01:00
|
|
|
#include <linux/elf.h>
|
|
|
|
#include <linux/elf-em.h>
|
2022-10-07 01:11:38 +02:00
|
|
|
#undef EI_PAD
|
|
|
|
|
|
|
|
#include <bits/auxvec.h>
|
|
|
|
#include <bits/elf_common.h>
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2017-11-01 01:22:41 +01:00
|
|
|
/* http://www.sco.com/developers/gabi/latest/ch4.intro.html */
|
2017-12-05 22:00:22 +01:00
|
|
|
typedef __u64 Elf32_Xword;
|
2015-05-08 07:58:00 +02:00
|
|
|
typedef __s64 Elf32_Sxword;
|
|
|
|
|
2013-01-11 23:43:05 +01:00
|
|
|
typedef struct {
|
2014-02-11 02:46:57 +01:00
|
|
|
__u32 a_type;
|
2013-01-11 23:43:05 +01:00
|
|
|
union {
|
2014-02-11 02:46:57 +01:00
|
|
|
__u32 a_val;
|
2013-01-11 23:43:05 +01:00
|
|
|
} a_un;
|
|
|
|
} Elf32_auxv_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2014-02-11 02:46:57 +01:00
|
|
|
__u64 a_type;
|
2013-01-11 23:43:05 +01:00
|
|
|
union {
|
2014-02-11 02:46:57 +01:00
|
|
|
__u64 a_val;
|
2013-01-11 23:43:05 +01:00
|
|
|
} a_un;
|
|
|
|
} Elf64_auxv_t;
|
|
|
|
|
2017-11-01 01:22:41 +01:00
|
|
|
/* http://www.sco.com/developers/gabi/latest/ch4.sheader.html */
|
|
|
|
typedef struct {
|
|
|
|
Elf32_Word ch_type;
|
|
|
|
Elf32_Word ch_size;
|
|
|
|
Elf32_Word ch_addralign;
|
|
|
|
} Elf32_Chdr;
|
|
|
|
typedef struct {
|
|
|
|
Elf64_Word ch_type;
|
|
|
|
Elf64_Word ch_reserved;
|
|
|
|
Elf64_Xword ch_size;
|
|
|
|
Elf64_Xword ch_addralign;
|
|
|
|
} Elf64_Chdr;
|
|
|
|
|
2017-12-05 22:00:22 +01:00
|
|
|
typedef struct {
|
|
|
|
Elf32_Word l_name;
|
|
|
|
Elf32_Word l_time_stamp;
|
|
|
|
Elf32_Word l_checksum;
|
|
|
|
Elf32_Word l_version;
|
|
|
|
Elf32_Word l_flags;
|
|
|
|
} Elf32_Lib;
|
|
|
|
typedef struct {
|
|
|
|
Elf64_Word l_name;
|
|
|
|
Elf64_Word l_time_stamp;
|
|
|
|
Elf64_Word l_checksum;
|
|
|
|
Elf64_Word l_version;
|
|
|
|
Elf64_Word l_flags;
|
|
|
|
} Elf64_Lib;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Elf32_Xword m_value;
|
|
|
|
Elf32_Word m_info;
|
|
|
|
Elf32_Word m_poffset;
|
|
|
|
Elf32_Half m_repeat;
|
|
|
|
Elf32_Half m_stride;
|
|
|
|
} Elf32_Move;
|
|
|
|
typedef struct {
|
|
|
|
Elf64_Xword m_value;
|
|
|
|
Elf64_Xword m_info;
|
|
|
|
Elf64_Xword m_poffset;
|
|
|
|
Elf64_Half m_repeat;
|
|
|
|
Elf64_Half m_stride;
|
|
|
|
} Elf64_Move;
|
|
|
|
|
2017-11-01 01:22:41 +01:00
|
|
|
typedef __u16 Elf32_Section;
|
|
|
|
typedef __u16 Elf64_Section;
|
|
|
|
|
2017-12-05 22:00:22 +01:00
|
|
|
typedef struct {
|
|
|
|
Elf32_Half si_boundto;
|
|
|
|
Elf32_Half si_flags;
|
|
|
|
} Elf32_Syminfo;
|
|
|
|
typedef struct {
|
|
|
|
Elf64_Half si_boundto;
|
|
|
|
Elf64_Half si_flags;
|
|
|
|
} Elf64_Syminfo;
|
|
|
|
|
2015-04-09 22:58:53 +02:00
|
|
|
typedef Elf32_Half Elf32_Versym;
|
|
|
|
typedef Elf64_Half Elf64_Versym;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Elf32_Half vd_version;
|
|
|
|
Elf32_Half vd_flags;
|
|
|
|
Elf32_Half vd_ndx;
|
|
|
|
Elf32_Half vd_cnt;
|
|
|
|
Elf32_Word vd_hash;
|
|
|
|
Elf32_Word vd_aux;
|
|
|
|
Elf32_Word vd_next;
|
|
|
|
} Elf32_Verdef;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Elf32_Word vda_name;
|
|
|
|
Elf32_Word vda_next;
|
|
|
|
} Elf32_Verdaux;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Elf64_Half vd_version;
|
|
|
|
Elf64_Half vd_flags;
|
|
|
|
Elf64_Half vd_ndx;
|
|
|
|
Elf64_Half vd_cnt;
|
|
|
|
Elf64_Word vd_hash;
|
|
|
|
Elf64_Word vd_aux;
|
|
|
|
Elf64_Word vd_next;
|
|
|
|
} Elf64_Verdef;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Elf64_Word vda_name;
|
|
|
|
Elf64_Word vda_next;
|
|
|
|
} Elf64_Verdaux;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Elf32_Half vn_version;
|
|
|
|
Elf32_Half vn_cnt;
|
|
|
|
Elf32_Word vn_file;
|
|
|
|
Elf32_Word vn_aux;
|
|
|
|
Elf32_Word vn_next;
|
|
|
|
} Elf32_Verneed;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Elf32_Word vna_hash;
|
|
|
|
Elf32_Half vna_flags;
|
|
|
|
Elf32_Half vna_other;
|
|
|
|
Elf32_Word vna_name;
|
|
|
|
Elf32_Word vna_next;
|
|
|
|
} Elf32_Vernaux;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Elf64_Half vn_version;
|
|
|
|
Elf64_Half vn_cnt;
|
|
|
|
Elf64_Word vn_file;
|
|
|
|
Elf64_Word vn_aux;
|
|
|
|
Elf64_Word vn_next;
|
|
|
|
} Elf64_Verneed;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Elf64_Word vna_hash;
|
|
|
|
Elf64_Half vna_flags;
|
|
|
|
Elf64_Half vna_other;
|
|
|
|
Elf64_Word vna_name;
|
|
|
|
Elf64_Word vna_next;
|
|
|
|
} Elf64_Vernaux;
|
|
|
|
|
2018-01-26 00:34:15 +01:00
|
|
|
/* Relocation table entry for relative (in section of type SHT_RELR). */
|
2017-12-20 00:25:23 +01:00
|
|
|
typedef Elf32_Word Elf32_Relr;
|
|
|
|
typedef Elf64_Xword Elf64_Relr;
|
|
|
|
|
2017-11-01 01:22:41 +01:00
|
|
|
/* http://www.sco.com/developers/gabi/latest/ch5.dynamic.html */
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2014-10-13 21:23:55 +02:00
|
|
|
#define DF_1_NOW 0x00000001 /* Perform complete relocation processing. */
|
2014-09-30 04:14:45 +02:00
|
|
|
#define DF_1_GROUP 0x00000004
|
|
|
|
#define DF_1_INITFIRST 0x00000020
|
|
|
|
#define DF_1_DIRECT 0x00000100
|
|
|
|
#define DF_1_TRANS 0x00000200
|
2014-10-13 21:23:55 +02:00
|
|
|
#define DF_1_NODUMP 0x00001000 /* Object cannot be dumped with dldump(3) */
|
2014-09-30 04:14:45 +02:00
|
|
|
#define DF_1_CONFALT 0x00002000
|
|
|
|
#define DF_1_ENDFILTEE 0x00004000
|
|
|
|
#define DF_1_DISPRELDNE 0x00008000
|
|
|
|
#define DF_1_DISPRELPND 0x00010000
|
|
|
|
#define DF_1_NODIRECT 0x00020000
|
2014-10-13 21:23:55 +02:00
|
|
|
#define DF_1_IGNMULDEF 0x00040000 /* Internal use */
|
|
|
|
#define DF_1_NOKSYMS 0x00080000 /* Internal use */
|
|
|
|
#define DF_1_NOHDR 0x00100000 /* Internal use */
|
2014-09-30 04:14:45 +02:00
|
|
|
#define DF_1_EDITED 0x00200000
|
2014-10-13 21:23:55 +02:00
|
|
|
#define DF_1_NORELOC 0x00400000 /* Internal use */
|
2014-09-30 04:14:45 +02:00
|
|
|
#define DF_1_SYMINTPOSE 0x00800000
|
|
|
|
#define DF_1_GLOBAUDIT 0x01000000
|
|
|
|
#define DF_1_SINGLETON 0x02000000
|
|
|
|
#define DF_1_STUB 0x04000000
|
2017-11-01 01:22:41 +01:00
|
|
|
|
|
|
|
/* http://www.sco.com/developers/gabi/latest/ch4.eheader.html */
|
|
|
|
#define ELFOSABI_SYSV 0 /* Synonym for ELFOSABI_NONE used by valgrind. */
|
|
|
|
#define ELFOSABI_GNU 3 /* Synonym for ELFOSABI_LINUX. */
|
|
|
|
|
|
|
|
/* http://www.sco.com/developers/gabi/latest/ch4.reloc.html */
|
|
|
|
#define ELF32_R_INFO(sym, type) ((((Elf32_Word)sym) << 8) | ((type) & 0xff))
|
|
|
|
#define ELF64_R_INFO(sym, type) ((((Elf64_Xword)sym) << 32) | ((type) & 0xffffffff))
|
2014-02-11 02:46:57 +01:00
|
|
|
|
2017-11-01 01:22:41 +01:00
|
|
|
/* http://www.sco.com/developers/gabi/latest/ch4.symtab.html */
|
2017-05-01 07:56:10 +02:00
|
|
|
#undef ELF_ST_TYPE
|
|
|
|
#define ELF_ST_TYPE(x) ((x) & 0xf)
|
|
|
|
#define ELF_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
|
|
|
|
#define ELF32_ST_INFO(b,t) ELF_ST_INFO(b,t)
|
|
|
|
#define ELF64_ST_INFO(b,t) ELF_ST_INFO(b,t)
|
|
|
|
|
2017-11-01 01:22:41 +01:00
|
|
|
/* http://www.sco.com/developers/gabi/latest/ch4.sheader.html */
|
|
|
|
#define GRP_MASKOS 0x0ff00000
|
|
|
|
#define GRP_MASKPROC 0xf0000000
|
|
|
|
|
|
|
|
/* http://www.sco.com/developers/gabi/latest/ch4.sheader.html */
|
2022-10-07 01:11:38 +02:00
|
|
|
/*
|
|
|
|
* Standard replacement for SHT_ANDROID_RELR.
|
|
|
|
*/
|
2020-01-24 23:36:10 +01:00
|
|
|
#define SHT_RELR 19
|
2017-11-01 01:22:41 +01:00
|
|
|
#undef SHT_NUM
|
2020-01-24 23:36:10 +01:00
|
|
|
#define SHT_NUM 20
|
2015-04-09 22:42:33 +02:00
|
|
|
|
2020-01-24 23:36:10 +01:00
|
|
|
/*
|
|
|
|
* Experimental support for SHT_RELR sections. For details, see proposal
|
|
|
|
* at https://groups.google.com/forum/#!topic/generic-abi/bX460iggiKg.
|
2020-01-28 01:00:19 +01:00
|
|
|
*
|
2020-01-24 23:36:10 +01:00
|
|
|
* This was eventually replaced by SHT_RELR and DT_RELR (which are identical
|
|
|
|
* other than their different constants), but those constants are only
|
2020-01-28 01:00:19 +01:00
|
|
|
* supported by the OS in API levels >= 30.
|
2020-01-24 23:36:10 +01:00
|
|
|
*/
|
|
|
|
#define SHT_ANDROID_RELR 0x6fffff00
|
|
|
|
#define DT_ANDROID_RELR 0x6fffe000
|
|
|
|
#define DT_ANDROID_RELRSZ 0x6fffe001
|
|
|
|
#define DT_ANDROID_RELRENT 0x6fffe003
|
|
|
|
#define DT_ANDROID_RELRCOUNT 0x6fffe005
|
2020-01-28 01:00:19 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Android compressed REL/RELA sections. These were generated by the relocation
|
|
|
|
* packer in old versions of Android, and can be generated directly by lld
|
|
|
|
* with https://reviews.llvm.org/D39152.
|
|
|
|
*
|
|
|
|
* This was replaced by SHT_ANDROID_RELR in API level 28 (but is supported
|
|
|
|
* in all API levels >= 23).
|
|
|
|
*/
|
|
|
|
#define SHT_ANDROID_REL 0x60000001
|
|
|
|
#define SHT_ANDROID_RELA 0x60000002
|
|
|
|
#define DT_ANDROID_REL 0x6000000f // DT_LOOS + 2
|
|
|
|
#define DT_ANDROID_RELSZ 0x60000010 // DT_LOOS + 3
|
|
|
|
#define DT_ANDROID_RELA 0x60000011 // DT_LOOS + 4
|
|
|
|
#define DT_ANDROID_RELASZ 0x60000012 // DT_LOOS + 5
|
2022-10-07 01:11:38 +02:00
|
|
|
|
|
|
|
/* Linux traditionally doesn't have the trailing 64 that BSD has on these. */
|
|
|
|
#define R_AARCH64_TLS_DTPREL R_AARCH64_TLS_DTPREL64
|
|
|
|
#define R_AARCH64_TLS_DTPMOD R_AARCH64_TLS_DTPMOD64
|
|
|
|
#define R_AARCH64_TLS_TPREL R_AARCH64_TLS_TPREL64
|
|
|
|
|
|
|
|
/* TODO: upstream these to FreeBSD? */
|
|
|
|
#define R_ARM_TLS_DESC 13
|
|
|
|
#define R_ARM_IRELATIVE 160
|
|
|
|
#define R_X86_64_JUMP_SLOT 7
|