Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp3364722rwl; Tue, 27 Dec 2022 08:06:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXssu1Bwa7Kcq19FVxAOGXCx2Qy0QW635AkcwbpEnMIkiRht+RDED6bhNSIrhE/I9eu7OFar X-Received: by 2002:a50:9f09:0:b0:467:4df0:718c with SMTP id b9-20020a509f09000000b004674df0718cmr18990115edf.9.1672157211884; Tue, 27 Dec 2022 08:06:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672157211; cv=none; d=google.com; s=arc-20160816; b=xB6wzGagzhsdbsMkshtm62On1LaRGnCNQzlDl+6oLam9J1uw1mYOqXAC1TcCNOuTH2 8dTPfvziGoX4DyQ2jzBjuX+h8ePOiNHQGRGtxyCKPkAgVEX2fsh0NVrK39FzTNM+3enK WtuII071mxawztqaxEgoaoNVZXoZ/MytKsGPCaosdt5JWOHEHjNPJUZM3JIixv0RuBzY xD2OSEoAgIGeunqld4P5/RBaalZzlJbIvVjmJk/4QHZzLV01gk2yp6mKIi5O17mBhCCp FKkSAlwTJb97+Ffrijjn5k2xhEVcz/pY012Y40ofDKRGockojENtOZx9euQovZF8kLDO wvEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:dkim-signature :from; bh=UPKYUXhz5W0OEToyOJwznXcU5mqY9LQXhFytpkfal5k=; b=LvlcZ5LhZ09iYuQxPHNMtTxZRX+7+G4BGCQ4etZ7NJmMiG+C8qOIYQQXSoblHGBIjs 2o0w3Rx78AuPXjg5j3WTHmOHOfOhmz7oaAjCLWXVI+0aDAC86nnkzbEPHvB6T+Yj7hSz YHFXg9o2W53hjMU4JXlreSyzgFVl/uSBOsZ8Zm27u+SPCi7EYqnmERY1QZ6ExkwDEWtk krCkbK6HqBYS/HLLioZqVbfRXBrP3RCnLPf1NXfhQsRbbVKtIH6f6BRKRDyxQH8PgANA dfscge3Q4GSMi0G4SO8iC4WHf/gn6AN8osGxGKNe65IH2q+VvLdwtCaj5J+0bUfz47lQ 4YQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@weissschuh.net header.s=mail header.b="EMe/icwp"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o25-20020aa7c519000000b004865244368fsi2792604edq.334.2022.12.27.08.06.33; Tue, 27 Dec 2022 08:06:51 -0800 (PST) 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=fail header.i=@weissschuh.net header.s=mail header.b="EMe/icwp"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231417AbiL0QDc (ORCPT + 66 others); Tue, 27 Dec 2022 11:03:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231608AbiL0QCv (ORCPT ); Tue, 27 Dec 2022 11:02:51 -0500 Received: from todd.t-8ch.de (todd.t-8ch.de [IPv6:2a01:4f8:c010:41de::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9AC860DF for ; Tue, 27 Dec 2022 08:02:49 -0800 (PST) From: Thomas =?utf-8?q?Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=weissschuh.net; s=mail; t=1672156966; bh=HMfXPM4QGrr46ln+5URVoZikc1BOiA+8cDROM3xuWNg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EMe/icwpCrtDDLc2F9MA+Ztlf16gn5RUk7Yzc0xtAs8c0WQ9/mir7JknzUycNOhVY Go3Wkg3o0QiBbV0AFrqApoOHeNmo4L9Q+6aZU2svuuG6biaynAGmx5CUmT1C2Vn3Mk GUcU08WMe9YL8M5Pzvdh5qpd5BcA8M6H0J7cNFzk= Date: Tue, 27 Dec 2022 16:01:01 +0000 Subject: [PATCH v2 5/8] objtool: reduce memory usage of struct reloc MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-Id: <20221216-objtool-memory-v2-5-17968f85a464@weissschuh.net> References: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> In-Reply-To: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net> To: Josh Poimboeuf , Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas =?utf-8?q?Wei=C3=9Fschuh?= X-Mailer: b4 0.11.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1672156865; l=1624; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=HMfXPM4QGrr46ln+5URVoZikc1BOiA+8cDROM3xuWNg=; b=aQ7IAbiGlCMxnLDaQjHg0BDIPnl012xb3SFB40A9z7vKTalZQK3yit84aV22CrH7wWZWCUoqz2Df A6uktE2gA3vVzsVDRuuuZxI3CCC+KycU/RoK1bmhpvzlMS/nRTjE X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,SPF_HELO_NONE,SPF_PASS autolearn=no 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 Use a smaller type for the relocation type and move it to a location in the structure where it avoids wasted padding bytes. Technically ELF could use up to four bytes for the type. But until now only types up to number 43 have been defined. Reduce the size of struct reloc on x86_64 from 120 to 112 bytes. This structure is allocated a lot and never freed. This reduces maximum memory usage while processing vmlinux.o from 3035668 KB to 2919716 KB (-3.8%) on my notebooks "localmodconfig". Signed-off-by: Thomas Weißschuh --- tools/objtool/elf.c | 3 +++ tools/objtool/include/objtool/elf.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index ee355beb0d82..182452adaa71 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -1474,5 +1474,8 @@ void elf_close(struct elf *elf) void elf_reloc_set_type(struct reloc *reloc, int type) { + if (type >= (1U << (8 * sizeof(reloc->type)))) + WARN("reloc->type out of range: %d", type); + reloc->type = type; } diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h index 33ec6cf72325..2b5becad5a0a 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -77,10 +77,10 @@ struct reloc { struct symbol *sym; struct list_head sym_reloc_entry; unsigned long offset; - unsigned int type; s64 addend; int idx; bool jump_table_start; + unsigned char type; }; void elf_reloc_set_type(struct reloc *reloc, int type); -- 2.39.0