1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 #ifndef _OBJTOOL_KLP_H 3 #define _OBJTOOL_KLP_H 4 5 #define SHF_RELA_LIVEPATCH 0x00100000 6 #define SHN_LIVEPATCH 0xff20 7 8 /* 9 * .init.klp_objects and .init.klp_funcs are created by klp diff and used by the 10 * patch module init code to build the klp_patch, klp_object and klp_func 11 * structs needed by the livepatch API. 12 */ 13 #define KLP_OBJECTS_SEC ".init.klp_objects" 14 #define KLP_FUNCS_SEC ".init.klp_funcs" 15 16 /* 17 * __klp_relocs.<objname> are intermediate sections which are created by klp 18 * diff and converted into KLP symbols/relas by "objtool klp post-link". This 19 * is needed to work around the linker, which doesn't preserve SHN_LIVEPATCH or 20 * SHF_RELA_LIVEPATCH, nor does it support having two RELA sections for a 21 * single PROGBITS section. 22 * 23 * "objname" is the object whose loading gates the relocation: "vmlinux" for 24 * references to vmlinux symbols, otherwise the name of the module being 25 * patched. post-link uses it to name the resulting 26 * .klp.rela.objname.section_name sections. 27 */ 28 #define KLP_RELOCS_SEC "__klp_relocs" 29 #define KLP_STRINGS_SEC ".rodata.klp.str1.1" 30 31 #define KLP_TOMBSTONE_PREFIX ".klp.tombstone." 32 33 struct klp_reloc { 34 void *offset; 35 void *sym; 36 u32 type; 37 }; 38 39 /* 40 * .klp.symid is used to correlate symbols between vmlinux.o and vmlinux, for 41 * calculating sympos to disambiguate duplicately-named symbols. 42 */ 43 #define KLP_SYMID_SEC ".klp.symid" 44 45 struct klp_symid { 46 u64 id; 47 u64 addr; 48 }; 49 50 struct objtool_file; 51 struct elf; 52 struct symbol; 53 54 int klp_create_symid_sections(struct objtool_file *file); 55 56 int klp_sympos_init(struct elf *orig); 57 unsigned long klp_find_sympos(struct elf *elf, struct symbol *sym); 58 59 int cmd_klp_checksum(int argc, const char **argv); 60 int cmd_klp_diff(int argc, const char **argv); 61 int cmd_klp_post_link(int argc, const char **argv); 62 63 #endif /* _OBJTOOL_KLP_H */ 64