Skip to content

Commit be5da15

Browse files
committed
adapt to clang/arm64 naming
New toolchain/arch, new conventions for section/label/etc names gcc's .LCx symbols point to string literals in '.rodata.<func>.str1.*' sections. Clang creates similar .Ltmp%d symbols in '.rodata.str' The function is_string_literal_section() generalized (too much?) to match either - clang's/arm64 /^\.rodata\.str$/ - gcc's /^\.rodata\./ && /\.str1\./ Various matchers for .data.unlikely .bss.unlikely replaced by is_data_unlikely_section() generalized to match - gcc's ".data.unlikely" - clang's ".(data|bss).module_name.unlikely" .data.once handled similarly Signed-off-by: Pete Swain <[email protected]>
1 parent 80bb442 commit be5da15

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

kpatch-build/create-diff-object.c

+30-4
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,28 @@ static bool is_string_literal_section(struct section *sec)
340340
return !strncmp(sec->name, ".rodata.", 8) && strstr(sec->name, ".str");
341341
}
342342

343+
/* gcc's ".data.unlikely" or clang's ".(data|bss).module_name.unlikely" */
344+
static bool is_data_unlikely_section(const char *name)
345+
{
346+
size_t len = strlen(name);
347+
348+
return (len >= 5 + 8 &&
349+
((!strncmp(name, ".data.", 6) ||
350+
!strncmp(name, ".bss.", 5)) &&
351+
strstr(name + len - 9, ".unlikely")));
352+
}
353+
354+
/* either ".data.once" or clang's ".(data|bss).module_name.once" */
355+
static bool is_data_once_section(const char *name)
356+
{
357+
size_t len = strlen(name);
358+
359+
return (len >= 5 + 4 &&
360+
(!strncmp(name, ".data.", 6) ||
361+
!strncmp(name, ".bss.", 5)) &&
362+
strstr(name + len - 5, ".once"));
363+
}
364+
343365
/*
344366
* This function detects whether the given symbol is a "special" static local
345367
* variable (for lack of a better term).
@@ -381,7 +403,7 @@ static bool is_special_static(struct symbol *sym)
381403
if (sym->type != STT_OBJECT || sym->bind != STB_LOCAL)
382404
return false;
383405

384-
if (!strcmp(sym->sec->name, ".data.once"))
406+
if (is_data_once_section(sym->sec->name))
385407
return true;
386408

387409
for (var_name = var_names; *var_name; var_name++) {
@@ -1148,9 +1170,11 @@ static void kpatch_correlate_symbols(struct kpatch_elf *kelf_orig,
11481170
* The .LCx symbols point to string literals in
11491171
* '.rodata.<func>.str1.*' sections. They get included
11501172
* in kpatch_include_standard_elements().
1173+
* Clang creates similar .Ltmp%d symbols in .rodata.str
11511174
*/
11521175
if (sym_orig->type == STT_NOTYPE &&
1153-
!strncmp(sym_orig->name, ".LC", 3))
1176+
(!strncmp(sym_orig->name, ".LC", 3) ||
1177+
!strncmp(sym_orig->name, ".Ltmp", 5)))
11541178
continue;
11551179

11561180
if (kpatch_is_mapping_symbol(kelf_orig, sym_orig))
@@ -1787,8 +1811,10 @@ static void kpatch_verify_patchability(struct kpatch_elf *kelf)
17871811
* (.data.unlikely and .data.once is ok b/c it only has __warned vars)
17881812
*/
17891813
if (sec->include && sec->status != NEW &&
1790-
(!strncmp(sec->name, ".data", 5) || !strncmp(sec->name, ".bss", 4)) &&
1791-
(strcmp(sec->name, ".data.unlikely") && strcmp(sec->name, ".data.once"))) {
1814+
(!strncmp(sec->name, ".data", 5) ||
1815+
!strncmp(sec->name, ".bss", 4)) &&
1816+
!is_data_once_section(sec->name) &&
1817+
!is_data_unlikely_section(sec->name)) {
17921818
log_normal("data section %s selected for inclusion\n",
17931819
sec->name);
17941820
errs++;

0 commit comments

Comments
 (0)