summaryrefslogtreecommitdiff
path: root/tools/objtool/include/objtool/klp.h
blob: c57775d78c71e445b4be450fe292cbb985264bee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef _OBJTOOL_KLP_H
#define _OBJTOOL_KLP_H

#define SHF_RELA_LIVEPATCH	0x00100000
#define SHN_LIVEPATCH		0xff20

/*
 * .init.klp_objects and .init.klp_funcs are created by klp diff and used by the
 * patch module init code to build the klp_patch, klp_object and klp_func
 * structs needed by the livepatch API.
 */
#define KLP_OBJECTS_SEC	".init.klp_objects"
#define KLP_FUNCS_SEC	".init.klp_funcs"

/*
 * __klp_relocs.<objname> are intermediate sections which are created by klp
 * diff and converted into KLP symbols/relas by "objtool klp post-link".  This
 * is needed to work around the linker, which doesn't preserve SHN_LIVEPATCH or
 * SHF_RELA_LIVEPATCH, nor does it support having two RELA sections for a
 * single PROGBITS section.
 *
 * "objname" is the object whose loading gates the relocation: "vmlinux" for
 * references to vmlinux symbols, otherwise the name of the module being
 * patched.  post-link uses it to name the resulting
 * .klp.rela.objname.section_name sections.
 */
#define KLP_RELOCS_SEC	"__klp_relocs"
#define KLP_STRINGS_SEC	".rodata.klp.str1.1"

#define KLP_TOMBSTONE_PREFIX	".klp.tombstone."

struct klp_reloc {
	void *offset;
	void *sym;
	u32 type;
};

/*
 * .klp.symid is used to correlate symbols between vmlinux.o and vmlinux, for
 * calculating sympos to disambiguate duplicately-named symbols.
 */
#define KLP_SYMID_SEC	".klp.symid"

struct klp_symid {
	u64 id;
	u64 addr;
};

struct objtool_file;
struct elf;
struct symbol;

int klp_create_symid_sections(struct objtool_file *file);

int klp_sympos_init(struct elf *orig);
unsigned long klp_find_sympos(struct elf *elf, struct symbol *sym);

int cmd_klp_checksum(int argc, const char **argv);
int cmd_klp_diff(int argc, const char **argv);
int cmd_klp_post_link(int argc, const char **argv);

#endif /* _OBJTOOL_KLP_H */