From nobody Tue Dec 16 16:41:25 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 6BCA3C001B0 for ; Tue, 15 Aug 2023 10:36:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236457AbjHOKgC (ORCPT ); Tue, 15 Aug 2023 06:36:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236455AbjHOKfi (ORCPT ); Tue, 15 Aug 2023 06:35:38 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E37D1987 for ; Tue, 15 Aug 2023 03:35:37 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2FB7F1F38D; Tue, 15 Aug 2023 10:35:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1692095736; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=EHgfTGo331RLPVXZ/xeaNmO0JfnBMv1OFCIB4OSMpaI=; b=AkmIWBonKT9ykk3UUPcpUDx195hMy33WNcKCSEeZ9xNZDIIXOtljlZwP5jaZn4XvDILP3p ESgyKkN+PtUDGxFhhQ5XP0zKms/O/IzGy5jQT9OGezJNpVV7O98WIhCAXRk+fwrtP5cToo W+UrQgJ1y87sAbc5g26yZreV3LTV+Ps= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B09D213909; Tue, 15 Aug 2023 10:35:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id dRnGJvdU22SjXgAAMHmgww (envelope-from ); Tue, 15 Aug 2023 10:35:35 +0000 From: Nikolay Borisov To: Josh Poimboeuf , Peter Zijlstra , linux-kernel@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH] objtool: Cache number of return sites recorded Date: Tue, 15 Aug 2023 13:35:09 +0300 Message-Id: <20230815103509.309443-1-nik.borisov@suse.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" On an allyesconfig currently the kernels emits 454324. No point in making around half a million iterations just to count them. Simply increment a counter at the time of creation of each site. Quick measurements shows a meager 200ms improvement when running objtool --rethunk --prefix=3D64 --no-unreachable --stats --link Signed-off-by: Nikolay Borisov --- tools/objtool/check.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 8936a05f0e5a..bb71c5d8859f 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -33,6 +33,7 @@ static struct cfi_init_state initial_func_cfi; static struct cfi_state init_cfi; static struct cfi_state func_cfi; static struct cfi_state force_undefined_cfi; +static unsigned long nr_rethunk_sites; =20 struct instruction *find_insn(struct objtool_file *file, struct section *sec, unsigned long offset) @@ -802,15 +803,12 @@ static int create_return_sites_sections(struct objtoo= l_file *file) return 0; } =20 - idx =3D 0; - list_for_each_entry(insn, &file->return_thunk_list, call_node) - idx++; - - if (!idx) + if (!nr_rethunk_sites) return 0; =20 sec =3D elf_create_section_pair(file->elf, ".return_sites", - sizeof(int), idx, idx); + sizeof(int), nr_rethunk_sites, + nr_rethunk_sites); if (!sec) return -1; =20 @@ -1473,8 +1471,10 @@ static void add_return_call(struct objtool_file *fil= e, struct instruction *insn, insn->type =3D INSN_RETURN; insn->retpoline_safe =3D true; =20 - if (add) + if (add) { list_add_tail(&insn->call_node, &file->return_thunk_list); + nr_rethunk_sites++; + } } =20 static bool is_first_func_insn(struct objtool_file *file, --=20 2.34.1