Skip to content

Commit d01cbc2

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 <swine@google.com>
1 parent 71eb58d commit d01cbc2

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

kpatch-build/create-diff-object.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,28 @@ static bool is_string_literal_section(struct section *sec)
345345
return !strncmp(sec->name, ".rodata.", 8) && strstr(sec->name, ".str");
346346
}
347347

348+
/* gcc's ".data.unlikely" or clang's ".(data|bss).module_name.unlikely" */
349+
static bool is_data_unlikely_section(const char *name)
350+
{
351+
size_t len = strlen(name);
352+
353+
return (len >= 5 + 8 &&
354+
((!strncmp(name, ".data.", 6) ||
355+
!strncmp(name, ".bss.", 5)) &&
356+
strstr(name + len - 9, ".unlikely")));
357+
}
358+
359+
/* either ".data.once" or clang's ".(data|bss).module_name.once" */
360+
static bool is_data_once_section(const char *name)
361+
{
362+
size_t len = strlen(name);
363+
364+
return (len >= 5 + 4 &&
365+
(!strncmp(name, ".data.", 6) ||
366+
!strncmp(name, ".bss.", 5)) &&
367+
strstr(name + len - 5, ".once"));
368+
}
369+
348370
/*
349371
* This function detects whether the given symbol is a "special" static local
350372
* variable (for lack of a better term).
@@ -386,7 +408,7 @@ static bool is_special_static(struct symbol *sym)
386408
if (sym->type != STT_OBJECT || sym->bind != STB_LOCAL)
387409
return false;
388410

389-
if (!strcmp(sym->sec->name, ".data.once"))
411+
if (is_data_once_section(sym->sec->name))
390412
return true;
391413

392414
for (var_name = var_names; *var_name; var_name++) {
@@ -1185,9 +1207,11 @@ static void kpatch_correlate_symbols(struct kpatch_elf *kelf_orig,
11851207
* The .LCx symbols point to string literals in
11861208
* '.rodata.<func>.str1.*' sections. They get included
11871209
* in kpatch_include_standard_elements().
1210+
* Clang creates similar .Ltmp%d symbols in .rodata.str
11881211
*/
11891212
if (sym_orig->type == STT_NOTYPE &&
1190-
!strncmp(sym_orig->name, ".LC", 3))
1213+
!(strncmp(sym_orig->name, ".LC", 3) &&
1214+
strncmp(sym_orig->name, ".Ltmp", 5)))
11911215
continue;
11921216

11931217
if (kpatch_is_mapping_symbol(kelf_orig, sym_orig))
@@ -1824,8 +1848,10 @@ static void kpatch_verify_patchability(struct kpatch_elf *kelf)
18241848
* (.data.unlikely and .data.once is ok b/c it only has __warned vars)
18251849
*/
18261850
if (sec->include && sec->status != NEW &&
1827-
(!strncmp(sec->name, ".data", 5) || !strncmp(sec->name, ".bss", 4)) &&
1828-
(strcmp(sec->name, ".data.unlikely") && strcmp(sec->name, ".data.once"))) {
1851+
(!strncmp(sec->name, ".data", 5) ||
1852+
!strncmp(sec->name, ".bss", 4)) &&
1853+
!is_data_once_section(sec->name) &&
1854+
!is_data_unlikely_section(sec->name)) {
18291855
log_normal("data section %s selected for inclusion\n",
18301856
sec->name);
18311857
errs++;

0 commit comments

Comments
 (0)