From: Jiri Slaby Subject: ppc64: .opd section fix Patch-mainline: submitted 2021/05/03 Functions in the .opd section should be considered valid too. Otherwise, pahole cannot produce a .BTF section from vmlinux and kernel build fails on ppc64. --- btf_encoder.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) --- a/btf_encoder.c +++ b/btf_encoder.c @@ -31,6 +31,8 @@ struct funcs_layout { unsigned long mcount_start; unsigned long mcount_stop; unsigned long mcount_sec_idx; + unsigned long opd_start; + unsigned long opd_stop; }; struct elf_function { @@ -271,11 +273,24 @@ static int is_ftrace_func(struct elf_fun return start <= addrs[r] && addrs[r] < end; } +static int is_opd_func(struct elf_function *func, struct funcs_layout *fl) +{ + return fl->opd_start <= func->addr && func->addr < fl->opd_stop; +} + static int setup_functions(struct btf_elf *btfe, struct funcs_layout *fl) { __u64 *addrs, count, i; int functions_valid = 0; bool kmod = false; + GElf_Shdr shdr; + Elf_Scn *sec; + + sec = elf_section_by_name(btfe->elf, &btfe->ehdr, &shdr, ".opd", NULL); + if (sec) { + fl->opd_start = shdr.sh_addr; + fl->opd_stop = shdr.sh_addr + shdr.sh_size; + } /* * Check if we are processing vmlinux image and @@ -322,7 +337,8 @@ static int setup_functions(struct btf_el func->addr += func->sh_addr; /* Make sure function is within ftrace addresses. */ - if (is_ftrace_func(func, addrs, count)) { + if (is_opd_func(func, fl) || + is_ftrace_func(func, addrs, count)) { /* * We iterate over sorted array, so we can easily skip * not valid item and move following valid field into