Blame kpatch-build/kpatch-elf.h

Packit Service ac8aad
/*
Packit Service ac8aad
 * kpatch-elf.h
Packit Service ac8aad
 *
Packit Service ac8aad
 * This program is free software; you can redistribute it and/or
Packit Service ac8aad
 * modify it under the terms of the GNU General Public License
Packit Service ac8aad
 * as published by the Free Software Foundation; either version 2
Packit Service ac8aad
 * of the License, or (at your option) any later version.
Packit Service ac8aad
 *
Packit Service ac8aad
 * This program is distributed in the hope that it will be useful,
Packit Service ac8aad
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service ac8aad
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service ac8aad
 * GNU General Public License for more details.
Packit Service ac8aad
 *
Packit Service ac8aad
 * You should have received a copy of the GNU General Public License
Packit Service ac8aad
 * along with this program; if not, write to the Free Software
Packit Service ac8aad
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA,
Packit Service ac8aad
 * 02110-1301, USA.
Packit Service ac8aad
 */
Packit Service ac8aad
Packit Service ac8aad
#ifndef _KPATCH_ELF_H_
Packit Service ac8aad
#define _KPATCH_ELF_H_
Packit Service ac8aad
Packit Service ac8aad
#include <stdbool.h>
Packit Service ac8aad
#include <gelf.h>
Packit Service ac8aad
#include "list.h"
Packit Service ac8aad
#include "log.h"
Packit Service ac8aad
Packit Service ac8aad
#define KLP_SYM_PREFIX		".klp.sym."
Packit Service ac8aad
#define KLP_RELASEC_PREFIX	".klp.rela."
Packit Service ac8aad
#define KLP_ARCH_PREFIX 	".klp.arch."
Packit Service ac8aad
#define SHF_RELA_LIVEPATCH	0x00100000
Packit Service ac8aad
#define SHN_LIVEPATCH		0xff20
Packit Service ac8aad
Packit Service ac8aad
/*******************
Packit Service ac8aad
 * Data structures
Packit Service ac8aad
 * ****************/
Packit Service ac8aad
struct section;
Packit Service ac8aad
struct symbol;
Packit Service ac8aad
struct rela;
Packit Service ac8aad
Packit Service ac8aad
enum status {
Packit Service ac8aad
	NEW,
Packit Service ac8aad
	CHANGED,
Packit Service ac8aad
	SAME
Packit Service ac8aad
};
Packit Service ac8aad
Packit Service ac8aad
struct section {
Packit Service ac8aad
	struct list_head list;
Packit Service ac8aad
	struct section *twin;
Packit Service ac8aad
	GElf_Shdr sh;
Packit Service ac8aad
	Elf_Data *data;
Packit Service ac8aad
	char *name;
Packit Service ac8aad
	unsigned int index;
Packit Service ac8aad
	enum status status;
Packit Service ac8aad
	int include;
Packit Service ac8aad
	int ignore;
Packit Service ac8aad
	int grouped;
Packit Service ac8aad
	union {
Packit Service ac8aad
		struct { /* if (is_rela_section()) */
Packit Service ac8aad
			struct section *base;
Packit Service ac8aad
			struct list_head relas;
Packit Service ac8aad
		};
Packit Service ac8aad
		struct { /* else */
Packit Service ac8aad
			struct section *rela;
Packit Service ac8aad
			struct symbol *secsym, *sym;
Packit Service ac8aad
		};
Packit Service ac8aad
	};
Packit Service ac8aad
};
Packit Service ac8aad
Packit Service ac8aad
struct symbol {
Packit Service ac8aad
	struct list_head list;
Packit Service ac8aad
	struct symbol *twin;
Packit Service da4517
	struct symbol *parent;
Packit Service da4517
	struct list_head children;
Packit Service da4517
	struct list_head subfunction_node;
Packit Service ac8aad
	struct section *sec;
Packit Service ac8aad
	GElf_Sym sym;
Packit Service ac8aad
	char *name;
Packit Service ac8aad
	unsigned int index;
Packit Service ac8aad
	unsigned char bind, type;
Packit Service ac8aad
	enum status status;
Packit Service ac8aad
	union {
Packit Service ac8aad
		int include; /* used in the patched elf */
Packit Service ac8aad
		int strip; /* used in the output elf */
Packit Service ac8aad
	};
Packit Service ac8aad
	int has_func_profiling;
Packit Service ac8aad
};
Packit Service ac8aad
Packit Service ac8aad
struct rela {
Packit Service ac8aad
	struct list_head list;
Packit Service ac8aad
	GElf_Rela rela;
Packit Service ac8aad
	struct symbol *sym;
Packit Service ac8aad
	unsigned int type;
Packit Service ac8aad
	unsigned int offset;
Packit Service da4517
	long addend;
Packit Service ac8aad
	char *string;
Packit Service ac8aad
	bool need_dynrela;
Packit Service ac8aad
};
Packit Service ac8aad
Packit Service ac8aad
struct string {
Packit Service ac8aad
	struct list_head list;
Packit Service ac8aad
	char *name;
Packit Service ac8aad
};
Packit Service ac8aad
Packit Service ac8aad
struct kpatch_elf {
Packit Service ac8aad
	Elf *elf;
Packit Service ac8aad
	struct list_head sections;
Packit Service ac8aad
	struct list_head symbols;
Packit Service ac8aad
	struct list_head strings;
Packit Service ac8aad
	int fd;
Packit Service ac8aad
};
Packit Service ac8aad
Packit Service ac8aad
/*******************
Packit Service ac8aad
 * Helper functions
Packit Service ac8aad
 ******************/
