Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp878694ybt; Wed, 24 Jun 2020 13:36:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5MKQyZDQvWgh52bgsWaV+47HzDCJxdFuV5/QY+BMssIC9HWSGlIzblV6WXcMnfwjgojHa X-Received: by 2002:a17:907:20d1:: with SMTP id qq17mr21239906ejb.214.1593030984345; Wed, 24 Jun 2020 13:36:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593030984; cv=none; d=google.com; s=arc-20160816; b=fh6EmuWh7/lpm6O3HhwQws99I/p5s9ge7dI2Is1zcduxjECYZTKtf9PaPJl5VY14iR si2oBi4/86C2GDJ+h02TyqdpgZv0s89KzH6TlfxLbObGn33EaTFwpB2AQGbZa68tapzT CVIq03Q7pZXjCpRVXsx4B7bU4ta/k9AxkvkqYNqORdmFohO1FhatP/JNYy7F/JukqjIJ MH4rgNsiaqOmDwRhSPtWK9Fhfhj4O2714YF0GfUU9UKMJD4ecOHxeGBiZuXFERHyaKXH ao6LbJR2fRygPBcU0+xncezu14YBkZUiM8MMaITj0Tt8KUTOLim4RxKr2dsu5vBcmBbc uFhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=BYARsb6kk5gBajh2Z9y53LZQA7+hhrma13n1XSCdmOU=; b=GUsLjl6Nd3wCuvU/beLMb88Tf4be7SZM5z+i+wklOdcxKqITCapZoPWegnjV5WoL1Q X12H35+Rs9LZ6NahlI/C2NAEBirJtBVHRprrgS15kqVCCAZticEyePa/LvqNZIifM8bM gA6DBjeAJYckzmxQ5JMqIZHrOXoob8/ZU7Vw48zJSxdzKNvlfzKADtn1mNp+sTyzC6JD YGBTmIeWHvcJV3y1yjazRyPKz9zev587Bpl1zJAcUSAC4zKYh1ITkvejCMuB3VgfnDJC Kgn5x6ZrbcsWkAsJm4OWmN1O2LPMg1x4BK9C3e3/3pU6TFIewBIdSRHV7TbgHpGqWHba L2JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VR9flySj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nh4si13347888ejb.339.2020.06.24.13.36.00; Wed, 24 Jun 2020 13:36:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VR9flySj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406719AbgFXUez (ORCPT + 99 others); Wed, 24 Jun 2020 16:34:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406475AbgFXUdN (ORCPT ); Wed, 24 Jun 2020 16:33:13 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B756FC061796 for ; Wed, 24 Jun 2020 13:33:11 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id e8so2409118qtq.22 for ; Wed, 24 Jun 2020 13:33:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=BYARsb6kk5gBajh2Z9y53LZQA7+hhrma13n1XSCdmOU=; b=VR9flySjUJwP/ToHZH5/xrbg3xtifUP2l8XzNOwvghrmkrOPlt0NBT0Anzq/fEaIeF KEoHKkAEPYQr1ae9axGCAMJQRNQ8Zn+uof7PhiL9L7JyAKcAQBsmFp+OoG91RU7+TJkG Yd8jJUh3wkbN8zyU9bxEpyOLO9sldP4qCwirdkQYZ3Ena38i/lEtgSWPv5cRv7bJRl2N UiX9uZX38aM3TP9J7+dUEiU2tJ3qLNH5BAb5fEeb58kPFpZiXEQBsf9meYLOuEa3jWcW FzXtiDx3izZRRi7FrJm7yt+UOltEWjza1vZCyR1pwcnJuQrqqarBC6T6qstSc9SdhCTJ LIZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=BYARsb6kk5gBajh2Z9y53LZQA7+hhrma13n1XSCdmOU=; b=NBwpiioo0kj9scwSpqtBxwmQIFCAZEXTZF4o6CDgvdRPi7scc77js+O0PviLO/uoDo 9RxblgneUJJWbcD87yncv9Z+Y1IhiOwLCe2pbVLrVQL/Gk/cbdLP+Y5fCD70rlrvlZhQ Q3dAuSwAKhjJrnAqvNCeGz2leIKR27kTOPnkGdxBK9J6VRup9szD49hOVRqGhKEjvXLb cSL2B4Z6HhUoaYzidCzY5RItBxqPFWSGBVkRF8fMMOI3wTxkk8c66dAdMA6bTmqHtHOK o9RZEN54sseQ+fe6typaAMzJfWxFWgFkj0/1mbdalw5MibmVFnomp1/loWn9RhV0COKG loEQ== X-Gm-Message-State: AOAM530u5ij4FswDyZXCpOORWVm1Z9Wa6EksB9P+KqoqIz/q3D2bXdFH wqm1SA0yh0sgAv0ZKrgintam8rfyzpwDbjZXe5M= X-Received: by 2002:a0c:9d44:: with SMTP id n4mr20638647qvf.35.1593030790865; Wed, 24 Jun 2020 13:33:10 -0700 (PDT) Date: Wed, 24 Jun 2020 13:31:45 -0700 In-Reply-To: <20200624203200.78870-1-samitolvanen@google.com> Message-Id: <20200624203200.78870-8-samitolvanen@google.com> Mime-Version: 1.0 References: <20200624203200.78870-1-samitolvanen@google.com> X-Mailer: git-send-email 2.27.0.212.ge8ba1cc988-goog Subject: [PATCH 07/22] kbuild: lto: merge module sections From: Sami Tolvanen To: Masahiro Yamada , Will Deacon Cc: Greg Kroah-Hartman , "Paul E. McKenney" , Kees Cook , Nick Desaulniers , clang-built-linux@googlegroups.com, kernel-hardening@lists.openwall.com, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, x86@kernel.org, Sami Tolvanen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org LLD always splits sections with LTO, which increases module sizes. This change adds a linker script that merges the split sections in the final module and discards the .eh_frame section that LLD may generate. Suggested-by: Nick Desaulniers Signed-off-by: Sami Tolvanen --- Makefile | 2 ++ scripts/module-lto.lds | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 scripts/module-lto.lds diff --git a/Makefile b/Makefile index ee66513a5b66..9ffec5fe1737 100644 --- a/Makefile +++ b/Makefile @@ -898,6 +898,8 @@ CC_FLAGS_LTO_CLANG += -fvisibility=default # Limit inlining across translation units to reduce binary size LD_FLAGS_LTO_CLANG := -mllvm -import-instr-limit=5 KBUILD_LDFLAGS += $(LD_FLAGS_LTO_CLANG) + +KBUILD_LDS_MODULE += $(srctree)/scripts/module-lto.lds endif ifdef CONFIG_LTO diff --git a/scripts/module-lto.lds b/scripts/module-lto.lds new file mode 100644 index 000000000000..65884c652bf2 --- /dev/null +++ b/scripts/module-lto.lds @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * With CONFIG_LTO_CLANG, LLD always enables -fdata-sections and + * -ffunction-sections, which increases the size of the final module. + * Merge the split sections in the final binary. + */ +SECTIONS { + __patchable_function_entries : { *(__patchable_function_entries) } + + .bss : { + *(.bss .bss.[0-9a-zA-Z_]*) + *(.bss..L* .bss..compoundliteral*) + } + + .data : { + *(.data .data.[0-9a-zA-Z_]*) + *(.data..L* .data..compoundliteral*) + } + + .rodata : { + *(.rodata .rodata.[0-9a-zA-Z_]*) + *(.rodata..L* .rodata..compoundliteral*) + } + + .text : { *(.text .text.[0-9a-zA-Z_]*) } +} -- 2.27.0.212.ge8ba1cc988-goog