Skip to content

Commit 7ffc0d0

Browse files
committed
scripts/sorttable: Make compare_extable() into two functions
Instead of having the compare_extable() part of the sorttable.h header where it get's defined twice, since it is a very simple function, just define it twice in sorttable.c, and then it can use the proper read functions for the word size and endianess and the Elf_Addr macro can be removed from sorttable.h. Also add a micro optimization. Instead of: if (a < b) return -1; if (a > b) return 1; return 0; That can be shorten to: if (a < b) return -1; return a > b; Cc: bpf <bpf@vger.kernel.org> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Masahiro Yamada <masahiroy@kernel.org> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Nicolas Schier <nicolas@fjasle.eu> Cc: Zheng Yejian <zhengyejian1@huawei.com> Cc: Martin Kelly <martin.kelly@crowdstrike.com> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Link: https://lore.kernel.org/20250105162344.945299671@goodmis.org Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 66990c0 commit 7ffc0d0

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

scripts/sorttable.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,26 @@ static inline unsigned int get_secindex(unsigned int shndx,
173173
return r(&symtab_shndx_start[sym_offs]);
174174
}
175175

176+
static int compare_extable_32(const void *a, const void *b)
177+
{
178+
Elf32_Addr av = r(a);
179+
Elf32_Addr bv = r(b);
180+
181+
if (av < bv)
182+
return -1;
183+
return av > bv;
184+
}
185+
186+
static int compare_extable_64(const void *a, const void *b)
187+
{
188+
Elf64_Addr av = r8(a);
189+
Elf64_Addr bv = r8(b);
190+
191+
if (av < bv)
192+
return -1;
193+
return av > bv;
194+
}
195+
176196
/* 32 bit and 64 bit are very similar */
177197
#include "sorttable.h"
178198
#define SORTTABLE_64

scripts/sorttable.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#undef sort_mcount_loc
2424
#undef elf_mcount_loc
2525
#undef do_sort
26-
#undef Elf_Addr
2726
#undef Elf_Ehdr
2827
#undef Elf_Shdr
2928
#undef Elf_Sym
@@ -38,7 +37,6 @@
3837
# define sort_mcount_loc sort_mcount_loc_64
3938
# define elf_mcount_loc elf_mcount_loc_64
4039
# define do_sort do_sort_64
41-
# define Elf_Addr Elf64_Addr
4240
# define Elf_Ehdr Elf64_Ehdr
4341
# define Elf_Shdr Elf64_Shdr
4442
# define Elf_Sym Elf64_Sym
@@ -52,7 +50,6 @@
5250
# define sort_mcount_loc sort_mcount_loc_32
5351
# define elf_mcount_loc elf_mcount_loc_32
5452
# define do_sort do_sort_32
55-
# define Elf_Addr Elf32_Addr
5653
# define Elf_Ehdr Elf32_Ehdr
5754
# define Elf_Shdr Elf32_Shdr
5855
# define Elf_Sym Elf32_Sym
@@ -160,17 +157,6 @@ static void *sort_orctable(void *arg)
160157
}
161158
#endif
162159

163-
static int compare_extable(const void *a, const void *b)
164-
{
165-
Elf_Addr av = _r(a);
166-
Elf_Addr bv = _r(b);
167-
168-
if (av < bv)
169-
return -1;
170-
if (av > bv)
171-
return 1;
172-
return 0;
173-
}
174160
#ifdef MCOUNT_SORT_ENABLED
175161
pthread_t mcount_sort_thread;
176162

0 commit comments

Comments
 (0)