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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINKER_H_
|
|
|
|
#define _LINKER_H_
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
2012-02-28 19:40:00 +01:00
|
|
|
#include <elf.h>
|
|
|
|
#include <sys/exec_elf.h>
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2012-08-04 01:49:39 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2012-08-17 10:53:29 +02:00
|
|
|
#include <link.h>
|
2012-08-04 01:49:39 +02:00
|
|
|
|
2009-03-04 04:28:35 +01:00
|
|
|
#undef PAGE_MASK
|
|
|
|
#undef PAGE_SIZE
|
|
|
|
#define PAGE_SIZE 4096
|
2012-06-19 11:21:29 +02:00
|
|
|
#define PAGE_MASK (PAGE_SIZE-1)
|
|
|
|
|
|
|
|
/* Convenience macros to make page address/offset computations more explicit */
|
|
|
|
|
|
|
|
/* Returns the address of the page starting at address 'x' */
|
|
|
|
#define PAGE_START(x) ((x) & ~PAGE_MASK)
|
|
|
|
|
|
|
|
/* Returns the offset of address 'x' in its memory page, i.e. this is the
|
|
|
|
* same than 'x' - PAGE_START(x) */
|
|
|
|
#define PAGE_OFFSET(x) ((x) & PAGE_MASK)
|
|
|
|
|
|
|
|
/* Returns the address of the next page after address 'x', unless 'x' is
|
|
|
|
* itself at the start of a page. Equivalent to:
|
|
|
|
*
|
|
|
|
* (x == PAGE_START(x)) ? x : PAGE_START(x)+PAGE_SIZE
|
|
|
|
*/
|
|
|
|
#define PAGE_END(x) PAGE_START((x) + (PAGE_SIZE-1))
|
2009-03-04 04:28:35 +01:00
|
|
|
|
|
|
|
void debugger_init();
|
|
|
|
|
|
|
|
/* magic shared structures that GDB knows about */
|
|
|
|
|
|
|
|
struct link_map
|
|
|
|
{
|
|
|
|
uintptr_t l_addr;
|
|
|
|
char * l_name;
|
|
|
|
uintptr_t l_ld;
|
|
|
|
struct link_map * l_next;
|
|
|
|
struct link_map * l_prev;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Values for r_debug->state
|
|
|
|
enum {
|
|
|
|
RT_CONSISTENT,
|
|
|
|
RT_ADD,
|
|
|
|
RT_DELETE
|
|
|
|
};
|
|
|
|
|
|
|
|
struct r_debug
|
|
|
|
{
|
|
|
|
int32_t r_version;
|
|
|
|
struct link_map * r_map;
|
|
|
|
void (*r_brk)(void);
|
|
|
|
int32_t r_state;
|
|
|
|
uintptr_t r_ldbase;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct soinfo soinfo;
|
|
|
|
|
|
|
|
#define FLAG_LINKED 0x00000001
|
|
|
|
#define FLAG_ERROR 0x00000002
|
|
|
|
#define FLAG_EXE 0x00000004 // The main executable
|
2011-11-12 00:53:17 +01:00
|
|
|
#define FLAG_LINKER 0x00000010 // The linker itself
|
2009-03-04 04:28:35 +01:00
|
|
|
|
|
|
|
#define SOINFO_NAME_LEN 128
|
|
|
|
|
|
|
|
struct soinfo
|
|
|
|
{
|
2012-08-04 01:49:39 +02:00
|
|
|
char name[SOINFO_NAME_LEN];
|
2012-06-19 01:24:17 +02:00
|
|
|
const Elf32_Phdr *phdr;
|
2009-03-04 04:28:35 +01:00
|
|
|
int phnum;
|
|
|
|
unsigned entry;
|
|
|
|
unsigned base;
|
|
|
|
unsigned size;
|
|
|
|
|
2011-08-29 22:49:22 +02:00
|
|
|
int unused; // DO NOT USE, maintained for compatibility.
|
|
|
|
|
2009-03-04 04:28:35 +01:00
|
|
|
unsigned *dynamic;
|
|
|
|
|
2012-06-19 01:24:17 +02:00
|
|
|
unsigned unused2; // DO NOT USE, maintained for compatibility
|
|
|
|
unsigned unused3; // DO NOT USE, maintained for compatibility
|
2009-03-04 04:28:35 +01:00
|
|
|
|
|
|
|
soinfo *next;
|
|
|
|
unsigned flags;
|
|
|
|
|
|
|
|
const char *strtab;
|
|
|
|
Elf32_Sym *symtab;
|
|
|
|
|
|
|
|
unsigned nbucket;
|
|
|
|
unsigned nchain;
|
|
|
|
unsigned *bucket;
|
|
|
|
unsigned *chain;
|
|
|
|
|
|
|
|
unsigned *plt_got;
|
|
|
|
|
|
|
|
Elf32_Rel *plt_rel;
|
|
|
|
unsigned plt_rel_count;
|
|
|
|
|
|
|
|
Elf32_Rel *rel;
|
|
|
|
unsigned rel_count;
|
|
|
|
|
|
|
|
unsigned *preinit_array;
|
|
|
|
unsigned preinit_array_count;
|
|
|
|
|
|
|
|
unsigned *init_array;
|
|
|
|
unsigned init_array_count;
|
|
|
|
unsigned *fini_array;
|
|
|
|
unsigned fini_array_count;
|
|
|
|
|
|
|
|
void (*init_func)(void);
|
|
|
|
void (*fini_func)(void);
|
|
|
|
|
2012-07-31 21:07:22 +02:00
|
|
|
#if defined(ANDROID_ARM_LINKER)
|
2009-03-04 04:28:35 +01:00
|
|
|
/* ARM EABI section used for stack unwinding. */
|
|
|
|
unsigned *ARM_exidx;
|
|
|
|
unsigned ARM_exidx_count;
|
2012-07-31 21:07:22 +02:00
|
|
|
#elif defined(ANDROID_MIPS_LINKER)
|
|
|
|
#if 0
|
|
|
|
/* not yet */
|
|
|
|
unsigned *mips_pltgot
|
2009-03-04 04:28:35 +01:00
|
|
|
#endif
|
2012-07-31 21:07:22 +02:00
|
|
|
unsigned mips_symtabno;
|
|
|
|
unsigned mips_local_gotno;
|
|
|
|
unsigned mips_gotsym;
|
|
|
|
#endif /* ANDROID_*_LINKER */
|
2009-03-04 04:28:35 +01:00
|
|
|
|
|
|
|
unsigned refcount;
|
|
|
|
struct link_map linkmap;
|
2011-12-21 10:03:54 +01:00
|
|
|
|
|
|
|
int constructors_called;
|
2012-02-28 19:40:00 +01:00
|
|
|
|
2012-06-18 23:38:46 +02:00
|
|
|
/* When you read a virtual address from the ELF file, add this
|
|
|
|
* value to get the corresponding address in the process' address space */
|
|
|
|
Elf32_Addr load_bias;
|
2012-08-11 06:08:42 +02:00
|
|
|
int has_text_relocations;
|
2009-03-04 04:28:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
extern soinfo libdl_info;
|
|
|
|
|
|
|
|
|
2012-07-31 21:07:22 +02:00
|
|
|
#include <asm/elf.h>
|
|
|
|
|
|
|
|
#if defined(ANDROID_ARM_LINKER)
|
|
|
|
|
|
|
|
// These aren't defined in <arch-arm/asm/elf.h>.
|
|
|
|
#define R_ARM_REL32 3
|
2009-03-04 04:28:35 +01:00
|
|
|
#define R_ARM_COPY 20
|
|
|
|
#define R_ARM_GLOB_DAT 21
|
|
|
|
#define R_ARM_JUMP_SLOT 22
|
|
|
|
#define R_ARM_RELATIVE 23
|
|
|
|
|
2012-07-31 21:07:22 +02:00
|
|
|
#elif defined(ANDROID_MIPS_LINKER)
|
|
|
|
|
|
|
|
// These aren't defined in <arch-arm/mips/elf.h>.
|
|
|
|
#define R_MIPS_JUMP_SLOT 127
|
|
|
|
|
|
|
|
#define DT_MIPS_PLTGOT 0x70000032
|
|
|
|
#define DT_MIPS_RWPLT 0x70000034
|
2009-12-02 19:54:53 +01:00
|
|
|
|
2009-03-04 04:28:35 +01:00
|
|
|
#elif defined(ANDROID_X86_LINKER)
|
|
|
|
|
2012-07-31 21:07:22 +02:00
|
|
|
// x86 has everything it needs in <arch-arm/x86/elf.h>.
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2012-07-31 21:07:22 +02:00
|
|
|
#endif /* ANDROID_*_LINKER */
|
2009-03-04 04:28:35 +01:00
|
|
|
|
|
|
|
#ifndef DT_INIT_ARRAY
|
|
|
|
#define DT_INIT_ARRAY 25
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DT_FINI_ARRAY
|
|
|
|
#define DT_FINI_ARRAY 26
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DT_INIT_ARRAYSZ
|
|
|
|
#define DT_INIT_ARRAYSZ 27
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DT_FINI_ARRAYSZ
|
|
|
|
#define DT_FINI_ARRAYSZ 28
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DT_PREINIT_ARRAY
|
|
|
|
#define DT_PREINIT_ARRAY 32
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DT_PREINIT_ARRAYSZ
|
|
|
|
#define DT_PREINIT_ARRAYSZ 33
|
|
|
|
#endif
|
|
|
|
|
|
|
|
soinfo *find_library(const char *name);
|
2009-12-31 19:17:56 +01:00
|
|
|
Elf32_Sym *lookup(const char *name, soinfo **found, soinfo *start);
|
2011-09-28 07:30:19 +02:00
|
|
|
soinfo *find_containing_library(const void *addr);
|
2009-05-21 03:28:09 +02:00
|
|
|
const char *linker_get_error(void);
|
2012-06-12 16:25:37 +02:00
|
|
|
|
2012-08-14 23:07:59 +02:00
|
|
|
int soinfo_unload(soinfo* si);
|
2012-06-12 16:25:37 +02:00
|
|
|
Elf32_Sym *soinfo_find_symbol(soinfo* si, const void *addr);
|
|
|
|
Elf32_Sym *soinfo_lookup(soinfo *si, const char *name);
|
|
|
|
void soinfo_call_constructors(soinfo *si);
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2012-08-04 01:49:39 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2009-03-04 04:28:35 +01:00
|
|
|
#endif
|