From patchwork Fri Jun 9 07:47:32 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: 105341 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp781173vqr; Fri, 9 Jun 2023 00:58:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4agZZvLoHqmSfuI6FqRiVdFomrLSnhE7eyUc8dPwo2UujGzlFpcj/Mw7Qm93FrD81It5TO X-Received: by 2002:a05:6a00:399f:b0:662:c4ca:65c2 with SMTP id fi31-20020a056a00399f00b00662c4ca65c2mr436858pfb.0.1686297522466; Fri, 09 Jun 2023 00:58:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686297522; cv=none; d=google.com; s=arc-20160816; b=vsKeLHLlueU1AAGc3QsNfXdPr7fQ2jba9PypgZFioWzLGrCzjS7FWdlDKDrTrrMPX0 m9cLycTf7hNAyDVJVDhNRiEyhMkl6bxzavj8zW36uF4fRTfB5eQsTcXoVVX7Im8NSozB VmukJ9LAmVQzhyZ9siWpua1EyUh6rZSFvQ8/iQW4aqhRLDasO9EtuO3+iqnSgo+HfMjQ UFVLI0KsvN3JRImAG1ydeGH4Rp5QEB3Op5jztbRBioqhC5S9B1sUffRviXvSegMTJSBT YORIy2ka1SWmihNX7dt5aluXXSOZz+Dsg0oxCdx3MCa5VnanR/i/hU8Gnyp/o4Bqd7hi jO4A== 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=706pUqJ1rxVQuZQlYVkYva1NebzBF1ueHcAL4F1w4kg=; b=FPumvaA78FwCrzlAyL9Hwvi47GWgIKW+Umd+Fv/l9CmEAvgjaOBOaYtekXzIm0bqti D+ka8Of3yMA732NmKTeFstY2Ie3OGS/qjl4ZrCYC7yPqmDZTkuLw/iB6fqmjOFCq0SQc Nv3DpIclw6qpq1DmXh8yrK1C0Dj2RfryEkQhMUGt26NHDf8ockR6PFK9VunTJ+xmrlss icanLr1Oq5j4S76I3Zprn8S45SXMlF2tv3X/08YSPEoWvDBxpk566pAGbjM/A66zhFAW SM69my92WQVdWq2zeKCXqCD1z72CHazk0meZ2od9lkSzii46dpKV8748PFrxZ9HjBNba reJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=215sTCQ5; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 s20-20020a056a00195400b0064d6c74a8bbsi2226950pfk.98.2023.06.09.00.58.30; Fri, 09 Jun 2023 00:58:42 -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=215sTCQ5; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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 S239263AbjFIHsW (ORCPT + 99 others); Fri, 9 Jun 2023 03:48:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239057AbjFIHrm (ORCPT ); Fri, 9 Jun 2023 03:47:42 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E0E530F5; Fri, 9 Jun 2023 00:47:40 -0700 (PDT) Date: Fri, 09 Jun 2023 07:47:32 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686296853; 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=706pUqJ1rxVQuZQlYVkYva1NebzBF1ueHcAL4F1w4kg=; b=215sTCQ5yYQdwnrjV9K5sqr5mwxgfpm4IZjge0cDksEfGbc2Z4PG5ZPcFfSxZ+i5fhZ7zI UxemA1uUMvuLaYlCzgc0IgpgeS4vNc1ORCO33SrHtnNfsge33+At4fMqo5IVHw7sPp+hh2 HneFmBpNDSj8Eh/MmHIcZQQlgwBzmEYZt/AIGHQBTdifkXIAopRf7B0DTJOQQUjd6qnlo9 DaHW9WP+bQ5viAO8Zdmu07sNxQZ/RwgmrmU2A4By0gbFgVZgISqL1pfX8qdLFEYXUrDQzV qjivYeaGovhgCY5yDbrOy+JzX7PsvESrbTg4cjaUSEwF4f3HT4hQZPNSQkodZA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686296853; 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=706pUqJ1rxVQuZQlYVkYva1NebzBF1ueHcAL4F1w4kg=; b=PpGYaGTavtDzCm7x+v3ANT46XbkAkvDgE/7qxEhx4KUyNAXyPme/2uvWSr68EwXj35EW+A /J6drpHvggtJO9Bg== 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: Allocate relocs in advance for new rela sections Cc: Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <5332d845c5a2d6c2d052075b381bfba8bcb67ed5.1685464332.git.jpoimboe@kernel.org> References: <5332d845c5a2d6c2d052075b381bfba8bcb67ed5.1685464332.git.jpoimboe@kernel.org> MIME-Version: 1.0 Message-ID: <168629685285.404.18154288626119314332.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?1767340683841158079?= X-GMAIL-MSGID: =?utf-8?q?1768211110839214126?= The following commit has been merged into the objtool/core branch of tip: Commit-ID: e0a9349b4c590145c6a83e6c9f7701cec42debbd Gitweb: https://git.kernel.org/tip/e0a9349b4c590145c6a83e6c9f7701cec42debbd Author: Josh Poimboeuf AuthorDate: Tue, 30 May 2023 10:21:03 -07:00 Committer: Josh Poimboeuf CommitterDate: Wed, 07 Jun 2023 10:03:20 -07:00 objtool: Allocate relocs in advance for new rela sections Similar to read_relocs(), allocate the reloc structs all together in an array rather than allocating them one at a time. Link: https://lore.kernel.org/r/5332d845c5a2d6c2d052075b381bfba8bcb67ed5.1685464332.git.jpoimboe@kernel.org Signed-off-by: Josh Poimboeuf --- tools/objtool/elf.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 8d53f18..5f69d45 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -814,7 +814,7 @@ static struct reloc *elf_init_reloc(struct elf *elf, struct section *rsec, unsigned long offset, struct symbol *sym, s64 addend, unsigned int type) { - struct reloc *reloc; + struct reloc *reloc, empty = { 0 }; if (reloc_idx >= rsec->sh.sh_size / elf_rela_size(elf)) { WARN("%s: bad reloc_idx %u for %s with size 0x%lx", @@ -822,12 +822,13 @@ static struct reloc *elf_init_reloc(struct elf *elf, struct section *rsec, return NULL; } - reloc = malloc(sizeof(*reloc)); - if (!reloc) { - perror("malloc"); + reloc = &rsec->reloc_data[reloc_idx]; + + if (memcmp(reloc, &empty, sizeof(empty))) { + WARN("%s: %s: reloc %d already initialized!", + __func__, rsec->name, reloc_idx); return NULL; } - memset(reloc, 0, sizeof(*reloc)); reloc->idx = reloc_idx; reloc->sec = rsec; @@ -1185,6 +1186,13 @@ static struct section *elf_create_rela_section(struct elf *elf, rsec->sh.sh_info = sec->idx; rsec->sh.sh_flags = SHF_INFO_LINK; + rsec->reloc_data = calloc(rsec->sh.sh_size / rsec->sh.sh_entsize, + sizeof(struct reloc)); + if (!rsec->reloc_data) { + perror("calloc"); + return NULL; + } + sec->rsec = rsec; rsec->base = sec;