diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c index 21fe0a5..deba6a0 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c @@ -182,6 +182,12 @@ int is_rela_section(struct section *sec) return (sec->sh.sh_type == SHT_RELA); } +int is_text_section(struct section *sec) +{ + return (sec->sh.sh_type == SHT_PROGBITS && + (sec->sh.sh_flags & SHF_EXECINSTR)); +} + int is_debug_section(struct section *sec) { char *name; @@ -904,6 +910,7 @@ void kpatch_correlate_static_local_variables(struct kpatch_elf *base, sec = NULL; list_for_each_entry(tmpsec, &patched->sections, list) { if (!is_rela_section(tmpsec) || + !is_text_section(tmpsec->base) || is_debug_section(tmpsec)) continue; list_for_each_entry(rela, &tmpsec->relas, list) { @@ -1045,7 +1052,7 @@ void kpatch_replace_sections_syms(struct kpatch_elf *kelf) strcmp(rela->sym->name, ".data..read_mostly") && strcmp(rela->sym->name, ".data.unlikely") && !(rela->sym->type == STT_SECTION && rela->sym->sec && - (rela->sym->sec->sh.sh_flags & SHF_EXECINSTR))) + is_text_section(rela->sym->sec))) continue; list_for_each_entry(sym, &kelf->symbols, list) { diff --git a/test/integration/gcc-static-local-var-3.patch b/test/integration/gcc-static-local-var-3.patch new file mode 100644 index 0000000..9cabe93 --- /dev/null +++ b/test/integration/gcc-static-local-var-3.patch @@ -0,0 +1,20 @@ +Index: src/kernel/reboot.c +=================================================================== +--- src.orig/kernel/reboot.c ++++ src/kernel/reboot.c +@@ -285,8 +285,15 @@ SYSCALL_DEFINE4(reboot, int, magic1, int + return ret; + } + ++void kpatch_foo(void) ++{ ++ if (!jiffies) ++ printk("kpatch_foo\n"); ++} ++ + static void deferred_cad(struct work_struct *dummy) + { ++ kpatch_foo(); + kernel_restart(NULL); + } +