diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c index a5cbd532..56ade7ef 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c @@ -399,6 +399,18 @@ 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) || + !strncmp(name, ".data.__unnamed_", 16); +} + /* * This function detects whether the given symbol is a "special" static local * variable (for lack of a better term). @@ -428,6 +440,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) @@ -1150,6 +1166,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)) @@ -1793,6 +1814,7 @@ static void kpatch_replace_sections_syms(struct kpatch_elf *kelf) } if (!found && !is_string_literal_section(rela->sym->sec) && + !is_clang_unnamed_data(rela->sym->name) && strncmp(rela->sym->name, ".rodata", 7)) { ERROR("%s+0x%x: can't find replacement symbol for %s+%ld reference", relasec->base->name, rela->offset, rela->sym->name, rela->addend); diff --git a/test/unit/objs b/test/unit/objs index bf463645..813ba60c 160000 --- a/test/unit/objs +++ b/test/unit/objs @@ -1 +1 @@ -Subproject commit bf463645367ec892b0c0ba265d2deacbd6289581 +Subproject commit 813ba60cf7ccaaaeef9e3ea9aa610d184fb5f1e6