From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793816491; b=IHms1WddoTOiCToBkkN0dO9U7vWjqXLl7tyEMerJ03G6dcseziJxxrZB7/w6R6kWGog4 0+MWKmv4bFP0SXiLtsiaDO0izCY7ChCoJVYbsv+JFbWWLCZoviEjIN5lR0ZUn0V0zRXx0 o4b1FLkbMc6UOBEHjXV3lJyLyr9RUSue7REQLULnVSMAah757d0vPGWZHKXzpRz8C90Cr 8ecSNdt+x8+iSWYjrVnb7NaUC6H2J9x0byDiX6/hoedfmowfxM4orgRlNj2ndnbvm6Lf4 H2TM9O9yHj40bgG7dnBHUDPsvyII3BbLHImabRF3REMyp29J+dVgDCr5zmKm8g/9PyQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793816491; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=JePMCfKku9pEUDTHsAhZnlP/cQPhOTSidIJ9IlFtxng=; b=cGhm0u3f3Sgqa/bE6haUqBQAr+yXRh2UldRFhr8bYBBwcIOCvUXVeUoXs0b4hatoY4Sp iztkB/YjAciYcjLHLB8dNb6+cezpwh3ahehc4WIsq8hrTiakRHkpVzxvJh/3kZ4ZurSGy Do9YZS4/+rSZMPcjTWpbU47u7g0oRZyq0Kh82ufvHpU0xfSgC512oJb2cVYIlvFQXRUzv z9IHQaKUL0ADAaBFq+V7+SS10CSB1S4fW4fyPVt7P9AJGVBmWbF1Y/vf+L4KiZ3ANvQuT Al9AiQI3s+Z0z/HSMEMbGJP/tF2yELqejWdsEEzSnn3XUy559y0izWYfeNNELk/RPCQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oEqSqtuf; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1BFF607BCA5; Wed, 4 Nov 2026 18:21:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oEqSqtuf Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72B831F0180E; Wed, 4 Nov 2026 18:21:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793816490; bh=JePMCfKku9pEUDTHsAhZnlP/cQPhOTSidIJ9IlFtxng=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=oEqSqtuf3dQOGOF8fH7u936/F2G7Cgctm+FulpT4YWeG09bwZMpVbHKheBVML2qCg CivgxtItI//tYy8SEMWoJz13mF7ZxJHSJaxvF7x6p8g3eRk2rIy6D+URLkeRCQnNkR KNkIvppr4B6Y6UoYda6BbXkVlBDgmKM4EgJ7M5RTQGKCoUmHvoiHF2vFE5vee/JZTM 3PTMNnOt6qNHDgCFQ7Zr3oUtwP+PAcE/N1arv3UrAqW+sZbVQNEdj3pvZVZlatjjIX 8ExZfQDbyCr4pqUuyYfLvjjIQ5Gfi/wktxj6IxLJJFj9xR/XVZ3Xm4nHywmI0Z0K5v puqwUOgEprupA== From: "Lorenzo Stoakes (ARM)" Date: Wed, 04 Nov 2026 18:20:24 +0000 Subject: [PATCH v5 06/11] objtool: do not hash DWARF relocations X-Mailing-List: linux-modules@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261104-build-speedup-v5-6-0f6018be8dae@kernel.org> References: <20261104-build-speedup-v5-0-0f6018be8dae@kernel.org> In-Reply-To: <20261104-build-speedup-v5-0-0f6018be8dae@kernel.org> To: Linus Torvalds , Nathan Chancellor , Nicolas Schier , Nick Desaulniers , Bill Wendling , Justin Stitt , Geert Uytterhoeven , Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Josh Poimboeuf , Peter Zijlstra , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= Cc: ljs@kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3375; i=ljs@kernel.org; h=from:subject:message-id; bh=aMXclC3dToXuPw8amRZ/vPdHrAbL7HmKgomYoAoiYOU=; b=owGbwMvMwCV2fu7ZrsZH9SKMp9WSGLJel+fKZkToeSc89FulWqB6tlet4LVrj7hVydopnVH+b +OmfLfvKGVhEONikBVTZHn+RXx/kEjYvM4L/m4wc1iZQIYwcHEKwETYpBj+adX5apU++huh8eDQ idrntcIa/cu3vHJkNNJsz3c5Ocv7GMP/QMe9nRIMtzVqfX6XnSuI5wtkNp++UMq5sm6vqNjZzIv cAA== X-Developer-Key: i=ljs@kernel.org; a=openpgp; fpr=E7F417BF5214569E89D04F46CF9DCD8A81E27F14 objtool hashes the relocation of each section so it can find them by destination, but DWARF sections are never looked up this way, so there is no reason to hash them. With CONFIG_DEBUG_INFO_DWARF5 set a defconfig vmlinux.o has ~22 million relocations, 20.5 million of which are .debug_* sections. Therefore, don't hash these. With the same configuration the objtool vmlinux.o link-time run takes ~.5s less to complete (2.63s -> 2.14s) and ~130 MiB memory to do it. The output remains unchanged. Signed-off-by: Lorenzo Stoakes (ARM) --- tools/objtool/elf.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index a791f4ea6ec1..98a110e3e8f5 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -1071,7 +1071,8 @@ struct reloc *elf_init_reloc(struct elf *elf, struct section *rsec, set_reloc_type(elf, reloc, type); set_reloc_addend(elf, reloc, addend); - elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc)); + if (!is_dwarf_section(rsec->base)) + elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc)); set_sym_next_reloc(reloc, sym->relocs); sym->relocs = reloc; @@ -1125,16 +1126,14 @@ struct reloc *elf_init_reloc_data_sym(struct elf *elf, struct section *sec, static int read_relocs(struct elf *elf) { - unsigned long nr_reloc, max_reloc = 0; + unsigned long nr_reloc, max_reloc = 0, nr_hashed = 0; struct section *rsec; struct reloc *reloc; unsigned int symndx; struct symbol *sym; + bool hashed; int i; - if (!elf_alloc_hash(reloc, elf->num_relocs)) - return -1; - list_for_each_entry(rsec, &elf->sections, list) { if (!is_reloc_sec(rsec)) continue; @@ -1147,6 +1146,23 @@ static int read_relocs(struct elf *elf) rsec->base->rsec = rsec; + /* + * DWARF relocations are never looked up by destination, they + * only need to be on their symbol's list. + */ + if (!is_dwarf_section(rsec->base)) + nr_hashed += sec_num_entries(rsec); + } + + if (!elf_alloc_hash(reloc, nr_hashed)) + return -1; + + list_for_each_entry(rsec, &elf->sections, list) { + if (!is_reloc_sec(rsec)) + continue; + + hashed = !is_dwarf_section(rsec->base); + /* nr_alloc_relocs=0: libelf owns d_buf */ rsec->nr_alloc_relocs = 0; @@ -1168,7 +1184,8 @@ static int read_relocs(struct elf *elf) return -1; } - elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc)); + if (hashed) + elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc)); set_sym_next_reloc(reloc, sym->relocs); sym->relocs = reloc; @@ -1180,6 +1197,7 @@ static int read_relocs(struct elf *elf) if (opts.stats) { printf("max_reloc: %lu\n", max_reloc); printf("num_relocs: %lu\n", elf->num_relocs); + printf("num_relocs_hashed: %lu\n", nr_hashed); printf("reloc_bits: %d\n", elf->reloc_bits); } @@ -1634,7 +1652,7 @@ static int elf_alloc_reloc(struct elf *elf, struct section *rsec) memcpy(new_relocs, old_relocs, nr_relocs_old * sizeof(struct reloc)); - for (int i = 0; i < nr_relocs_old; i++) { + for (int i = 0; i < nr_relocs_old && !is_dwarf_section(rsec->base); i++) { struct reloc *old = &old_relocs[i]; struct reloc *new = &new_relocs[i]; u32 key = reloc_hash(old); -- 2.56.0