Skip to content

Commit d8f2671

Browse files
myxoidmasahir0y
authored andcommitted
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 <[email protected]> Acked-by: Greg Kroah-Hartman <[email protected]> Reviewed-by: Sami Tolvanen <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent e06aa69 commit d8f2671

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

scripts/gendwarfksyms/types.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#define _GNU_SOURCE
77
#include <inttypes.h>
88
#include <stdio.h>
9+
#include <stdlib.h>
10+
#include <string.h>
911
#include <zlib.h>
1012

1113
#include "gendwarfksyms.h"
@@ -179,20 +181,41 @@ static int type_map_get(const char *name, struct type_expansion **res)
179181
return -1;
180182
}
181183

184+
static int cmp_expansion_name(const void *p1, const void *p2)
185+
{
186+
struct type_expansion *const *e1 = p1;
187+
struct type_expansion *const *e2 = p2;
188+
189+
return strcmp((*e1)->name, (*e2)->name);
190+
}
191+
182192
static void type_map_write(FILE *file)
183193
{
184194
struct type_expansion *e;
185195
struct hlist_node *tmp;
196+
struct type_expansion **es;
197+
size_t count = 0;
198+
size_t i = 0;
186199

187200
if (!file)
188201
return;
189202

190-
hash_for_each_safe(type_map, e, tmp, hash) {
191-
checkp(fputs(e->name, file));
203+
hash_for_each_safe(type_map, e, tmp, hash)
204+
++count;
205+
es = xmalloc(count * sizeof(*es));
206+
hash_for_each_safe(type_map, e, tmp, hash)
207+
es[i++] = e;
208+
209+
qsort(es, count, sizeof(*es), cmp_expansion_name);
210+
211+
for (i = 0; i < count; ++i) {
212+
checkp(fputs(es[i]->name, file));
192213
checkp(fputs(" ", file));
193-
type_list_write(&e->expanded, file);
214+
type_list_write(&es[i]->expanded, file);
194215
checkp(fputs("\n", file));
195216
}
217+
218+
free(es);
196219
}
197220

198221
static void type_map_free(void)

0 commit comments

Comments
 (0)