blob: 5381a296a78c7f4c0df6f6eb85f946d84415d372 [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001#ifndef SOURCE_H
2#define SOURCE_H
3
4#include <sys/types.h>
5#include <sys/stat.h>
6#include <libelf.h>
7#include <libebl.h>
8#ifdef ARM_SPECIFIC_HACKS
9 #include <libebl_arm.h>
10#endif/*ARM_SPECIFIC_HACKS*/
11#include <elf.h>
12#include <gelf.h>
13#include <rangesort.h>
14#include <elfcopy.h>
15
16typedef struct source_t source_t;
17
18typedef struct {
19 Elf_Scn *scn;
20 GElf_Shdr shdr;
21 Elf_Data *data;
22 shdr_info_t *info;
23} section_info_t;
24
25typedef struct {
26 GElf_Rel *rels;
27 int num_rels; /* number of relocations that were not finished */
28 int rels_size; /* this is the size of rels[], NOT the number of rels! */
29} unfinished_relocation_t;
30
31typedef struct {
32 int processed;
33 size_t idx; /* index of DT entry in the .dynamic section, if entry has a ptr value */
34 Elf64_Addr addr; /* if DT entry's value is an address, we save it here */
35 size_t sz_idx; /* index of DT entry in the .dynamic section, if entry has a size value */
36 Elf64_Xword size; /* if DT entry's value is a size, we save it here */
37
38 range_list_t *sections; /* list of sections corresponding to this entry */
39 int num_unfinished_relocs; /* this variables is populated by adjust_dynamic_segment_for()
40 during the second pass of the prelinker */
41} dt_rel_info_t;
42
43struct source_t {
44 source_t *next;
45
46 char *name; /* full path name of this executable file */
47 char *output; /* name of the output file or directory */
48 int output_is_dir; /* nonzero if output is a directory, 0 if output is a file */
49 /* ELF-related information: */
50 Elf *oldelf;
51 Elf *elf;
52 /* info[] is an array of structures describing the sections of the new ELF
53 file. We populate the info[] array in clone_elf(), and use it to
54 adjust the size of the ELF file when we modify the relocation-entry
55 section.
56 */
57 shdr_info_t *shdr_info;
58 GElf_Ehdr old_ehdr_mem; /* store ELF header of original library */
59 GElf_Ehdr ehdr_mem; /* store ELF header of new library */
60 GElf_Phdr *phdr_info;
61 Ebl *ebl;
62 Elf_Data *shstrtab_data;
63 int elf_fd;
64 int newelf_fd; /* fd of output file, -1 if output == NULL */
Hristo Bojinov96be7202010-08-02 10:26:17 -070065 int newelf_relo_fd; /* fd of relocaion output file */
66 struct stat elf_file_info;
The Android Open Source Project88b60792009-03-03 19:28:42 -080067 GElf_Ehdr elf_hdr, oldelf_hdr;
68 size_t shstrndx;
69 int shnum; /* number of sections */
70 int dry_run; /* 0 if we do not update the files, 1 (default) otherwise */
71
72 section_info_t symtab;
73 section_info_t strtab;
74 section_info_t dynamic;
75 section_info_t hash;
76 section_info_t bss;
77
78 range_list_t *sorted_sections;
79
80 section_info_t *relocation_sections; /* relocation sections in file */
81 int num_relocation_sections; /* number of relocation sections (<= relocation_sections_size) */
82 int relocation_sections_size; /* sice of array -- NOT number of relocs! */
83
84 /* relocation sections that contain relocations that could not be handled.
85 This array is parallel to relocation_sections, and for each entry
86 in that array, it contains a list of relocations that could not be
87 handled.
88 */
89 unfinished_relocation_t *unfinished;
90
91 /* The sections field of these two structuer contains a list of elements
92 of the member variable relocations. */
93 dt_rel_info_t rel;
94 dt_rel_info_t jmprel;
95
96 int num_syms; /* number of symbols in symbol table. This is the length of
97 both exports[] and satisfied[] arrays. */
98
99 /* This is an array that contains one element for each library dependency
100 listed in the executable or shared library. */
101 source_t **lib_deps; /* list of library dependencies */
102 int num_lib_deps; /* actual number of library dependencies */
103 int lib_deps_size; /* size of lib_deps array--NOT actual number of deps! */
104
105 /* This is zero for executables. For shared libraries, it is the address
106 at which the library was prelinked. */
107 unsigned base;
108#ifdef SUPPORT_ANDROID_PRELINK_TAGS
109 /* When we read in a file, if it has the prelinked tag, we set prelinked
110 to 1 and the prelink address in the tag to prelink_base. This address
111 must match the value of base that we choose. */
112 int prelinked;
113 long prelink_base; /* valid if prelinked != 0 */
114#endif/*SUPPORT_ANDROID_PRELINK_TAGS*/
115};
116
117extern void find_section(source_t *source, Elf64_Addr address,
118 Elf_Scn **scn,
119 GElf_Shdr *shdr,
120 Elf_Data **data);
121
122#endif/*SOURCE_H*/