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

gendwarfksyms: order -T symtypes output by name

When writing symtypes information, we iterate through the entire hash
table containing type expansions. The key order varies unpredictably
as new entries are added, making it harder to compare symtypes between
builds.

Resolve this by sorting the type expansions by name before output.

Signed-off-by: Giuliano Procida <gprocida@google.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

authored by

Giuliano Procida and committed by
Masahiro Yamada
d8f26717 e06aa69d

+26 -3
+26 -3
scripts/gendwarfksyms/types.c
··· 6 6 #define _GNU_SOURCE 7 7 #include <inttypes.h> 8 8 #include <stdio.h> 9 + #include <stdlib.h> 10 + #include <string.h> 9 11 #include <zlib.h> 10 12 11 13 #include "gendwarfksyms.h" ··· 181 179 return -1; 182 180 } 183 181 182 + static int cmp_expansion_name(const void *p1, const void *p2) 183 + { 184 + struct type_expansion *const *e1 = p1; 185 + struct type_expansion *const *e2 = p2; 186 + 187 + return strcmp((*e1)->name, (*e2)->name); 188 + } 189 + 184 190 static void type_map_write(FILE *file) 185 191 { 186 192 struct type_expansion *e; 187 193 struct hlist_node *tmp; 194 + struct type_expansion **es; 195 + size_t count = 0; 196 + size_t i = 0; 188 197 189 198 if (!file) 190 199 return; 191 200 192 - hash_for_each_safe(type_map, e, tmp, hash) { 193 - checkp(fputs(e->name, file)); 201 + hash_for_each_safe(type_map, e, tmp, hash) 202 + ++count; 203 + es = xmalloc(count * sizeof(*es)); 204 + hash_for_each_safe(type_map, e, tmp, hash) 205 + es[i++] = e; 206 + 207 + qsort(es, count, sizeof(*es), cmp_expansion_name); 208 + 209 + for (i = 0; i < count; ++i) { 210 + checkp(fputs(es[i]->name, file)); 194 211 checkp(fputs(" ", file)); 195 - type_list_write(&e->expanded, file); 212 + type_list_write(&es[i]->expanded, file); 196 213 checkp(fputs("\n", file)); 197 214 } 215 + 216 + free(es); 198 217 } 199 218 200 219 static void type_map_free(void)