Skip to content

Commit 1b649e6

Browse files
committed
scripts/sorttable: Use uint64_t for mcount sorting
The mcount sorting defines uint_t to uint64_t on 64bit architectures and uint32_t on 32bit architectures. It can work with just using uint64_t as that will hold the values of both, and they are not used to point into the ELF file. sizeof(uint_t) is used for defining the size of the mcount_loc section. Instead of using a type, define long_size and use that instead. This will allow the header code to be moved into the C file as generic functions and not need to include sorttable.h twice, once for 64bit and once for 32bit. 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/20250105162346.373528925@goodmis.org Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 17bed33 commit 1b649e6

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

scripts/sorttable.h

Lines changed: 11 additions & 11 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 uint_t
2726
#undef ehdr_shoff
2827
#undef ehdr_shentsize
2928
#undef ehdr_shstrndx
@@ -39,6 +38,7 @@
3938
#undef sym_name
4039
#undef sym_value
4140
#undef sym_shndx
41+
#undef long_size
4242

4343
#ifdef SORTTABLE_64
4444
# define extable_ent_size 16
@@ -47,7 +47,6 @@
4747
# define sort_mcount_loc sort_mcount_loc_64
4848
# define elf_mcount_loc elf_mcount_loc_64
4949
# define do_sort do_sort_64
50-
# define uint_t uint64_t
5150
# define ehdr_shoff ehdr64_shoff
5251
# define ehdr_shentsize ehdr64_shentsize
5352
# define ehdr_shstrndx ehdr64_shstrndx
@@ -63,14 +62,14 @@
6362
# define sym_name sym64_name
6463
# define sym_value sym64_value
6564
# define sym_shndx sym64_shndx
65+
# define long_size 8
6666
#else
6767
# define extable_ent_size 8
6868
# define compare_extable compare_extable_32
6969
# define get_mcount_loc get_mcount_loc_32
7070
# define sort_mcount_loc sort_mcount_loc_32
7171
# define elf_mcount_loc elf_mcount_loc_32
7272
# define do_sort do_sort_32
73-
# define uint_t uint32_t
7473
# define ehdr_shoff ehdr32_shoff
7574
# define ehdr_shentsize ehdr32_shentsize
7675
# define ehdr_shstrndx ehdr32_shstrndx
@@ -86,6 +85,7 @@
8685
# define sym_name sym32_name
8786
# define sym_value sym32_value
8887
# define sym_shndx sym32_shndx
88+
# define long_size 4
8989
#endif
9090

9191
#if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED)
@@ -193,25 +193,25 @@ pthread_t mcount_sort_thread;
193193
struct elf_mcount_loc {
194194
Elf_Ehdr *ehdr;
195195
Elf_Shdr *init_data_sec;
196-
uint_t start_mcount_loc;
197-
uint_t stop_mcount_loc;
196+
uint64_t start_mcount_loc;
197+
uint64_t stop_mcount_loc;
198198
};
199199

200200
/* Sort the addresses stored between __start_mcount_loc to __stop_mcount_loc in vmlinux */
201201
static void *sort_mcount_loc(void *arg)
202202
{
203203
struct elf_mcount_loc *emloc = (struct elf_mcount_loc *)arg;
204-
uint_t offset = emloc->start_mcount_loc - shdr_addr(emloc->init_data_sec)
204+
uint64_t offset = emloc->start_mcount_loc - shdr_addr(emloc->init_data_sec)
205205
+ shdr_offset(emloc->init_data_sec);
206-
uint_t count = emloc->stop_mcount_loc - emloc->start_mcount_loc;
206+
uint64_t count = emloc->stop_mcount_loc - emloc->start_mcount_loc;
207207
unsigned char *start_loc = (void *)emloc->ehdr + offset;
208208

209-
qsort(start_loc, count/sizeof(uint_t), sizeof(uint_t), compare_extable);
209+
qsort(start_loc, count/long_size, long_size, compare_extable);
210210
return NULL;
211211
}
212212

213213
/* Get the address of __start_mcount_loc and __stop_mcount_loc in System.map */
214-
static void get_mcount_loc(uint_t *_start, uint_t *_stop)
214+
static void get_mcount_loc(uint64_t *_start, uint64_t *_stop)
215215
{
216216
FILE *file_start, *file_stop;
217217
char start_buff[20];
@@ -277,8 +277,8 @@ static int do_sort(Elf_Ehdr *ehdr,
277277
unsigned int shstrndx;
278278
#ifdef MCOUNT_SORT_ENABLED
279279
struct elf_mcount_loc mstruct = {0};
280-
uint_t _start_mcount_loc = 0;
281-
uint_t _stop_mcount_loc = 0;
280+
uint64_t _start_mcount_loc = 0;
281+
uint64_t _stop_mcount_loc = 0;
282282
#endif
283283
#if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED)
284284
unsigned int orc_ip_size = 0;

0 commit comments

Comments
 (0)