From patchwork Thu Jan 2 23:26: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: 13925009 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 EFBA61BEF9F; Thu, 2 Jan 2025 23:25:32 +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=1735860333; cv=none; b=hdnCBRc1NdulQAkOlQLZ/MuI3JroMnJot3IC/sLJffQpe+2zX56UnXMFQAAw6F6hhn4rZt47edJVSRfOzj/J1xwyK+70F+UiSZKX4t6sRYohOj3dJfssUSbwX0k8gi8Uea1fG3Xp8KWqV9YT7Byal2N9krxasR6PzY1jRX94W7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735860333; c=relaxed/simple; bh=rpDkiZolJ8Aw8FySmRQR6P9UH1zV54Fcd5p2oSzjU24=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=qlR6+JS/bSHBmyNCQj/JROCb5dAM7KsNWcgOPpaLgA5pxsywOlcroCAEvBQEqwLUm+cw5XlgZ5CDf+pnPx3dmLhWm7yBQ/ry6fLSNN1I2ar78oxDiPYrVUmYf4xo+0cTaiaiyB/sb4/12LcOibpLxUOzWsbhK0wcOwT8BA3a01Q= 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 D1E78C4CEEB; Thu, 2 Jan 2025 23:25:32 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tTUaY-00000005Yun-0XmB; Thu, 02 Jan 2025 18:26:50 -0500 Message-ID: <20250102232649.981589934@goodmis.org> User-Agent: quilt/0.68 Date: Thu, 02 Jan 2025 18:26:17 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, bpf Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Peter Zijlstra , Linus Torvalds , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Zheng Yejian , Martin Kelly , Christophe Leroy , Josh Poimboeuf Subject: [PATCH v2 08/16] scripts/sorttable: Convert Elf_Sym MACRO over to a union References: <20250102232609.529842248@goodmis.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Steven Rostedt In order to remove the double #include of sorttable.h for 64 and 32 bit to create duplicate functions for both, replace the Elf_Sym macro with a union that defines both Elf64_Sym and Elf32_Sym, with field e64 for the 64bit version, and e32 for the 32bit version. It can then use the macro etype to get the proper value. This will eventually be replaced with just single functions that can handle both 32bit and 64bit ELF parsing. Signed-off-by: Steven Rostedt (Google) --- scripts/sorttable.c | 5 +++++ scripts/sorttable.h | 25 ++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/scripts/sorttable.c b/scripts/sorttable.c index 94497b8ab04c..57792cf2aa89 100644 --- a/scripts/sorttable.c +++ b/scripts/sorttable.c @@ -74,6 +74,11 @@ typedef union { Elf64_Shdr e64; } Elf_Shdr; +typedef union { + Elf32_Sym e32; + Elf64_Sym e64; +} Elf_Sym; + static uint32_t (*r)(const uint32_t *); static uint16_t (*r2)(const uint16_t *); static uint64_t (*r8)(const uint64_t *); diff --git a/scripts/sorttable.h b/scripts/sorttable.h index 034ce8560dad..a365a8bc405a 100644 --- a/scripts/sorttable.h +++ b/scripts/sorttable.h @@ -23,7 +23,6 @@ #undef sort_mcount_loc #undef elf_mcount_loc #undef do_sort -#undef Elf_Sym #undef ELF_ST_TYPE #undef uint_t #undef _r @@ -36,7 +35,6 @@ # define sort_mcount_loc sort_mcount_loc_64 # define elf_mcount_loc elf_mcount_loc_64 # define do_sort do_sort_64 -# define Elf_Sym Elf64_Sym # define ELF_ST_TYPE ELF64_ST_TYPE # define uint_t uint64_t # define _r r8 @@ -48,7 +46,6 @@ # define sort_mcount_loc sort_mcount_loc_32 # define elf_mcount_loc elf_mcount_loc_32 # define do_sort do_sort_32 -# define Elf_Sym Elf32_Sym # define ELF_ST_TYPE ELF32_ST_TYPE # define uint_t uint32_t # define _r r @@ -227,10 +224,13 @@ static int do_sort(Elf_Ehdr *ehdr, Elf_Sym *sort_needed_sym = NULL; Elf_Shdr *sort_needed_sec; uint32_t *sort_needed_loc; + void *sym_start; + void *sym_end; const char *secstrings; const char *strtab; char *extab_image; int sort_need_index; + int symentsize; int shentsize; int idx; int i; @@ -373,12 +373,15 @@ static int do_sort(Elf_Ehdr *ehdr, } /* find the flag main_extable_sort_needed */ - for (sym = (void *)ehdr + _r(&symtab_sec->etype.sh_offset); - sym < sym + _r(&symtab_sec->etype.sh_size) / sizeof(Elf_Sym); - sym++) { - if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT) + sym_start = (void *)ehdr + _r(&symtab_sec->etype.sh_offset); + sym_end = sym_start + _r(&symtab_sec->etype.sh_size); + symentsize = _r(&symtab_sec->etype.sh_entsize); + + for (sym = sym_start; (void *)sym + symentsize < sym_end; + sym = (void *)sym + symentsize) { + if (ELF_ST_TYPE(sym->etype.st_info) != STT_OBJECT) continue; - if (!strcmp(strtab + r(&sym->st_name), + if (!strcmp(strtab + r(&sym->etype.st_name), "main_extable_sort_needed")) { sort_needed_sym = sym; break; @@ -392,13 +395,13 @@ static int do_sort(Elf_Ehdr *ehdr, goto out; } - sort_need_index = get_secindex(r2(&sym->st_shndx), - sort_needed_sym - symtab, + sort_need_index = get_secindex(r2(&sym->etype.st_shndx), + ((void *)sort_needed_sym - (void *)symtab) / symentsize, symtab_shndx); sort_needed_sec = get_index(shdr_start, shentsize, sort_need_index); sort_needed_loc = (void *)ehdr + _r(&sort_needed_sec->etype.sh_offset) + - _r(&sort_needed_sym->st_value) - + _r(&sort_needed_sym->etype.st_value) - _r(&sort_needed_sec->etype.sh_addr); /* extable has been sorted, clear the flag */