From patchwork Tue May 30 17:20:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Poimboeuf X-Patchwork-Id: 10056 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2344042vqr; Tue, 30 May 2023 10:30:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ74o+diCO+zpkEYzEtg5zUBbz+0Brtpma8Hw9sjtsw1r7VyS5ItGOmLUhWBw5EhaV17Fbs4 X-Received: by 2002:a17:90a:8f03:b0:256:8065:6a4c with SMTP id g3-20020a17090a8f0300b0025680656a4cmr3370867pjo.23.1685467848423; Tue, 30 May 2023 10:30:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685467848; cv=none; d=google.com; s=arc-20160816; b=K3JRLvaueSxIcnelyfHyufh4bTehUOwkXQi/vvtG950SXRKAl/OTsCnjIf5MWihi6y a4bLP6ppRz3jarKOmkWYpvNb+vmVvBwT6luVBYqkhjjQ6HR872cL0jViRWRwyv3HNpqX XwXS5QtTLoMaxt7q/kUTnSIn2wFA6Qm+Ex0M1g9NgSU1ijeUcWjDG2lnkj/+yQdNFCQk QBwtMBqujnXXvMs9HGlYoQm3B2Hkq1+dJjQY9HKFYXIlAEKkvh8n1FuhLmtvDV4HDsXO OpTtC9WeBDAyO9LprZZEGvevGyHGoo49x1TiXWcrD5iMWahADPzzeCpMi65du/S5eg9/ h9WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=jOUn1S4gTbtQeg5uTpqXlPU8H6iJdkSTuol0/iJZW9Y=; b=iVT97q3Wq0KI4Lc6WqXwEIqHknPtv5/Q/OFQqzIBqnHuMWl3krQu0E8Cf1T1QeGkqR MjGMG+PaSr7gnZHIz4tIdR733rxqCnzEBRfh9lajpmyMVcDVoUESzNh1owNS/buxFQiO 1H7+m7pnGMQ3S2GnhcC0QdGCE5ChQ6x6JO2l97pFiX8u7usdpPgUydPbvJdS+woCbIwI p3hcrdkqCi6okFh6/nBPTG/6R3crAo03QNFYphAfRQd6RmJTlCO+TFNSJ/c5Cqn/7pSS 16YLlAHLffpMgcnSSDFKQzlJzp1oAGVyJqXHDpwLYTrYbzKc9DpW2oMm1lLpmqHSwJTY eVrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ld4IKAPw; 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=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 11-20020a17090a194b00b002535fa552f2si1900608pjh.85.2023.05.30.10.30.33; Tue, 30 May 2023 10:30:48 -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=@kernel.org header.s=k20201202 header.b=ld4IKAPw; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232005AbjE3RVg (ORCPT + 99 others); Tue, 30 May 2023 13:21:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230479AbjE3RVe (ORCPT ); Tue, 30 May 2023 13:21:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F195DA3 for ; Tue, 30 May 2023 10:21:32 -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 8E66F630DB for ; Tue, 30 May 2023 17:21:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDB40C433D2; Tue, 30 May 2023 17:21:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685467291; bh=c+O+LLgqN5oTgo0HoROZJSsAcr4bfSI/Bxgq9ilr0CY=; h=From:To:Cc:Subject:Date:From; b=ld4IKAPwxj/ynldPT0K7p0sFQXmymcalYygVqgTSLvetQxplpPXJW+4DXYx7vjFDj MncBS9L83qTMabZBXoFHiPXz8gxtIT3UInNn35S0lKnQzGyinOpyj4R4QIBTrVG46U 2vYTw05WfSSho7UCN6mSURos7PXsWsVcW1hgB/xiQ2pdqJyevzaG6nQ9SQPeDwBDmN NMUeXLKfN/AB9dbZE8wWxqMLGRSSk1CYbwtqCP/ZOwkMUNNQ7CELF3OljX9STkSzDv r//Oy8STI51wF5KiT7ESk5hcB3n/FwAtXbeXEzI4fcBYO8MZbQwrvM//XdTXNDqBDZ QGPOnjK7+SDPw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH 00/22] objtool: Reduce memory usage with CONFIG_DEBUG_INFO Date: Tue, 30 May 2023 10:20:52 -0700 Message-Id: X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1767341134698845535?= X-GMAIL-MSGID: =?utf-8?q?1767341134698845535?= DWARF uses a LOT of relocations, causing objtool to need a LOT of memory for processing vmlinux.o. In the worst case of an allyesconfig+CONFIG_DEBUG_INFO kernel, DWARF creates almost 200 million relocations, ballooning objtool's peak heap usage to 53GB. These patches reduce that to 25GB. On a distro-type kernel with kernel IBT enabled, they reduce objtool's peak heap usage from 4.2GB to 2.8GB. They also improve the runtime significantly (from 2m50s to 1m54s on my system with allyesconfig+CONFIG_DEBUG_INFO), though most of that comes from fixing the size calculation for reloc_hash. Josh Poimboeuf (22): objtool: Tidy elf.h objtool: Remove flags argument from elf_create_section() objtool: Improve reloc naming objtool: Consolidate rel/rela handling objtool: Fix reloc_hash size objtool: Add mark_sec_changed() objtool: Add elf_create_section_pair() objtool: Keep GElf_Rel[a] structs synced objtool: Don't free memory in elf_close() objtool: Add for_each_reloc() objtool: Allocate relocs in advance for new rela sections objtool: Get rid of reloc->list objtool: Get rid of reloc->idx objtool: Get rid of reloc->offset objtool: Get rid of reloc->type objtool: Get rid of reloc->addend objtool: Get rid of reloc->jump_table_start objtool: Shrink reloc->sym_reloc_entry objtool: Shrink elf hash nodes objtool: Get rid of reloc->rel[a] objtool: Free insns when done objtool: Skip reading DWARF section data tools/objtool/arch/powerpc/include/arch/elf.h | 11 +- tools/objtool/arch/x86/decode.c | 6 +- tools/objtool/arch/x86/include/arch/elf.h | 11 +- tools/objtool/arch/x86/special.c | 6 +- tools/objtool/check.c | 429 +++++++------- tools/objtool/elf.c | 537 +++++++----------- tools/objtool/include/objtool/elf.h | 326 ++++++++--- tools/objtool/orc_gen.c | 8 +- tools/objtool/special.c | 4 +- 9 files changed, 698 insertions(+), 640 deletions(-)