diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c index 09160030..86bc5328 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c @@ -396,6 +396,17 @@ static bool is_string_literal_section(struct section *sec) return !strncmp(sec->name, ".rodata.", 8) && strstr(sec->name, ".str"); } +/* + * Clang generates .data..L__unnamed_XX sections for anonymous constants. + * The numeric suffix is unstable (it can change if code is added/removed). + * Therefore, we must never correlate these by name; the patched object + * must always allocate a fresh copy (Status: NEW). + */ +static bool is_clang_unnamed_data(const char *name) +{ + return !strncmp(name, ".data..L__unnamed_", 18); +} + /* * This function detects whether the given symbol is a "special" static local * variable (for lack of a better term). @@ -425,6 +436,10 @@ static bool is_special_static(struct symbol *sym) if (is_dynamic_debug_symbol(sym)) return true; + /* Do not try to correlate statics inside unstable Clang sections */ + if (sym->sec && is_clang_unnamed_data(sym->sec->name)) + return true; + if (sym->type == STT_SECTION) { /* make sure section is bundled */ if (!sym->sec->sym) @@ -1142,6 +1157,11 @@ static void kpatch_correlate_sections(struct list_head *seclist_orig, if (is_ubsan_sec(sec_orig->name)) continue; + /* Skip correlation for unstable Clang anonymous sections */ + if (is_clang_unnamed_data(sec_orig->name) || + is_clang_unnamed_data(sec_patched->name)) + continue; + if (is_special_static(is_rela_section(sec_orig) ? sec_orig->base->secsym : sec_orig->secsym))