From nobody Tue Sep 16 21:42:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCDBFC4332F for ; Tue, 27 Dec 2022 16:02:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231682AbiL0QCz (ORCPT ); Tue, 27 Dec 2022 11:02:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229736AbiL0QCs (ORCPT ); Tue, 27 Dec 2022 11:02:48 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3104EA9 for ; Tue, 27 Dec 2022 08:02:46 -0800 (PST) From: Thomas =?utf-8?q?Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1672156964; bh=kT8j13gOnAKWYlSV+YMQw4TiVnvJKl0cCOa21YM32M0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NryKx8/WX4EttN2Wi7A01V/T+QeFOxPEcOYewudl8K5pU06HrP1jzw1Q1U/9g/UnF BaS2e9pdkU0JrXbUgolwwWI9nN4ODSobyrqO+IQk5DABU29VMAviScn9H34JGMgyX1 B3iiNyzM33rdyzepT8vFzQdaHGMxvMGu6CH7arxU= Date: Tue, 27 Dec 2022 16:00:57 +0000 Subject: [PATCH v2 1/8] objtool: make struct entries[] static and const MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221216-objtool-memory-v2-1-17968f85a464@weissschuh.net> References: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> In-Reply-To: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> To: Josh Poimboeuf , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas =?utf-8?q?Wei=C3=9Fschuh?= X-Mailer: b4 0.11.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1672156865; l=1357; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=kT8j13gOnAKWYlSV+YMQw4TiVnvJKl0cCOa21YM32M0=; b=KVBj9VZ9YQSV25Jq2t8yb7ci7FBwnt5YjyakqphuIDIRCP6beV5l2wrS/0h8KA8/9ibZai5PYDGO 8HfVrMblAEPjhqpksBwKtiEl3VZG0yIzdaDrrLGbQJkoy4ZiEGjG X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This data is not modified and not used outside of special.c. Also adapt its users to the constness. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/objtool/special.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/objtool/special.c b/tools/objtool/special.c index 9c8d827f69af..baa85c31526b 100644 --- a/tools/objtool/special.c +++ b/tools/objtool/special.c @@ -26,7 +26,7 @@ struct special_entry { unsigned char key; /* jump_label key */ }; =20 -struct special_entry entries[] =3D { +static const struct special_entry entries[] =3D { { .sec =3D ".altinstructions", .group =3D true, @@ -65,7 +65,7 @@ static void reloc_to_sec_off(struct reloc *reloc, struct = section **sec, *off =3D reloc->sym->offset + reloc->addend; } =20 -static int get_alt_entry(struct elf *elf, struct special_entry *entry, +static int get_alt_entry(struct elf *elf, const struct special_entry *entr= y, struct section *sec, int idx, struct special_alt *alt) { @@ -139,7 +139,7 @@ static int get_alt_entry(struct elf *elf, struct specia= l_entry *entry, */ int special_get_alts(struct elf *elf, struct list_head *alts) { - struct special_entry *entry; + const struct special_entry *entry; struct section *sec; unsigned int nr_entries; struct special_alt *alt; --=20 2.39.0 From nobody Tue Sep 16 21:42:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 913F7C10F1B for ; Tue, 27 Dec 2022 16:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232016AbiL0QDI (ORCPT ); Tue, 27 Dec 2022 11:03:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231575AbiL0QCv (ORCPT ); Tue, 27 Dec 2022 11:02:51 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9991D73 for ; Tue, 27 Dec 2022 08:02:49 -0800 (PST) From: Thomas =?utf-8?q?Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1672156966; bh=s5ecXOvEehEk53y4y2OsKyfg1cQWJRf01QzJ+Hcl4rk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=bGIKGHdIZ/KqixZJ7Q5PHiVT7CjHcdMVbIheTEv+Mv16FdEi59VKqdEqVRutatzZX owjZJgDOzaBYLsH/rkR3ptyxR2QtPbdfp4v7o0Zuq36H4wJHDs4SoyAiry+EDq4okl oMP2i8+QIgJUvkdUWkNZZC7WBAkvXPrf1xB/inR4= Date: Tue, 27 Dec 2022 16:00:58 +0000 Subject: [PATCH v2 2/8] objtool: make struct check_options static MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221216-objtool-memory-v2-2-17968f85a464@weissschuh.net> References: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> In-Reply-To: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> To: Josh Poimboeuf , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas =?utf-8?q?Wei=C3=9Fschuh?= X-Mailer: b4 0.11.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1672156865; l=1353; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=s5ecXOvEehEk53y4y2OsKyfg1cQWJRf01QzJ+Hcl4rk=; b=h6yH1/xaYHrNAEVhKJ/pU5PXmhFBqfDVr6QKS8oRm+oyYvouX6nXqdoGXJ0rf3+iCugXF1ms329M 0xIG269CD2SSQp5lQY4O91LF7o7iMBHHTRULpI014EJsmQVcwdRs X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is not used outside of builtin-check.c. Also remove the unused declaration from builtin.h . Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/objtool/builtin-check.c | 2 +- tools/objtool/include/objtool/builtin.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index a4f39407bf59..7c175198d09f 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -65,7 +65,7 @@ static int parse_hacks(const struct option *opt, const ch= ar *str, int unset) return found ? 0 : -1; } =20 -const struct option check_options[] =3D { +static const struct option check_options[] =3D { OPT_GROUP("Actions:"), OPT_CALLBACK_OPTARG('h', "hacks", NULL, NULL, "jump_label,noinstr,skylake= ", "patch toolchain bugs/limitations", parse_hacks), OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"), diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index fa45044e3863..2a108e648b7a 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -7,8 +7,6 @@ =20 #include =20 -extern const struct option check_options[]; - struct opts { /* actions: */ bool dump_orc; --=20 2.39.0 From nobody Tue Sep 16 21:42:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62A28C4167B for ; Tue, 27 Dec 2022 16:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231755AbiL0QDC (ORCPT ); Tue, 27 Dec 2022 11:03:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231502AbiL0QCt (ORCPT ); Tue, 27 Dec 2022 11:02:49 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 195FCF1A for ; Tue, 27 Dec 2022 08:02:47 -0800 (PST) From: Thomas =?utf-8?q?Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1672156964; bh=y+8ND3SPE2pShaR1P8+M7kgXvRP1pJvPmxf10cM5y8Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=B1CyNrKUwOFlrC/zgBHc9Up0AmSlWdkNnf/zucgJzpvF9KscVOFZm+v5sv8KqNX8+ zJDIt/c/lFIz2XKLHYcnLcL0CipdrSUrrdz3v4OKojwRNd4PXb0emo6oWcB34vAlre +x/sKyBaX97HIJX6tO5KNXs8LtnVCgIld5bTNL1o= Date: Tue, 27 Dec 2022 16:00:59 +0000 Subject: [PATCH v2 3/8] objtool: allocate multiple structures with calloc() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221216-objtool-memory-v2-3-17968f85a464@weissschuh.net> References: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> In-Reply-To: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> To: Josh Poimboeuf , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas =?utf-8?q?Wei=C3=9Fschuh?= X-Mailer: b4 0.11.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1672156865; l=3464; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=y+8ND3SPE2pShaR1P8+M7kgXvRP1pJvPmxf10cM5y8Q=; b=bm0NcSswg7oFUqzRMCfQCFgtM2ia9e0hYr/UJH2Ja8VEhCPmcRWUO4dZSpBYyAgPY3kP2q/Xxvf8 FkDHETPnD/lDwkqgNbWghVPYCVeObcNKKSO8u0USlUOGuitMyCGH X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org By using calloc() instead of malloc() in a loop, libc does not have to keep around bookkeeping information for each single structure. This reduces maximum memory usage while processing vmlinux.o from 3153325 KB to 3035668 KB (-3.7%) on my notebooks "localmodconfig". Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/objtool/elf.c | 42 ++++++++++++++++++---------------= ---- tools/objtool/include/objtool/elf.h | 4 ++++ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 7eae95f33a72..9c326efb8cd9 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -285,13 +285,13 @@ static int read_sections(struct elf *elf) !elf_alloc_hash(section_name, sections_nr)) return -1; =20 + elf->section_data =3D calloc(sections_nr, sizeof(*sec)); + if (!elf->section_data) { + perror("calloc"); + return -1; + } for (i =3D 0; i < sections_nr; i++) { - sec =3D malloc(sizeof(*sec)); - if (!sec) { - perror("malloc"); - return -1; - } - memset(sec, 0, sizeof(*sec)); + sec =3D &elf->section_data[i]; =20 INIT_LIST_HEAD(&sec->symbol_list); INIT_LIST_HEAD(&sec->reloc_list); @@ -423,13 +423,13 @@ static int read_symbols(struct elf *elf) !elf_alloc_hash(symbol_name, symbols_nr)) return -1; =20 + elf->symbol_data =3D calloc(symbols_nr, sizeof(*sym)); + if (!elf->symbol_data) { + perror("calloc"); + return -1; + } for (i =3D 0; i < symbols_nr; i++) { - sym =3D malloc(sizeof(*sym)); - if (!sym) { - perror("malloc"); - return -1; - } - memset(sym, 0, sizeof(*sym)); + sym =3D &elf->symbol_data[i]; =20 sym->idx =3D i; =20 @@ -919,13 +919,13 @@ static int read_relocs(struct elf *elf) sec->base->reloc =3D sec; =20 nr_reloc =3D 0; + sec->reloc_data =3D calloc(sec->sh.sh_size / sec->sh.sh_entsize, sizeof(= *reloc)); + if (!sec->reloc_data) { + perror("calloc"); + return -1; + } for (i =3D 0; i < sec->sh.sh_size / sec->sh.sh_entsize; i++) { - reloc =3D malloc(sizeof(*reloc)); - if (!reloc) { - perror("malloc"); - return -1; - } - memset(reloc, 0, sizeof(*reloc)); + reloc =3D &sec->reloc_data[i]; switch (sec->sh.sh_type) { case SHT_REL: if (read_rel_reloc(sec, i, reloc, &symndx)) @@ -1458,16 +1458,16 @@ void elf_close(struct elf *elf) list_for_each_entry_safe(sym, tmpsym, &sec->symbol_list, list) { list_del(&sym->list); hash_del(&sym->hash); - free(sym); } list_for_each_entry_safe(reloc, tmpreloc, &sec->reloc_list, list) { list_del(&reloc->list); hash_del(&reloc->hash); - free(reloc); } list_del(&sec->list); - free(sec); + free(sec->reloc_data); } =20 + free(elf->symbol_data); + free(elf->section_data); free(elf); } diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index bb60fd42b46f..1c90f0ac0d53 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -39,6 +39,7 @@ struct section { char *name; int idx; bool changed, text, rodata, noinstr, init, truncate; + struct reloc *reloc_data; }; =20 struct symbol { @@ -104,6 +105,9 @@ struct elf { struct hlist_head *section_hash; struct hlist_head *section_name_hash; struct hlist_head *reloc_hash; + + struct section *section_data; + struct symbol *symbol_data; }; =20 #define OFFSET_STRIDE_BITS 4 --=20 2.39.0 From nobody Tue Sep 16 21:42:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8152DC46467 for ; Tue, 27 Dec 2022 16:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231840AbiL0QDE (ORCPT ); Tue, 27 Dec 2022 11:03:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231417AbiL0QCt (ORCPT ); Tue, 27 Dec 2022 11:02:49 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9BAEF18 for ; Tue, 27 Dec 2022 08:02:46 -0800 (PST) From: Thomas =?utf-8?q?Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1672156964; bh=XawsrqdClQjkEya+uIP7vjQbb3ysRQ5lLFyEAtEK+X4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lINXVNrUUOk3hwcmjZnbQqmQK+nWm1BcT4cDJEsbYIIzLtmYmF/Pa46Qr/kz4ILKE aIMVVuWkMs85n8wybbHJLPIPfPqJEsNwLInKYqw77S5rV88v2eBaeTtg/42RC+aktE 9Yv1W/0cepNMMrI8WYetZPG6WcPIEyVLUIggI8/s= Date: Tue, 27 Dec 2022 16:01:00 +0000 Subject: [PATCH v2 4/8] objtool: introduce function elf_reloc_set_type MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221216-objtool-memory-v2-4-17968f85a464@weissschuh.net> References: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> In-Reply-To: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> To: Josh Poimboeuf , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas =?utf-8?q?Wei=C3=9Fschuh?= X-Mailer: b4 0.11.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1672156865; l=3243; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=XawsrqdClQjkEya+uIP7vjQbb3ysRQ5lLFyEAtEK+X4=; b=gugRTtsJc0DvdnolPu6136JquZ3HSZXxFn9SkQmu8SbmeCtcWKkUYH2qz4tHTEEZRpry7agDfeVf xZvDrS44Czdh0zzmjTf9DxjCa0HgwUTq3S7H3iJUan4BcdvqDiOC X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org An upcoming patch needs to perform validation when setting reloc->type so introduce a helper to contain this validation. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/objtool/check.c | 6 +++--- tools/objtool/elf.c | 11 ++++++++--- tools/objtool/include/objtool/elf.h | 2 ++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 4350be739f4f..971ee6826de7 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1355,7 +1355,7 @@ static void annotate_call_site(struct objtool_file *f= ile, */ if (opts.hack_noinstr && insn->sec->noinstr && sym->profiling_func) { if (reloc) { - reloc->type =3D R_NONE; + elf_reloc_set_type(reloc, R_NONE); elf_write_reloc(file->elf, reloc); } =20 @@ -1384,7 +1384,7 @@ static void annotate_call_site(struct objtool_file *f= ile, WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset); if (opts.mnop) { if (reloc) { - reloc->type =3D R_NONE; + elf_reloc_set_type(reloc, R_NONE); elf_write_reloc(file->elf, reloc); } =20 @@ -1863,7 +1863,7 @@ static int handle_jump_alt(struct objtool_file *file, struct reloc *reloc =3D insn_reloc(file, orig_insn); =20 if (reloc) { - reloc->type =3D R_NONE; + elf_reloc_set_type(reloc, R_NONE); elf_write_reloc(file->elf, reloc); } elf_write_insn(file->elf, orig_insn->sec, diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 9c326efb8cd9..ee355beb0d82 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -555,7 +555,7 @@ int elf_add_reloc(struct elf *elf, struct section *sec,= unsigned long offset, =20 reloc->sec =3D sec->reloc; reloc->offset =3D offset; - reloc->type =3D type; + elf_reloc_set_type(reloc, type); reloc->sym =3D sym; reloc->addend =3D addend; =20 @@ -872,7 +872,7 @@ static int read_rel_reloc(struct section *sec, int i, s= truct reloc *reloc, unsig WARN_ELF("gelf_getrel"); return -1; } - reloc->type =3D GELF_R_TYPE(reloc->rel.r_info); + elf_reloc_set_type(reloc, GELF_R_TYPE(reloc->rel.r_info)); reloc->addend =3D 0; reloc->offset =3D reloc->rel.r_offset; *symndx =3D GELF_R_SYM(reloc->rel.r_info); @@ -885,7 +885,7 @@ static int read_rela_reloc(struct section *sec, int i, = struct reloc *reloc, unsi WARN_ELF("gelf_getrela"); return -1; } - reloc->type =3D GELF_R_TYPE(reloc->rela.r_info); + elf_reloc_set_type(reloc, GELF_R_TYPE(reloc->rela.r_info)); reloc->addend =3D reloc->rela.r_addend; reloc->offset =3D reloc->rela.r_offset; *symndx =3D GELF_R_SYM(reloc->rela.r_info); @@ -1471,3 +1471,8 @@ void elf_close(struct elf *elf) free(elf->section_data); free(elf); } + +void elf_reloc_set_type(struct reloc *reloc, int type) +{ + reloc->type =3D type; +} diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index 1c90f0ac0d53..33ec6cf72325 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -83,6 +83,8 @@ struct reloc { bool jump_table_start; }; =20 +void elf_reloc_set_type(struct reloc *reloc, int type); + #define ELF_HASH_BITS 20 =20 struct elf { --=20 2.39.0 From nobody Tue Sep 16 21:42:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A25EEC4332F for ; Tue, 27 Dec 2022 16:04:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231689AbiL0QDg (ORCPT ); Tue, 27 Dec 2022 11:03:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231608AbiL0QCv (ORCPT ); Tue, 27 Dec 2022 11:02:51 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9AC860DF for ; Tue, 27 Dec 2022 08:02:49 -0800 (PST) From: Thomas =?utf-8?q?Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1672156966; bh=HMfXPM4QGrr46ln+5URVoZikc1BOiA+8cDROM3xuWNg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EMe/icwpCrtDDLc2F9MA+Ztlf16gn5RUk7Yzc0xtAs8c0WQ9/mir7JknzUycNOhVY Go3Wkg3o0QiBbV0AFrqApoOHeNmo4L9Q+6aZU2svuuG6biaynAGmx5CUmT1C2Vn3Mk GUcU08WMe9YL8M5Pzvdh5qpd5BcA8M6H0J7cNFzk= Date: Tue, 27 Dec 2022 16:01:01 +0000 Subject: [PATCH v2 5/8] objtool: reduce memory usage of struct reloc MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221216-objtool-memory-v2-5-17968f85a464@weissschuh.net> References: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> In-Reply-To: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> To: Josh Poimboeuf , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas =?utf-8?q?Wei=C3=9Fschuh?= X-Mailer: b4 0.11.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1672156865; l=1624; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=HMfXPM4QGrr46ln+5URVoZikc1BOiA+8cDROM3xuWNg=; b=aQ7IAbiGlCMxnLDaQjHg0BDIPnl012xb3SFB40A9z7vKTalZQK3yit84aV22CrH7wWZWCUoqz2Df A6uktE2gA3vVzsVDRuuuZxI3CCC+KycU/RoK1bmhpvzlMS/nRTjE X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use a smaller type for the relocation type and move it to a location in the structure where it avoids wasted padding bytes. Technically ELF could use up to four bytes for the type. But until now only types up to number 43 have been defined. Reduce the size of struct reloc on x86_64 from 120 to 112 bytes. This structure is allocated a lot and never freed. This reduces maximum memory usage while processing vmlinux.o from 3035668 KB to 2919716 KB (-3.8%) on my notebooks "localmodconfig". Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: Rong Tao --- tools/objtool/elf.c | 3 +++ tools/objtool/include/objtool/elf.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index ee355beb0d82..182452adaa71 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -1474,5 +1474,8 @@ void elf_close(struct elf *elf) =20 void elf_reloc_set_type(struct reloc *reloc, int type) { + if (type >=3D (1U << (8 * sizeof(reloc->type)))) + WARN("reloc->type out of range: %d", type); + reloc->type =3D type; } diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index 33ec6cf72325..2b5becad5a0a 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -77,10 +77,10 @@ struct reloc { struct symbol *sym; struct list_head sym_reloc_entry; unsigned long offset; - unsigned int type; s64 addend; int idx; bool jump_table_start; + unsigned char type; }; =20 void elf_reloc_set_type(struct reloc *reloc, int type); --=20 2.39.0 From nobody Tue Sep 16 21:42:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B039BC4708E for ; Tue, 27 Dec 2022 16:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232116AbiL0QDM (ORCPT ); Tue, 27 Dec 2022 11:03:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231593AbiL0QCv (ORCPT ); Tue, 27 Dec 2022 11:02:51 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9A60EA9 for ; Tue, 27 Dec 2022 08:02:49 -0800 (PST) From: Thomas =?utf-8?q?Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1672156966; bh=gxt7wUGYdqW5dnnuQ+NaxVEhN/M72u1992lthLjmCpQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EiXUPHGFDmtPI7cJe3auCz78QEZVKKF7TJace5j4pwj6zMPPa/GLrAThg8QRf45cb CRiY80s8+sLJ68Ia20SlXixIMUM3zT613FRFkUsFCDPdOkxURh1dpVKZVBIdgs0WV6 /f+FEcehsMWpRxT0eX3prW9HW6suMy5Mn2qVygQ4= Date: Tue, 27 Dec 2022 16:01:02 +0000 Subject: [PATCH v2 6/8] objtool: optimize layout of struct symbol MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221216-objtool-memory-v2-6-17968f85a464@weissschuh.net> References: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> In-Reply-To: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> To: Josh Poimboeuf , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas =?utf-8?q?Wei=C3=9Fschuh?= X-Mailer: b4 0.11.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1672156865; l=1055; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=gxt7wUGYdqW5dnnuQ+NaxVEhN/M72u1992lthLjmCpQ=; b=Xsvfu2//FCigo7nfKlub7bHkejf0HGMpbq3HbjfGca8mWRf746ZswAaDkqiJvr95RiP3HIyPAfT+ BjLuHeGpBnQGqMsq+1ETS/WYtzPaT8s4r8ITG7PGAXEO+6sixRQ4 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reduce the size of struct symbol on x86_64 from 208 to 200 bytes. This structure is allocated a lot and never freed. This reduces maximum memory usage while processing vmlinux.o from 2919716 KB to 2917988 KB (-0.5%) on my notebooks "localmodconfig". Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/objtool/include/objtool/elf.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index 2b5becad5a0a..f41573ff1f8b 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -50,12 +50,11 @@ struct symbol { GElf_Sym sym; struct section *sec; char *name; - unsigned int idx; - unsigned char bind, type; + unsigned int idx, len; unsigned long offset; - unsigned int len; unsigned long __subtree_last; struct symbol *pfunc, *cfunc, *alias; + unsigned char bind, type; u8 uaccess_safe : 1; u8 static_call_tramp : 1; u8 retpoline_thunk : 1; --=20 2.39.0 From nobody Tue Sep 16 21:42:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C12CAC4167B for ; Tue, 27 Dec 2022 16:04:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231919AbiL0QDj (ORCPT ); Tue, 27 Dec 2022 11:03:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231615AbiL0QCw (ORCPT ); Tue, 27 Dec 2022 11:02:52 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB755B4A5 for ; Tue, 27 Dec 2022 08:02:49 -0800 (PST) From: Thomas =?utf-8?q?Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1672156966; bh=QPm4tnLN0YjuqSH/PP3qCzyHZ3iKBL4Z+lxmjKe0ykc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=amxlfhy+MP1y275Npt9ETo36B6ozZo8wrqf3cLIUnRWnh5aU4+3JgCtVUlz67HbJc SNMfURiS7WvPlC4nycAu3l22IokTv+O3AeITA8BEBO5hKm0VlTtZdtAA+lpgiGBNjS ymwTaCVLjDuYhA3OCbOkN+74MIr1ZjKSFL4BFLrs= Date: Tue, 27 Dec 2022 16:01:03 +0000 Subject: [PATCH v2 7/8] objtool: optimize layout of struct special_alt MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221216-objtool-memory-v2-7-17968f85a464@weissschuh.net> References: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> In-Reply-To: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> To: Josh Poimboeuf , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas =?utf-8?q?Wei=C3=9Fschuh?= X-Mailer: b4 0.11.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1672156865; l=856; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=QPm4tnLN0YjuqSH/PP3qCzyHZ3iKBL4Z+lxmjKe0ykc=; b=AEnINnK17XKm+Yujt5K8r+9bzPJKBLA6p9hkW6Q/8EnBpM7k5dpJo+bkSc5LsyKIE0kdzZvneyiA y/LDhEoHCEvGfbsR9r1Dv9TtGYQ0LApDEQh27/oX4l9zpodXWlkb X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reduce the size of struct special_alt from 72 to 64 bytes. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/objtool/include/objtool/special.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/objtool/include/objtool/special.h b/tools/objtool/includ= e/objtool/special.h index dc4721e19002..86d4af9c5aa9 100644 --- a/tools/objtool/include/objtool/special.h +++ b/tools/objtool/include/objtool/special.h @@ -19,6 +19,7 @@ struct special_alt { bool skip_orig; bool skip_alt; bool jump_or_nop; + u8 key_addend; =20 struct section *orig_sec; unsigned long orig_off; @@ -27,7 +28,6 @@ struct special_alt { unsigned long new_off; =20 unsigned int orig_len, new_len; /* group only */ - u8 key_addend; }; =20 int special_get_alts(struct elf *elf, struct list_head *alts); --=20 2.39.0 From nobody Tue Sep 16 21:42:43 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDCB0C4332F for ; Tue, 27 Dec 2022 16:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231535AbiL0QCu (ORCPT ); Tue, 27 Dec 2022 11:02:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230209AbiL0QCs (ORCPT ); Tue, 27 Dec 2022 11:02:48 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2F92D73 for ; Tue, 27 Dec 2022 08:02:46 -0800 (PST) From: Thomas =?utf-8?q?Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1672156964; bh=WygJ1LogaMt7MCTVMz5LRPbo5ugX1SmSSa6UqeJvw4g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BoJrCV32q5+ZX9E7hByJLWwo7fCfvpmrC+NI8JWcOJ4OXoeUmNeiVkEBNdl97cP1C fJis5QnFfTipBbfr/kazHgOWmDYa959RnH3GmpbfKBFf9M6NczsoKxwpF+JPI0LJie WZVNrCY9ff0/sfMvuCOLEQSrVuANtVqmphzTycXY= Date: Tue, 27 Dec 2022 16:01:04 +0000 Subject: [PATCH v2 8/8] objtool: explicitly cleanup resources on success MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221216-objtool-memory-v2-8-17968f85a464@weissschuh.net> References: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> In-Reply-To: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> To: Josh Poimboeuf , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas =?utf-8?q?Wei=C3=9Fschuh?= X-Mailer: b4 0.11.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1672156865; l=618; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=WygJ1LogaMt7MCTVMz5LRPbo5ugX1SmSSa6UqeJvw4g=; b=MRmJd1QRpDgL/iIJ/DCBZTdg4HCDjlAvrgtCTCrxDptY+z/uSoHWpLTa0PFHkm8zAL2huAiioeNH ElsMGfVWBLCXo8f9Z0XTYkwtKZVjIAmY8TzWcVqvEtLc+YOAf6Er X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Previously the file was only closed and resources properly freed on errors, not on normal exits. Signed-off-by: Thomas Wei=C3=9Fschuh --- tools/objtool/builtin-check.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 7c175198d09f..e11c766b98ce 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -229,5 +229,7 @@ int objtool_run(int argc, const char **argv) if (file->elf->changed) return elf_write(file->elf); =20 + elf_close(file->elf); + return 0; } --=20 2.39.0