blob: a5d96bd2f6f1c0f324664a73bbf894662e6d4645 [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 */
65 struct stat elf_file_info;
66 GElf_Ehdr elf_hdr, oldelf_hdr;
67 size_t shstrndx;
68 int shnum; /* number of sections */
69 int dry_run; /* 0 if we do not update the files, 1 (default) otherwise */
70
71 section_info_t symtab;
72 section_info_t strtab;
73 section_info_t dynamic;
74 section_info_t hash;
75 section_info_t bss;
76
77 range_list_t *sorted_sections;
78
79 section_info_t *relocation_sections; /* relocation sections in file */
80 int num_relocation_sections; /* number of relocation sections (<= relocation_sections_size) */
81 int relocation_sections_size; /* sice of array -- NOT number of relocs! */
82
83 /* relocation sections that contain relocations that could not be handled.
84 This array is parallel to relocation_sections, and for each entry
85 in that array, it contains a list of relocations that could not be
86 handled.
87 */
88 unfinished_relocation_t *unfinished;
89
90 /* The sections field of these two structuer contains a list of elements
91 of the member variable relocations. */
92 dt_rel_info_t rel;
93 dt_rel_info_t jmprel;
94
95 int num_syms; /* number of symbols in symbol table. This is the length of
96 both exports[] and satisfied[] arrays. */
97
98 /* This is an array that contains one element for each library dependency
99 listed in the executable or shared library. */
100 source_t **lib_deps; /* list of library dependencies */
101 int num_lib_deps; /* actual number of library dependencies */
102 int lib_deps_size; /* size of lib_deps array--NOT actual number of deps! */
103
104 /* This is zero for executables. For shared libraries, it is the address
105 at which the library was prelinked. */
106 unsigned base;
107#ifdef SUPPORT_ANDROID_PRELINK_TAGS
108 /* When we read in a file, if it has the prelinked tag, we set prelinked
109 to 1 and the prelink address in the tag to prelink_base. This address
110 must match the value of base that we choose. */
111 int prelinked;
112 long prelink_base; /* valid if prelinked != 0 */
113#endif/*SUPPORT_ANDROID_PRELINK_TAGS*/
114};
115
116extern void find_section(source_t *source, Elf64_Addr address,
117 Elf_Scn **scn,
118 GElf_Shdr *shdr,
119 Elf_Data **data);
120
121#endif/*SOURCE_H*/