Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
fork

Configure Feed

Select the types of activity you want to include in your feed.

gendwarfksyms: Fix structure type overrides

As we always iterate through the entire die_map when expanding
type strings, recursively processing referenced types in
type_expand_child() is not actually necessary. Furthermore,
the type_string kABI rule added in commit c9083467f7b9
("gendwarfksyms: Add a kABI rule to override type strings") can
fail to override type strings for structures due to a missing
kabi_get_type_string() check in this function.

Fix the issue by dropping the unnecessary recursion and moving
the override check to type_expand(). Note that symbol versions
are otherwise unchanged with this patch.

Fixes: c9083467f7b9 ("gendwarfksyms: Add a kABI rule to override type strings")
Reported-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Petr Pavlu <petr.pavlu@suse.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

authored by

Sami Tolvanen and committed by
Masahiro Yamada
2f6b47b2 a6a7946b

+21 -58
+2 -12
scripts/gendwarfksyms/gendwarfksyms.h
··· 216 void cache_init(struct cache *cache); 217 void cache_free(struct cache *cache); 218 219 - static inline void __cache_mark_expanded(struct cache *cache, uintptr_t addr) 220 - { 221 - cache_set(cache, addr, 1); 222 - } 223 - 224 - static inline bool __cache_was_expanded(struct cache *cache, uintptr_t addr) 225 - { 226 - return cache_get(cache, addr) == 1; 227 - } 228 - 229 static inline void cache_mark_expanded(struct cache *cache, void *addr) 230 { 231 - __cache_mark_expanded(cache, (uintptr_t)addr); 232 } 233 234 static inline bool cache_was_expanded(struct cache *cache, void *addr) 235 { 236 - return __cache_was_expanded(cache, (uintptr_t)addr); 237 } 238 239 /*
··· 216 void cache_init(struct cache *cache); 217 void cache_free(struct cache *cache); 218 219 static inline void cache_mark_expanded(struct cache *cache, void *addr) 220 { 221 + cache_set(cache, (unsigned long)addr, 1); 222 } 223 224 static inline bool cache_was_expanded(struct cache *cache, void *addr) 225 { 226 + return cache_get(cache, (unsigned long)addr) == 1; 227 } 228 229 /*
+19 -46
scripts/gendwarfksyms/types.c
··· 333 cache_free(&expansion_cache); 334 } 335 336 - static void __type_expand(struct die *cache, struct type_expansion *type, 337 - bool recursive); 338 - 339 - static void type_expand_child(struct die *cache, struct type_expansion *type, 340 - bool recursive) 341 - { 342 - struct type_expansion child; 343 - char *name; 344 - 345 - name = get_type_name(cache); 346 - if (!name) { 347 - __type_expand(cache, type, recursive); 348 - return; 349 - } 350 - 351 - if (recursive && !__cache_was_expanded(&expansion_cache, cache->addr)) { 352 - __cache_mark_expanded(&expansion_cache, cache->addr); 353 - type_expansion_init(&child); 354 - __type_expand(cache, &child, true); 355 - type_map_add(name, &child); 356 - type_expansion_free(&child); 357 - } 358 - 359 - type_expansion_append(type, name, name); 360 - } 361 - 362 - static void __type_expand(struct die *cache, struct type_expansion *type, 363 - bool recursive) 364 { 365 struct die_fragment *df; 366 struct die *child; 367 368 list_for_each_entry(df, &cache->fragments, list) { 369 switch (df->type) { ··· 353 error("unknown child: %" PRIxPTR, 354 df->data.addr); 355 356 - type_expand_child(child, type, recursive); 357 break; 358 case FRAGMENT_LINEBREAK: 359 /* ··· 376 } 377 } 378 379 - static void type_expand(struct die *cache, struct type_expansion *type, 380 - bool recursive) 381 { 382 type_expansion_init(type); 383 - __type_expand(cache, type, recursive); 384 - cache_free(&expansion_cache); 385 } 386 387 static void type_parse(const char *name, const char *str, ··· 399 400 if (!*str) 401 error("empty type string override for '%s'", name); 402 - 403 - type_expansion_init(type); 404 405 for (pos = 0; str[pos]; ++pos) { 406 bool empty; ··· 460 static void expand_type(struct die *cache, void *arg) 461 { 462 struct type_expansion type; 463 - const char *override; 464 char *name; 465 466 if (cache->mapped) ··· 485 486 debug("%s", name); 487 488 - if (stable && kabi_get_type_string(name, &override)) 489 - type_parse(name, override, &type); 490 - else 491 - type_expand(cache, &type, true); 492 - 493 type_map_add(name, &type); 494 type_expansion_free(&type); 495 free(name); ··· 495 { 496 struct type_expansion type; 497 struct version version; 498 - const char *override; 499 struct die *cache; 500 501 /* ··· 508 if (__die_map_get(sym->die_addr, DIE_SYMBOL, &cache)) 509 return; /* We'll warn about missing CRCs later. */ 510 511 - if (stable && kabi_get_type_string(sym->name, &override)) 512 - type_parse(sym->name, override, &type); 513 - else 514 - type_expand(cache, &type, false); 515 516 /* If the symbol already has a version, don't calculate it again. */ 517 if (sym->state != SYMBOL_PROCESSED) {
··· 333 cache_free(&expansion_cache); 334 } 335 336 + static void __type_expand(struct die *cache, struct type_expansion *type) 337 { 338 struct die_fragment *df; 339 struct die *child; 340 + char *name; 341 342 list_for_each_entry(df, &cache->fragments, list) { 343 switch (df->type) { ··· 379 error("unknown child: %" PRIxPTR, 380 df->data.addr); 381 382 + name = get_type_name(child); 383 + if (name) 384 + type_expansion_append(type, name, name); 385 + else 386 + __type_expand(child, type); 387 + 388 break; 389 case FRAGMENT_LINEBREAK: 390 /* ··· 397 } 398 } 399 400 + static void type_expand(const char *name, struct die *cache, 401 + struct type_expansion *type) 402 { 403 + const char *override; 404 + 405 type_expansion_init(type); 406 + 407 + if (stable && kabi_get_type_string(name, &override)) 408 + type_parse(name, override, type); 409 + else 410 + __type_expand(cache, type); 411 } 412 413 static void type_parse(const char *name, const char *str, ··· 415 416 if (!*str) 417 error("empty type string override for '%s'", name); 418 419 for (pos = 0; str[pos]; ++pos) { 420 bool empty; ··· 478 static void expand_type(struct die *cache, void *arg) 479 { 480 struct type_expansion type; 481 char *name; 482 483 if (cache->mapped) ··· 504 505 debug("%s", name); 506 507 + type_expand(name, cache, &type); 508 type_map_add(name, &type); 509 type_expansion_free(&type); 510 free(name); ··· 518 { 519 struct type_expansion type; 520 struct version version; 521 struct die *cache; 522 523 /* ··· 532 if (__die_map_get(sym->die_addr, DIE_SYMBOL, &cache)) 533 return; /* We'll warn about missing CRCs later. */ 534 535 + type_expand(sym->name, cache, &type); 536 537 /* If the symbol already has a version, don't calculate it again. */ 538 if (sym->state != SYMBOL_PROCESSED) {