Blame view

tools/objtool/elf.h 2.43 KB
1ccea77e2   Thomas Gleixner   treewide: Replace...
1
  /* SPDX-License-Identifier: GPL-2.0-or-later */
442f04c34   Josh Poimboeuf   objtool: Add tool...
2
3
  /*
   * Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com>
442f04c34   Josh Poimboeuf   objtool: Add tool...
4
5
6
7
8
9
10
11
   */
  
  #ifndef _OBJTOOL_ELF_H
  #define _OBJTOOL_ELF_H
  
  #include <stdio.h>
  #include <gelf.h>
  #include <linux/list.h>
042ba73fe   Josh Poimboeuf   objtool: Add seve...
12
  #include <linux/hashtable.h>
442f04c34   Josh Poimboeuf   objtool: Add tool...
13

2e51f2624   Jan Beulich   objtool: Allow bu...
14
15
16
17
  #ifdef LIBELF_USE_DEPRECATED
  # define elf_getshdrnum    elf_getshnum
  # define elf_getshdrstrndx elf_getshstrndx
  #endif
627fce148   Josh Poimboeuf   objtool: Add ORC ...
18
19
20
21
22
23
  /*
   * Fallback for systems without this "read, mmaping if possible" cmd.
   */
  #ifndef ELF_C_READ_MMAP
  #define ELF_C_READ_MMAP ELF_C_READ
  #endif
442f04c34   Josh Poimboeuf   objtool: Add tool...
24
25
26
  struct section {
  	struct list_head list;
  	GElf_Shdr sh;
a196e1719   Josh Poimboeuf   objtool: Rename s...
27
  	struct list_head symbol_list;
042ba73fe   Josh Poimboeuf   objtool: Add seve...
28
  	DECLARE_HASHTABLE(symbol_hash, 8);
a196e1719   Josh Poimboeuf   objtool: Rename s...
29
  	struct list_head rela_list;
042ba73fe   Josh Poimboeuf   objtool: Add seve...
30
  	DECLARE_HASHTABLE(rela_hash, 16);
442f04c34   Josh Poimboeuf   objtool: Add tool...
31
32
  	struct section *base, *rela;
  	struct symbol *sym;
baa41469a   Josh Poimboeuf   objtool: Implemen...
33
  	Elf_Data *data;
442f04c34   Josh Poimboeuf   objtool: Add tool...
34
35
  	char *name;
  	int idx;
442f04c34   Josh Poimboeuf   objtool: Add tool...
36
  	unsigned int len;
4a60aa05a   Allan Xavier   objtool: Support ...
37
  	bool changed, text, rodata;
442f04c34   Josh Poimboeuf   objtool: Add tool...
38
39
40
41
  };
  
  struct symbol {
  	struct list_head list;
042ba73fe   Josh Poimboeuf   objtool: Add seve...
42
  	struct hlist_node hash;
442f04c34   Josh Poimboeuf   objtool: Add tool...
43
44
45
  	GElf_Sym sym;
  	struct section *sec;
  	char *name;
042ba73fe   Josh Poimboeuf   objtool: Add seve...
46
  	unsigned int idx;
442f04c34   Josh Poimboeuf   objtool: Add tool...
47
48
49
  	unsigned char bind, type;
  	unsigned long offset;
  	unsigned int len;
09f30d83d   Peter Zijlstra   objtool: Handle f...
50
  	struct symbol *pfunc, *cfunc, *alias;
ea24213d8   Peter Zijlstra   objtool: Add UACC...
51
  	bool uaccess_safe;
442f04c34   Josh Poimboeuf   objtool: Add tool...
52
53
54
55
  };
  
  struct rela {
  	struct list_head list;
042ba73fe   Josh Poimboeuf   objtool: Add seve...
56
  	struct hlist_node hash;
442f04c34   Josh Poimboeuf   objtool: Add tool...
57
  	GElf_Rela rela;
e7c2bc37b   Josh Poimboeuf   objtool: Refactor...
58
  	struct section *sec;
442f04c34   Josh Poimboeuf   objtool: Add tool...
59
60
  	struct symbol *sym;
  	unsigned int type;
042ba73fe   Josh Poimboeuf   objtool: Add seve...
61
  	unsigned long offset;
442f04c34   Josh Poimboeuf   objtool: Add tool...
62
  	int addend;
bd98c8134   Jann Horn   objtool: Support ...
63
  	bool jump_table_start;
442f04c34   Josh Poimboeuf   objtool: Add tool...
64
65
66
67
68
69
70
71
  };
  
  struct elf {
  	Elf *elf;
  	GElf_Ehdr ehdr;
  	int fd;
  	char *name;
  	struct list_head sections;
042ba73fe   Josh Poimboeuf   objtool: Add seve...
72
  	DECLARE_HASHTABLE(rela_hash, 16);
442f04c34   Josh Poimboeuf   objtool: Add tool...
73
  };
8e144797f   Michael Forney   objtool: Rename e...
74
  struct elf *elf_read(const char *name, int flags);
442f04c34   Josh Poimboeuf   objtool: Add tool...
75
76
  struct section *find_section_by_name(struct elf *elf, const char *name);
  struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset);
13810435b   Josh Poimboeuf   objtool: Support ...
77
  struct symbol *find_symbol_by_name(struct elf *elf, const char *name);
5c51f4ae8   Josh Poimboeuf   objtool: Fix anot...
78
  struct symbol *find_symbol_containing(struct section *sec, unsigned long offset);
442f04c34   Josh Poimboeuf   objtool: Add tool...
79
80
81
82
  struct rela *find_rela_by_dest(struct section *sec, unsigned long offset);
  struct rela *find_rela_by_dest_range(struct section *sec, unsigned long offset,
  				     unsigned int len);
  struct symbol *find_containing_func(struct section *sec, unsigned long offset);
627fce148   Josh Poimboeuf   objtool: Add ORC ...
83
84
85
86
87
  struct section *elf_create_section(struct elf *elf, const char *name, size_t
  				   entsize, int nr);
  struct section *elf_create_rela_section(struct elf *elf, struct section *base);
  int elf_rebuild_rela_section(struct section *sec);
  int elf_write(struct elf *elf);
442f04c34   Josh Poimboeuf   objtool: Add tool...
88
  void elf_close(struct elf *elf);
baa41469a   Josh Poimboeuf   objtool: Implemen...
89
90
  #define for_each_sec(file, sec)						\
  	list_for_each_entry(sec, &file->elf->sections, list)
442f04c34   Josh Poimboeuf   objtool: Add tool...
91
92
  
  #endif /* _OBJTOOL_ELF_H */