Commit 9290e772 authored by Josh Poimboeuf's avatar Josh Poimboeuf Committed by Peter Zijlstra
Browse files

objtool: Add symbol iteration helpers

parent 246b2c85
Loading
Loading
Loading
Loading
+41 −57
Original line number Diff line number Diff line
@@ -470,7 +470,7 @@ static int decode_instructions(struct objtool_file *file)

//		printf("%s: last chunk used: %d\n", sec->name, (int)idx);

		list_for_each_entry(func, &sec->symbol_list, list) {
		sec_for_each_sym(sec, func) {
			if (func->type != STT_NOTYPE && func->type != STT_FUNC)
				continue;

@@ -924,7 +924,7 @@ static int create_ibt_endbr_seal_sections(struct objtool_file *file)

static int create_cfi_sections(struct objtool_file *file)
{
	struct section *sec, *s;
	struct section *sec;
	struct symbol *sym;
	unsigned int *loc;
	int idx;
@@ -937,11 +937,7 @@ static int create_cfi_sections(struct objtool_file *file)
	}

	idx = 0;
	for_each_sec(file, s) {
		if (!s->text)
			continue;

		list_for_each_entry(sym, &s->symbol_list, list) {
	for_each_sym(file, sym) {
		if (sym->type != STT_FUNC)
			continue;

@@ -950,18 +946,13 @@ static int create_cfi_sections(struct objtool_file *file)

		idx++;
	}
	}

	sec = elf_create_section(file->elf, ".cfi_sites", 0, sizeof(unsigned int), idx);
	if (!sec)
		return -1;

	idx = 0;
	for_each_sec(file, s) {
		if (!s->text)
			continue;

		list_for_each_entry(sym, &s->symbol_list, list) {
	for_each_sym(file, sym) {
		if (sym->type != STT_FUNC)
			continue;

@@ -974,12 +965,11 @@ static int create_cfi_sections(struct objtool_file *file)
		if (elf_add_reloc_to_insn(file->elf, sec,
					  idx * sizeof(unsigned int),
					  R_X86_64_PC32,
						  s, sym->offset))
					  sym->sec, sym->offset))
			return -1;

		idx++;
	}
	}

	return 0;
}
@@ -2207,15 +2197,13 @@ static int add_func_jump_tables(struct objtool_file *file,
 */
static int add_jump_table_alts(struct objtool_file *file)
{
	struct section *sec;
	struct symbol *func;
	int ret;

	if (!file->rodata)
		return 0;

	for_each_sec(file, sec) {
		list_for_each_entry(func, &sec->symbol_list, list) {
	for_each_sym(file, func) {
		if (func->type != STT_FUNC)
			continue;

@@ -2224,7 +2212,6 @@ static int add_jump_table_alts(struct objtool_file *file)
		if (ret)
			return ret;
	}
	}

	return 0;
}
@@ -2535,11 +2522,9 @@ static bool is_profiling_func(const char *name)

static int classify_symbols(struct objtool_file *file)
{
	struct section *sec;
	struct symbol *func;

	for_each_sec(file, sec) {
		list_for_each_entry(func, &sec->symbol_list, list) {
	for_each_sym(file, func) {
		if (func->bind != STB_GLOBAL)
			continue;

@@ -2559,7 +2544,6 @@ static int classify_symbols(struct objtool_file *file)
		if (is_profiling_func(func->name))
			func->profiling_func = true;
	}
	}

	return 0;
}
@@ -4213,7 +4197,7 @@ static int validate_section(struct objtool_file *file, struct section *sec)
	struct symbol *func;
	int warnings = 0;

	list_for_each_entry(func, &sec->symbol_list, list) {
	sec_for_each_sym(sec, func) {
		if (func->type != STT_FUNC)
			continue;

+1 −1
Original line number Diff line number Diff line
@@ -474,7 +474,7 @@ static int read_symbols(struct elf *elf)

	/* Create parent/child links for any cold subfunctions */
	list_for_each_entry(sec, &elf->sections, list) {
		list_for_each_entry(sym, &sec->symbol_list, list) {
		sec_for_each_sym(sec, sym) {
			char pname[MAX_NAME_LEN + 1];
			size_t pnamelen;
			if (sym->type != STT_FUNC)
+9 −0
Original line number Diff line number Diff line
@@ -188,4 +188,13 @@ struct symbol *find_func_containing(struct section *sec, unsigned long offset);
#define for_each_sec(file, sec)						\
	list_for_each_entry(sec, &file->elf->sections, list)

#define sec_for_each_sym(sec, sym)					\
	list_for_each_entry(sym, &sec->symbol_list, list)

#define for_each_sym(file, sym)						\
	for (struct section *__sec, *__fake = (struct section *)1;	\
	     __fake; __fake = NULL)					\
		for_each_sec(file, __sec)				\
			sec_for_each_sym(__sec, sym)

#endif /* _OBJTOOL_ELF_H */