From patchwork Wed Feb 19 15:18:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13982434 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5711D19D067; Wed, 19 Feb 2025 15:18:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739978320; cv=none; b=LBZC0WZ6hjunoB2eKcyv0EHltBTCoAS6x0bXf41JtSovcjikFy7SO4ewR/L4gaPBUUARkOg8MVq52BBzn1wBH8uYUxYwI7Y0OT6/463Mff1qhnOlaxdMpG/1f/sgEUosSmLiBGYLb+oGV7L1Keup0c8O0QlGWL2/LIrCZ6PSm3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739978320; c=relaxed/simple; bh=2gfuHK10pWbnp1kasPYwpA9FyJnNwp/Rer8OuBT8Dzc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=nYWQpnmDLWSfahqO5nU2MfHCYWXBKT77q3+t6nqvbAHzJvsapt5Ltu1PiM/YrELh+5yOwuOCF/HkI8rbJnTYjbNsaj9/rbMCv5zlNANsfj0BWyoaXPPj81fwpxZXCKRZ7ygniR7KafJCAXnK3tJkFN72JQLphxReNcz4jpdBaUk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACC3FC4CEE7; Wed, 19 Feb 2025 15:18:39 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tklqq-00000004bZJ-1CSm; Wed, 19 Feb 2025 10:19:04 -0500 Message-ID: <20250219151904.133228859@goodmis.org> User-Agent: quilt/0.68 Date: Wed, 19 Feb 2025 10:18:17 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , bpf , Peter Zijlstra , Linus Torvalds , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Zheng Yejian , Martin Kelly , Christophe Leroy , Josh Poimboeuf , Heiko Carstens , Catalin Marinas , Will Deacon , Vasily Gorbik , Alexander Gordeev Subject: [for-next][PATCH 2/6] scripts/sorttable: Have mcount rela sort use direct values References: <20250219151815.734900568@goodmis.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Steven Rostedt 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 Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Peter Zijlstra Cc: Linus Torvalds Cc: Masahiro Yamada Cc: Nathan Chancellor Cc: Nicolas Schier Cc: Zheng Yejian Cc: Martin Kelly Cc: Christophe Leroy Cc: Josh Poimboeuf Cc: Heiko Carstens Cc: Catalin Marinas Cc: Will Deacon Cc: Vasily Gorbik Cc: Alexander Gordeev Link: https://lore.kernel.org/20250218200022.538888594@goodmis.org Signed-off-by: Steven Rostedt (Google) --- scripts/sorttable.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/scripts/sorttable.c b/scripts/sorttable.c index 4a34c275123e..f62a91d8af0a 100644 --- a/scripts/sorttable.c +++ b/scripts/sorttable.c @@ -552,6 +552,28 @@ static void *sort_orctable(void *arg) #ifdef MCOUNT_SORT_ENABLED +static int compare_values_64(const void *a, const void *b) +{ + uint64_t av = *(uint64_t *)a; + uint64_t bv = *(uint64_t *)b; + + if (av < bv) + return -1; + return av > bv; +} + +static int compare_values_32(const void *a, const void *b) +{ + uint32_t av = *(uint32_t *)a; + uint32_t bv = *(uint32_t *)b; + + if (av < bv) + return -1; + return av > bv; +} + +static int (*compare_values)(const void *a, const void *b); + /* Only used for sorting mcount table */ static void rela_write_addend(Elf_Rela *rela, uint64_t val) { @@ -583,6 +605,8 @@ static void *sort_relocs(Elf_Ehdr *ehdr, uint64_t start_loc, uint64_t size) void *vals; void *ptr; + compare_values = long_size == 4 ? compare_values_32 : compare_values_64; + shdr_start = (Elf_Shdr *)((char *)ehdr + ehdr_shoff(ehdr)); shentsize = ehdr_shentsize(ehdr); @@ -640,7 +664,7 @@ static void *sort_relocs(Elf_Ehdr *ehdr, uint64_t start_loc, uint64_t size) } } count = ptr - vals; - qsort(vals, count / long_size, long_size, compare_extable); + qsort(vals, count / long_size, long_size, compare_values); ptr = vals; for (int i = 0; i < shnum; i++) {