When vmlinux is linked, the rodata from kallsyms is placed arbitrarily within the .rodata section. The linking process is repeated several times, since the kallsyms data size changes, which shifts symbols, requiring re-generating the data and re-linking. BTF is generated during the first link only. For variables, BTF includes a BTF_K_DATASEC for each data section that may contain a variable, which includes the variable's name, type, and offset within the data section. Because the size of kallsyms data changes during later links, the offsets of variables placed after it in .rodata will change. This means that BTF_K_DATASEC information for those variables becomes inaccurate. This is not currently a problem, because BTF currently only generates variable data for percpu variables. However, the next commit will add support for generating BTF for all global variables, including for the .rodata section. We could re-generate BTF each time vmlinux is linked, but this is quite expensive, and should be avoided at all costs. Further as each chunk of data (BTF and kallsyms) are re-generated, there's no guarantee that their sizes will converge anyway. Instead, we can take advantage of the fact that BTF only cares to store the offset of variables from the start of their section. Therefore, so long as the kallsyms data is stored last in the .rodata section, no offsets will be affected. Adjust kallsyms to output to .rodata.kallsyms, and update the linker script to include this at the end of .rodata. Signed-off-by: Stephen Brennan <stephen.s.brennan@xxxxxxxxxx> --- include/asm-generic/vmlinux.lds.h | 1 + scripts/kallsyms.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 54504013c7491..9284f0e502e27 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -463,6 +463,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG) . = ALIGN(8); \ BOUNDED_SECTION_BY(__tracepoints_ptrs, ___tracepoints_ptrs) \ *(__tracepoints_strings)/* Tracepoints: strings */ \ + *(.kallsyms_rodata) \ } \ \ .rodata1 : AT(ADDR(.rodata1) - LOAD_OFFSET) { \ diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 03852da3d2490..743d3dd453599 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -365,7 +365,7 @@ static void write_src(void) printf("#define ALGN .balign 4\n"); printf("#endif\n"); - printf("\t.section .rodata, \"a\"\n"); + printf("\t.section .kallsyms_rodata, \"a\"\n"); output_label("kallsyms_num_syms"); printf("\t.long\t%u\n", table_cnt); -- 2.43.5