Packit Service ac8aad
char *status_str(enum status status);
Packit Service ac8aad
int is_rela_section(struct section *sec);
Packit Service ac8aad
int is_text_section(struct section *sec);
Packit Service ac8aad
int is_debug_section(struct section *sec);
Packit Service ac8aad
Packit Service ac8aad
struct section *find_section_by_index(struct list_head *list, unsigned int index);
Packit Service ac8aad
struct section *find_section_by_name(struct list_head *list, const char *name);
Packit Service ac8aad
struct symbol *find_symbol_by_index(struct list_head *list, size_t index);
Packit Service ac8aad
struct symbol *find_symbol_by_name(struct list_head *list, const char *name);
Packit Service ac8aad
struct rela *find_rela_by_offset(struct section *relasec, unsigned int offset);
Packit Service ac8aad
Packit Service ac8aad
#define ALLOC_LINK(_new, _list) \
Packit Service ac8aad
{ \
Packit Service ac8aad
	(_new) = malloc(sizeof(*(_new))); \
Packit Service ac8aad
	if (!(_new)) \
Packit Service ac8aad
		ERROR("malloc"); \
Packit Service ac8aad
	memset((_new), 0, sizeof(*(_new))); \
Packit Service ac8aad
	INIT_LIST_HEAD(&(_new)->list); \
Packit Service ac8aad
	if (_list) \
Packit Service ac8aad
		list_add_tail(&(_new)->list, (_list)); \
Packit Service ac8aad
}
Packit Service ac8aad
Packit Service ac8aad
int offset_of_string(struct list_head *list, char *name);
Packit Service ac8aad
Packit Service ac8aad
#ifndef R_PPC64_ENTRY
Packit Service ac8aad
#define R_PPC64_ENTRY   118
Packit Service ac8aad
#endif
Packit Service ac8aad
Packit Service ac8aad
/*************
Packit Service ac8aad
 * Functions
Packit Service ac8aad
 * **********/
Packit Service ac8aad
void kpatch_create_rela_list(struct kpatch_elf *kelf, struct section *sec);
Packit Service ac8aad
void kpatch_create_section_list(struct kpatch_elf *kelf);
Packit Service ac8aad
void kpatch_create_symbol_list(struct kpatch_elf *kelf);
Packit Service ac8aad
struct kpatch_elf *kpatch_elf_open(const char *name);
Packit Service ac8aad
void kpatch_dump_kelf(struct kpatch_elf *kelf);
Packit Service ac8aad
Packit Service ac8aad
int is_null_sym(struct symbol *sym);
Packit Service ac8aad
int is_file_sym(struct symbol *sym);
Packit Service ac8aad
int is_local_func_sym(struct symbol *sym);
Packit Service ac8aad
int is_local_sym(struct symbol *sym);
Packit Service ac8aad
Packit Service ac8aad
void print_strtab(char *buf, size_t size);
Packit Service ac8aad
void kpatch_create_shstrtab(struct kpatch_elf *kelf);
Packit Service ac8aad
void kpatch_create_strtab(struct kpatch_elf *kelf);
Packit Service ac8aad
void kpatch_create_symtab(struct kpatch_elf *kelf);
Packit Service ac8aad
struct section *create_section_pair(struct kpatch_elf *kelf, char *name,
Packit Service ac8aad
                                    int entsize, int nr);
Packit Service ac8aad
void kpatch_remove_and_free_section(struct kpatch_elf *kelf, char *secname);
Packit Service ac8aad
void kpatch_reindex_elements(struct kpatch_elf *kelf);
Packit Service ac8aad
void kpatch_rebuild_rela_section_data(struct section *sec);
Packit Service ac8aad
void kpatch_write_output_elf(struct kpatch_elf *kelf, Elf *elf, char *outfile);
Packit Service ac8aad
void kpatch_elf_teardown(struct kpatch_elf *kelf);
Packit Service ac8aad
void kpatch_elf_free(struct kpatch_elf *kelf);
Packit Service ac8aad
#endif /* _KPATCH_ELF_H_ */