From nobody Sun Feb 8 10:04:10 2026 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 DE739C7EE24 for ; Tue, 30 May 2023 17:22:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233291AbjE3RWU (ORCPT ); Tue, 30 May 2023 13:22:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232964AbjE3RVk (ORCPT ); Tue, 30 May 2023 13:21:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D2D1F3 for ; Tue, 30 May 2023 10:21:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 77EEF63104 for ; Tue, 30 May 2023 17:21:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B477DC4339E; Tue, 30 May 2023 17:21:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685467295; bh=5bKLUxUNwXL7zbFSdm1bk4h9wh+okZrHItfELV5Rer8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sDI8gjeyCx8VJZPs5/Q+PYBmp/xKv0tWOcR7wXGh52Nysw5W4vbK87wbGXynvcBV0 L+xaZ2Jz/MogFnOZ/fkKdm/BnHPFkYTiz4OarWEswn/W9C4RGOlf5AVpDv/Sgw8hRn J67seHDmXbTJPpjmx1g5nFzVytRSrgB5iQTNsz7Trtcz7s4OKHA24AeaMW1kU665+J ltZSMJMbsEGwceccQ7donK1Yir8UNleyR1Jz28hjmr8hto0W2JqzrVxQxcLAhByqXK f01AOv8QIi5t03mrjbNodPmY1XQ785vNu+SEQtpq+kAJ03KUZ7cwK4KMbJ7RXUah63 y+m0jEUmFzTgw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH 11/22] objtool: Allocate relocs in advance for new rela sections Date: Tue, 30 May 2023 10:21:03 -0700 Message-Id: <5332d845c5a2d6c2d052075b381bfba8bcb67ed5.1685464332.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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" Similar to read_relocs(), allocate the reloc structs all together in an array rather than allocating them one at a time. 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 8d53f18a9502..5f69d4590117 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -814,7 +814,7 @@ static struct reloc *elf_init_reloc(struct elf *elf, st= ruct section *rsec, unsigned long offset, struct symbol *sym, s64 addend, unsigned int type) { - struct reloc *reloc; + struct reloc *reloc, empty =3D { 0 }; =20 if (reloc_idx >=3D 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; } =20 - reloc =3D malloc(sizeof(*reloc)); - if (!reloc) { - perror("malloc"); + reloc =3D &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)); =20 reloc->idx =3D reloc_idx; reloc->sec =3D rsec; @@ -1185,6 +1186,13 @@ static struct section *elf_create_rela_section(struc= t elf *elf, rsec->sh.sh_info =3D sec->idx; rsec->sh.sh_flags =3D SHF_INFO_LINK; =20 + rsec->reloc_data =3D calloc(rsec->sh.sh_size / rsec->sh.sh_entsize, + sizeof(struct reloc)); + if (!rsec->reloc_data) { + perror("calloc"); + return NULL; + } + sec->rsec =3D rsec; rsec->base =3D sec; =20 --=20 2.40.1