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

Configure Feed

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

resolve_btfids: Refactor the sort_btf_by_name function

Preserve original relative order of anonymous or same-named
types to improve the consistency.

No functional changes.

Signed-off-by: Donglin Peng <pengdonglin@xiaomi.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20260202120114.3707141-1-dolinux.peng@gmail.com

authored by

Donglin Peng and committed by
Andrii Nakryiko
5e6e1dc4 78a16058

+11 -7
+11 -7
tools/bpf/resolve_btfids/main.c
··· 1226 1226 const struct btf_type *ta = btf__type_by_id(btf, *(__u32 *)a); 1227 1227 const struct btf_type *tb = btf__type_by_id(btf, *(__u32 *)b); 1228 1228 const char *na, *nb; 1229 + int r; 1229 1230 1230 1231 na = btf__str_by_offset(btf, ta->name_off); 1231 1232 nb = btf__str_by_offset(btf, tb->name_off); 1232 - return strcmp(na, nb); 1233 + r = strcmp(na, nb); 1234 + if (r != 0) 1235 + return r; 1236 + 1237 + /* preserve original relative order of anonymous or same-named types */ 1238 + return *(__u32 *)a < *(__u32 *)b ? -1 : 1; 1233 1239 } 1234 1240 1235 1241 static int sort_btf_by_name(struct btf *btf) 1236 1242 { 1237 1243 __u32 *permute_ids = NULL, *id_map = NULL; 1238 1244 int nr_types, i, err = 0; 1239 - __u32 start_id = 0, start_offs = 1, id; 1245 + __u32 start_id = 0, id; 1240 1246 1241 - if (btf__base_btf(btf)) { 1247 + if (btf__base_btf(btf)) 1242 1248 start_id = btf__type_cnt(btf__base_btf(btf)); 1243 - start_offs = 0; 1244 - } 1245 1249 nr_types = btf__type_cnt(btf) - start_id; 1246 1250 1247 1251 permute_ids = calloc(nr_types, sizeof(*permute_ids)); ··· 1263 1259 for (i = 0, id = start_id; i < nr_types; i++, id++) 1264 1260 permute_ids[i] = id; 1265 1261 1266 - qsort_r(permute_ids + start_offs, nr_types - start_offs, 1267 - sizeof(*permute_ids), cmp_type_names, btf); 1262 + qsort_r(permute_ids, nr_types, sizeof(*permute_ids), cmp_type_names, 1263 + btf); 1268 1264 1269 1265 for (i = 0; i < nr_types; i++) { 1270 1266 id = permute_ids[i] - start_id;