From patchwork Fri Jun 9 07:47:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 105336 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp780975vqr; Fri, 9 Jun 2023 00:58:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ai83EvlDdoRNoxJ0exLX/udwgrRePZsMLB2V5c7oJkyBDxqz4YZ6Y1BYrJmJ67/PYHwDw X-Received: by 2002:a17:903:2301:b0:1b2:4cdc:c4a2 with SMTP id d1-20020a170903230100b001b24cdcc4a2mr434573plh.16.1686297492393; Fri, 09 Jun 2023 00:58:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686297492; cv=none; d=google.com; s=arc-20160816; b=RgI2kN/58R7IuJBVpHjJsA7nDv/LXNkHnXmD+lJXAuOrrz4X12W+TFhyIt4YJNRjEh I+crKce2kGJEjsv0tleEtD9wkliCradG/e15bNfAh87OcBKu26NYHhONF5oUZ46MjHMt niR6s+4wS/I0ZQBUdmv5s4n1x9QvyUoDcHfDF725z86qnLEWTT7NPz4AhsODQdAHkmsk wn2bieJfEZCDWSQzoCWwjGt4P9G8BGgNYWzLETXSpHPJPoMDfrra7R7UGZoaQjsfMdE9 VzVKuktvZG2KID+wp2wq4JxqXNBjet2hkWNCEFa9zqVpM4/8pkK5R7l+hSNr9PBqKuJr VQ0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=vrhZCMplyizefRqS6kdXynqwThRa/YNMtlT+wHVGuCw=; b=S9Ax+1xttYUYcN4dIdxKeqEvmtgb+lIB7cwJ+3HH47eZbygtok+yOH732Jv0jPIe1y 94Ie40cUeW4JPHEVt3CTozQLJKWUbVwPn4wUqBW1+k0edJux6u9k9aORXe2zqmHTLlYU aK5AKqJytwnrPxyqSYfV9Mska9teI543HMzlqTeU4hJHsC8eDUNPPIfvzpTIeEHXfoud E9+T+dpQS/jO236R7Hw3u2R+NP3l+NLr+feeknkkso0lYI84gjDY/ct0Zbh/9OzSvjmX s7NDHFLiIVQgSAfyvCrhCEccSca//+dP8jw7qH0YHKryBlOjTTvzUqMfEl5SJD0FfcGz +3mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Pht3l2pB; dkim=neutral (no key) header.i=@linutronix.de header.b="/PgHlsoE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k1-20020a170902ba8100b001b046acc853si2222556pls.589.2023.06.09.00.57.59; Fri, 09 Jun 2023 00:58:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Pht3l2pB; dkim=neutral (no key) header.i=@linutronix.de header.b="/PgHlsoE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239237AbjFIHtE (ORCPT + 99 others); Fri, 9 Jun 2023 03:49:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239107AbjFIHrp (ORCPT ); Fri, 9 Jun 2023 03:47:45 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED7072121; Fri, 9 Jun 2023 00:47:42 -0700 (PDT) Date: Fri, 09 Jun 2023 07:47:36 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686296857; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vrhZCMplyizefRqS6kdXynqwThRa/YNMtlT+wHVGuCw=; b=Pht3l2pBJv3GF+SMMG8D+tb5N40hTJLW3URgMH0s43iVuvufqfaQ1qp5/XGKI61oauWsOm nNVwkVAJe4FjpT1v0XlcYcZmpBBGu0P3OocylnOweJ2ejCUlO0QcwNC9k3Yw8+/667AR/2 AF6ldbkp0EHpw5PteDMu6W+z1s5gIwDdO3Z6a4khaVbscD1snUSDy4afj8Y2EVqIY0P5C0 o+9LQegbX3OHb3GJ646C6ejzbVsMYXvLz/7xADj/ub1f0706FhyTGLGCe9SF6FTl447oIC a7SX+u3Rnp+SZAk5CJnFyry+MxwQr/tzwLy5pc7b9nL+UgiBi8o6GckkQZ9Qbg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686296857; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vrhZCMplyizefRqS6kdXynqwThRa/YNMtlT+wHVGuCw=; b=/PgHlsoEuZWefg+wR6j1GmEVmWqyI6BqTy28gdlEOJO+1ce/vPyYFkBupoo3djgcUHxgkl PTLBsoMYE3Ud1FCQ== From: "tip-bot2 for Josh Poimboeuf" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/core] objtool: Fix reloc_hash size Cc: Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <38ef60dc8043270bf3b9dfd139ae2a30ca3f75cc.1685464332.git.jpoimboe@kernel.org> References: <38ef60dc8043270bf3b9dfd139ae2a30ca3f75cc.1685464332.git.jpoimboe@kernel.org> MIME-Version: 1.0 Message-ID: <168629685671.404.3682740079672959168.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767340659626737525?= X-GMAIL-MSGID: =?utf-8?q?1768211079254513674?= The following commit has been merged into the objtool/core branch of tip: Commit-ID: eb0481bbc4ce386e73e28ad8590b4f12c8aded56 Gitweb: https://git.kernel.org/tip/eb0481bbc4ce386e73e28ad8590b4f12c8aded56 Author: Josh Poimboeuf AuthorDate: Tue, 30 May 2023 10:20:57 -07:00 Committer: Josh Poimboeuf CommitterDate: Wed, 07 Jun 2023 10:03:16 -07:00 objtool: Fix reloc_hash size With CONFIG_DEBUG_INFO, DWARF creates a lot of relocations and reloc_hash is woefully undersized, which can affect performance significantly. Fix that. Link: https://lore.kernel.org/r/38ef60dc8043270bf3b9dfd139ae2a30ca3f75cc.1685464332.git.jpoimboe@kernel.org Signed-off-by: Josh Poimboeuf --- tools/objtool/elf.c | 16 +++++++--------- tools/objtool/include/objtool/elf.h | 8 +++++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 4bbdd8e..f72ec6d 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -328,12 +328,12 @@ static int read_sections(struct elf *elf) } } - if (sec->sh.sh_flags & SHF_EXECINSTR) - elf->text_size += sec->sh.sh_size; - list_add_tail(&sec->list, &elf->sections); elf_hash_add(section, &sec->hash, sec->idx); elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name)); + + if (is_reloc_sec(sec)) + elf->num_relocs += sec->sh.sh_size / sec->sh.sh_entsize; } if (opts.stats) { @@ -888,19 +888,18 @@ static int read_reloc(struct section *rsec, int i, struct reloc *reloc) static int read_relocs(struct elf *elf) { - unsigned long nr_reloc, max_reloc = 0, tot_reloc = 0; + unsigned long nr_reloc, max_reloc = 0; struct section *rsec; struct reloc *reloc; unsigned int symndx; struct symbol *sym; int i; - if (!elf_alloc_hash(reloc, elf->text_size / 16)) + if (!elf_alloc_hash(reloc, elf->num_relocs)) return -1; list_for_each_entry(rsec, &elf->sections, list) { - if ((rsec->sh.sh_type != SHT_RELA) && - (rsec->sh.sh_type != SHT_REL)) + if (!is_reloc_sec(rsec)) continue; rsec->base = find_section_by_index(elf, rsec->sh.sh_info); @@ -942,12 +941,11 @@ static int read_relocs(struct elf *elf) nr_reloc++; } max_reloc = max(max_reloc, nr_reloc); - tot_reloc += nr_reloc; } if (opts.stats) { printf("max_reloc: %lu\n", max_reloc); - printf("tot_reloc: %lu\n", tot_reloc); + printf("num_relocs: %lu\n", elf->num_relocs); printf("reloc_bits: %d\n", elf->reloc_bits); } diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h index 6f82f25..b81d78b 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -90,8 +90,9 @@ struct elf { int fd; bool changed; char *name; - unsigned int text_size, num_files; + unsigned int num_files; struct list_head sections; + unsigned long num_relocs; int symbol_bits; int symbol_name_bits; @@ -158,6 +159,11 @@ static inline size_t elf_rela_size(struct elf *elf) return elf_addr_size(elf) == 4 ? sizeof(Elf32_Rela) : sizeof(Elf64_Rela); } +static inline bool is_reloc_sec(struct section *sec) +{ + return sec->sh.sh_type == SHT_RELA || sec->sh.sh_type == SHT_REL; +} + #define for_each_sec(file, sec) \ list_for_each_entry(sec, &file->elf->sections, list)