Skip to content

Commit a026565

Browse files
committed
scripts/sorttable: Have mcount rela sort use direct values
The mcount_loc sorting for when the values are stored in the Elf_Rela entries uses the compare_extable() function to do the compares in the qsort(). That function does handle byte swapping if the machine being compiled for is a different endian than the host machine. But the sort_relocs() function sorts an array that pulled in the values from the Elf_Rela section and has already done the swapping. Create two new compare functions that will sort the direct values. One will sort 32 bit values and the other will sort the 64 bit value. One of these will be assigned to a compare_values function pointer and that will be used for sorting the Elf_Rela mcount values. Cc: bpf <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Nathan Chancellor <[email protected]> Cc: Nicolas Schier <[email protected]> Cc: Zheng Yejian <[email protected]> Cc: Martin Kelly <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Will Deacon <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Alexander Gordeev <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent b3d09d0 commit a026565

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

scripts/sorttable.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,28 @@ static void *sort_orctable(void *arg)
552552

553553
#ifdef MCOUNT_SORT_ENABLED
554554

555+
static int compare_values_64(const void *a, const void *b)
556+
{
557+
uint64_t av = *(uint64_t *)a;
558+
uint64_t bv = *(uint64_t *)b;
559+
560+
if (av < bv)
561+
return -1;
562+
return av > bv;
563+
}
564+
565+
static int compare_values_32(const void *a, const void *b)
566+
{
567+
uint32_t av = *(uint32_t *)a;
568+
uint32_t bv = *(uint32_t *)b;
569+
570+
if (av < bv)
571+
return -1;
572+
return av > bv;
573+
}
574+
575+
static int (*compare_values)(const void *a, const void *b);
576+
555577
/* Only used for sorting mcount table */
556578
static void rela_write_addend(Elf_Rela *rela, uint64_t val)
557579
{
@@ -583,6 +605,8 @@ static void *sort_relocs(Elf_Ehdr *ehdr, uint64_t start_loc, uint64_t size)
583605
void *vals;
584606
void *ptr;
585607

608+
compare_values = long_size == 4 ? compare_values_32 : compare_values_64;
609+
586610
shdr_start = (Elf_Shdr *)((char *)ehdr + ehdr_shoff(ehdr));
587611
shentsize = ehdr_shentsize(ehdr);
588612

@@ -640,7 +664,7 @@ static void *sort_relocs(Elf_Ehdr *ehdr, uint64_t start_loc, uint64_t size)
640664
}
641665
}
642666
count = ptr - vals;
643-
qsort(vals, count / long_size, long_size, compare_extable);
667+
qsort(vals, count / long_size, long_size, compare_values);
644668

645669
ptr = vals;
646670
for (int i = 0; i < shnum; i++) {

0 commit comments

Comments
 (0)