@@ -399,6 +399,18 @@ static bool is_string_literal_section(struct section *sec)
399399 return !strncmp (sec -> name , ".rodata." , 8 ) && strstr (sec -> name , ".str" );
400400}
401401
402+ /*
403+ * Clang generates .data..L__unnamed_XX sections for anonymous constants.
404+ * The numeric suffix is unstable (it can change if code is added/removed).
405+ * Therefore, we must never correlate these by name; the patched object
406+ * must always allocate a fresh copy (Status: NEW).
407+ */
408+ static bool is_clang_unnamed_data (const char * name )
409+ {
410+ return !strncmp (name , ".data..L__unnamed_" , 18 ) ||
411+ !strncmp (name , ".data.__unnamed_" , 16 );
412+ }
413+
402414/*
403415 * This function detects whether the given symbol is a "special" static local
404416 * variable (for lack of a better term).
@@ -428,6 +440,10 @@ static bool is_special_static(struct symbol *sym)
428440 if (is_dynamic_debug_symbol (sym ))
429441 return true;
430442
443+ /* Do not try to correlate statics inside unstable Clang sections */
444+ if (sym -> sec && is_clang_unnamed_data (sym -> sec -> name ))
445+ return true;
446+
431447 if (sym -> type == STT_SECTION ) {
432448 /* make sure section is bundled */
433449 if (!sym -> sec -> sym )
@@ -1150,6 +1166,11 @@ static void kpatch_correlate_sections(struct list_head *seclist_orig,
11501166 if (is_ubsan_sec (sec_orig -> name ))
11511167 continue ;
11521168
1169+ /* Skip correlation for unstable Clang anonymous sections */
1170+ if (is_clang_unnamed_data (sec_orig -> name ) ||
1171+ is_clang_unnamed_data (sec_patched -> name ))
1172+ continue ;
1173+
11531174 if (is_special_static (is_rela_section (sec_orig ) ?
11541175 sec_orig -> base -> secsym :
11551176 sec_orig -> secsym ))
@@ -1793,6 +1814,7 @@ static void kpatch_replace_sections_syms(struct kpatch_elf *kelf)
17931814 }
17941815
17951816 if (!found && !is_string_literal_section (rela -> sym -> sec ) &&
1817+ !is_clang_unnamed_data (rela -> sym -> name ) &&
17961818 strncmp (rela -> sym -> name , ".rodata" , 7 )) {
17971819 ERROR ("%s+0x%x: can't find replacement symbol for %s+%ld reference" ,
17981820 relasec -> base -> name , rela -> offset , rela -> sym -> name , rela -> addend );
0 commit comments