Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions kpatch-build/create-diff-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down