]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - tools/objtool/include/objtool/elf.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com>
11 #include <linux/list.h>
12 #include <linux/hashtable.h>
13 #include <linux/rbtree.h>
14 #include <linux/jhash.h>
16 #ifdef LIBELF_USE_DEPRECATED
17 # define elf_getshdrnum elf_getshnum
18 # define elf_getshdrstrndx elf_getshstrndx
22 * Fallback for systems without this "read, mmaping if possible" cmd.
24 #ifndef ELF_C_READ_MMAP
25 #define ELF_C_READ_MMAP ELF_C_READ
29 struct list_head list
;
30 struct hlist_node hash
;
31 struct hlist_node name_hash
;
33 struct rb_root symbol_tree
;
34 struct list_head symbol_list
;
35 struct list_head reloc_list
;
36 struct section
*base
, *reloc
;
42 bool changed
, text
, rodata
, noinstr
;
46 struct list_head list
;
48 struct hlist_node hash
;
49 struct hlist_node name_hash
;
54 unsigned char bind
, type
;
57 struct symbol
*pfunc
, *cfunc
, *alias
;
59 bool static_call_tramp
;
63 struct list_head list
;
64 struct hlist_node hash
;
75 bool jump_table_start
;
78 #define ELF_HASH_BITS 20
86 unsigned int text_size
;
87 struct list_head sections
;
92 int section_name_bits
;
95 struct hlist_head
*symbol_hash
;
96 struct hlist_head
*symbol_name_hash
;
97 struct hlist_head
*section_hash
;
98 struct hlist_head
*section_name_hash
;
99 struct hlist_head
*reloc_hash
;
102 #define OFFSET_STRIDE_BITS 4
103 #define OFFSET_STRIDE (1UL << OFFSET_STRIDE_BITS)
104 #define OFFSET_STRIDE_MASK (~(OFFSET_STRIDE - 1))
106 #define for_offset_range(_offset, _start, _end) \
107 for (_offset = ((_start) & OFFSET_STRIDE_MASK); \
108 _offset >= ((_start) & OFFSET_STRIDE_MASK) && \
109 _offset <= ((_end) & OFFSET_STRIDE_MASK); \
110 _offset += OFFSET_STRIDE)
112 static inline u32
sec_offset_hash(struct section
*sec
, unsigned long offset
)
114 u32 ol
, oh
, idx
= sec
->idx
;
116 offset
&= OFFSET_STRIDE_MASK
;
119 oh
= (offset
>> 16) >> 16;
121 __jhash_mix(ol
, oh
, idx
);
126 static inline u32
reloc_hash(struct reloc
*reloc
)
128 return sec_offset_hash(reloc
->sec
, reloc
->offset
);
131 struct elf
*elf_open_read(const char *name
, int flags
);
132 struct section
*elf_create_section(struct elf
*elf
, const char *name
, unsigned int sh_flags
, size_t entsize
, int nr
);
134 int elf_add_reloc(struct elf
*elf
, struct section
*sec
, unsigned long offset
,
135 unsigned int type
, struct symbol
*sym
, int addend
);
136 int elf_add_reloc_to_insn(struct elf
*elf
, struct section
*sec
,
137 unsigned long offset
, unsigned int type
,
138 struct section
*insn_sec
, unsigned long insn_off
);
140 int elf_write_insn(struct elf
*elf
, struct section
*sec
,
141 unsigned long offset
, unsigned int len
,
143 int elf_write_reloc(struct elf
*elf
, struct reloc
*reloc
);
144 struct symbol
*elf_create_undef_symbol(struct elf
*elf
, const char *name
);
145 int elf_write(struct elf
*elf
);
146 void elf_close(struct elf
*elf
);
148 struct section
*find_section_by_name(const struct elf
*elf
, const char *name
);
149 struct symbol
*find_func_by_offset(struct section
*sec
, unsigned long offset
);
150 struct symbol
*find_symbol_by_offset(struct section
*sec
, unsigned long offset
);
151 struct symbol
*find_symbol_by_name(const struct elf
*elf
, const char *name
);
152 struct symbol
*find_symbol_containing(const struct section
*sec
, unsigned long offset
);
153 struct reloc
*find_reloc_by_dest(const struct elf
*elf
, struct section
*sec
, unsigned long offset
);
154 struct reloc
*find_reloc_by_dest_range(const struct elf
*elf
, struct section
*sec
,
155 unsigned long offset
, unsigned int len
);
156 struct symbol
*find_func_containing(struct section
*sec
, unsigned long offset
);
158 #define for_each_sec(file, sec) \
159 list_for_each_entry(sec, &file->elf->sections, list)
161 #endif /* _OBJTOOL_ELF_H */