blob: 9107c21007cb7fe66fe0a499c552aa34741e5901 [file] [log] [blame]
Aaron Durbin54ef3062014-03-05 12:12:09 -06001/*
2 * Copyright (C) 2014 Google, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
16 */
17
18#ifndef ELFPARSING_H
19#define ELFPARSING_H
20
21#include "elf.h"
Aaron Durbinc3e6e142014-03-05 14:33:42 -060022#include "common.h"
Aaron Durbin54ef3062014-03-05 12:12:09 -060023
Aaron Durbind0f61652014-03-05 13:09:55 -060024struct parsed_elf {
25 Elf64_Ehdr ehdr;
26 Elf64_Phdr *phdr;
27 Elf64_Shdr *shdr;
Aaron Durbinccb5ad82014-03-05 13:57:30 -060028 /*
29 * The relocs array contains pointers to arrays of relocation
30 * structures. Each index into the relocs array corresponds to its
31 * corresponding section index. i.e. if a section i is of type SHT_REL
32 * or SHT_RELA then the corresponding index into the relocs array will
33 * contain the associated relocations. Otherwise thee entry will be
34 * NULL.
35 */
36 Elf64_Rela **relocs;
Aaron Durbinc3e6e142014-03-05 14:33:42 -060037 /*
38 * Similarly to the relocs array the strtabs array consists of an
39 * array of pointers where each entry represents a potential struct
40 * buffer pointer. Only setions of type SHT_STRTAB will have a non-NULL
41 * entry.
42 */
43 struct buffer **strtabs;
Aaron Durbind0f61652014-03-05 13:09:55 -060044};
45
46#define ELF_PARSE_PHDR (1 << 0)
47#define ELF_PARSE_SHDR (1 << 1)
Aaron Durbinccb5ad82014-03-05 13:57:30 -060048#define ELF_PARSE_RELOC (1 << 2)
Aaron Durbinc3e6e142014-03-05 14:33:42 -060049#define ELF_PARSE_STRTAB (1 << 3)
Aaron Durbind0f61652014-03-05 13:09:55 -060050
51#define ELF_PARSE_ALL (-1)
52
53/*
54 * Parse an ELF file contained within provide struct buffer. The ELF header
55 * is always parsed while the flags value containing the ELF_PARSE_* values
56 * determine if other parts of the ELF file will be parsed as well.
57 * Returns 0 on success, < 0 error.
58 */
59int parse_elf(const struct buffer *pinput, struct parsed_elf *pelf, int flags);
60
61/*
62 * Clean up memory associated with parsed_elf.
63 */
64void parsed_elf_destroy(struct parsed_elf *pelf);
65
66
Aaron Durbin54ef3062014-03-05 12:12:09 -060067int
68elf_headers(const struct buffer *pinput,
69 uint32_t arch,
70 Elf64_Ehdr *ehdr,
71 Elf64_Phdr **pphdr,
72 Elf64_Shdr **pshdr);
73
74#endif /* ELFPARSING_H */