Skip to content

Commit 0bfbc1a

Browse files
myxoiddagomez137
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 <gprocida@google.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
1 parent 6381fa5 commit 0bfbc1a

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

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"
@@ -150,20 +152,41 @@ static void type_map_add(const char *name, struct type_expansion *type)
150152
}
151153
}
152154

155+
static int cmp_expansion_name(const void *p1, const void *p2)
156+
{
157+
struct type_expansion *const *e1 = p1;
158+
struct type_expansion *const *e2 = p2;
159+
160+
return strcmp((*e1)->name, (*e2)->name);
161+
}
162+
153163
static void type_map_write(FILE *file)
154164
{
155165
struct type_expansion *e;
156166
struct hlist_node *tmp;
167+
struct type_expansion **es;
168+
size_t count = 0;
169+
size_t i = 0;
157170

158171
if (!file)
159172
return;
160173

161-
hash_for_each_safe(type_map, e, tmp, hash) {
162-
checkp(fputs(e->name, file));
174+
hash_for_each_safe(type_map, e, tmp, hash)
175+
++count;
176+
es = xmalloc(count * sizeof(struct type_expansion *));
177+
hash_for_each_safe(type_map, e, tmp, hash)
178+
es[i++] = e;
179+
180+
qsort(es, count, sizeof(struct type_expansion *), cmp_expansion_name);
181+
182+
for (i = 0; i < count; ++i) {
183+
checkp(fputs(es[i]->name, file));
163184
checkp(fputs(" ", file));
164-
type_list_write(&e->expanded, file);
185+
type_list_write(&es[i]->expanded, file);
165186
checkp(fputs("\n", file));
166187
}
188+
189+
free(es);
167190
}
168191

169192
static void type_map_free(void)

0 commit comments

Comments
 (0)