Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4109516pxk; Tue, 29 Sep 2020 14:49:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxV8AfUcCx0qgi7XbtUMXmjd+ep/CjkSIb0FWbnFbUbiY3kCupBeYWciz+JBprbx90gkMB X-Received: by 2002:a17:906:1a11:: with SMTP id i17mr9469ejf.381.1601416143691; Tue, 29 Sep 2020 14:49:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601416143; cv=none; d=google.com; s=arc-20160816; b=jiAN0WJM7CQ9d2MecouLc8NhJHuJT3yB47YJiGXD8EFqVFYHA7jZ70Gi3flIVg05jH 8+LJJPg1sPgW3A1crJQOtuKZbQNjuEWBtpJL//w2jVcO5T+9p2IdiczYnFUoJ+CJxvU/ xJHaJYqgdxl79PbFjwcoLfMQo9OafGfel7wIBKQmQCNOD1W86i+22mWmNKrsyxsn99Ns d/U6gbmgWVk7srN3eDX/Dg8luUq1DEJ9JhlK+wxLZrmoLdDcBie7Wgg4m8BHgEjBKMes dzrNarh+7828mLNDJf1AGlEyL0Vr492XyFQoqGMEbOfw+65eODHgMkNbl4GX4jGgm/H6 b0/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=IM6BeG4IsHqc2HlM1gNMjcO8xaf7Yq/XvaXPBJbuDVo=; b=o6WaqyASdo/v607c0imgLF95aPVfP/jBgMTcT3slvJ52YrKyltA1ricfXprVqkf2kk zBZL+F+Faotz6aXVldl23+dPUCfc/ihi+6vyOy01DRmvsUIxWJBC5oIvyqTh+w4wD0Nc 3Sz8QMOOXWE0p8jns8s0IE/7c8N2r+y0dmRxSQmaHdYxd4Dgsgq5E0GrtiPYnf8VWtIb shrh9tTMQhrLQcK6i/u5cBTby1PUXuVjBeTvIFauWfpqU5MWGxlDyXALiouiQsmGGmH2 JVuFxtkV7BL42AG1SNfsMucNai+aZdsYTgkLT2lkLsFMjrQaAUPAL6YCruGdU6J3JRwg Oh5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=F5fLd2Sv; 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 dr1si3453792ejc.187.2020.09.29.14.48.40; Tue, 29 Sep 2020 14:49:03 -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=F5fLd2Sv; 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 S1728839AbgI2VrR (ORCPT + 99 others); Tue, 29 Sep 2020 17:47:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728847AbgI2VrH (ORCPT ); Tue, 29 Sep 2020 17:47:07 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E3A6C0613D2 for ; Tue, 29 Sep 2020 14:47:07 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id x191so3694139qkb.3 for ; Tue, 29 Sep 2020 14:47:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=IM6BeG4IsHqc2HlM1gNMjcO8xaf7Yq/XvaXPBJbuDVo=; b=F5fLd2SvpIplzncJLEztecG168LHlQrKNcKbedbFnUU8oPz2VYylmT9Mh1BQwGQWwd S0ZS2iRSNCDZBTJiH2iAxeyOVS4P1+Y10BtSKnYCQAn6a+GjpckK3VpZwEkV50DY8ZSy 3HLQoiSBVf3cPG9keb+CQtet28xkKUxeLTCuy2y7Dp3C3nWOnMUiuc+XwrAW3YxiGWPq /2KbafujJwZBb7QLVML/Va4ooU9T1eIfCSgSGwKdUGZ9zKWbuQx17Dqr2BMzsCAl+lkL 2CXyKcwhMnQZ7Jtse4QiNQ1zu7zDv2w3iAfRblAKfxEK4yCv2tM6mqw1dSGrb7v5pBfo dJsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=IM6BeG4IsHqc2HlM1gNMjcO8xaf7Yq/XvaXPBJbuDVo=; b=l69UulwJuslcWo/wuo1pyBnHV80omBmQul87AzXOAKQcV6zNP+U6i/Zat/p3FlAnVP F+qrl+MhCwj2aMNsPb5/Gtt0yb2Yb3ze6fxMMJRK8Lse6UOibsDQrOZRVd57yJ+Ax/2m v8tNCZLGID0vR2yX9k9b9sf1fu1XjMvtrmWHtkQWEyu2XEfnAPHzQhWbYWAYAEdhlSkl N52LSkRrnW/u+1GIhpxpe9ZF6x2SEIG+J2ldbglE8LUuyXXymLxkIYmytMDv/oc1YaS1 gkwmSGiPJ3FMeRd4fqPn1LMzEakCwXNegvcg3Fzu1OKVu11Hen9MVNsHCjKOQa64bpam s+vg== X-Gm-Message-State: AOAM531gNa5/tp+q2Lq/KxckmodwQkf4Zn1wQuEyByH292soqK87A6xc /wZjA6ecN4peAJUZ2n7tOJcXVD98rXAQTxS2lg8= Sender: "samitolvanen via sendgmr" X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:f693:9fff:fef4:1b6d]) (user=samitolvanen job=sendgmr) by 2002:ad4:5565:: with SMTP id w5mr6385766qvy.24.1601416026659; Tue, 29 Sep 2020 14:47:06 -0700 (PDT) Date: Tue, 29 Sep 2020 14:46:17 -0700 In-Reply-To: <20200929214631.3516445-1-samitolvanen@google.com> Message-Id: <20200929214631.3516445-16-samitolvanen@google.com> Mime-Version: 1.0 References: <20200929214631.3516445-1-samitolvanen@google.com> X-Mailer: git-send-email 2.28.0.709.gb0816b6eb0-goog Subject: [PATCH v4 15/29] kbuild: lto: merge module sections From: Sami Tolvanen To: Masahiro Yamada , Will Deacon , Steven Rostedt Cc: Peter Zijlstra , 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" 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 linker script rules to merge the split sections in the final module. Suggested-by: Nick Desaulniers Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook --- scripts/module.lds.S | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/scripts/module.lds.S b/scripts/module.lds.S index 69b9b71a6a47..037120173a22 100644 --- a/scripts/module.lds.S +++ b/scripts/module.lds.S @@ -25,5 +25,33 @@ SECTIONS { __jump_table 0 : ALIGN(8) { KEEP(*(__jump_table)) } } +#ifdef CONFIG_LTO_CLANG +/* + * 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*) + } + + .data : { + *(.data .data.[0-9a-zA-Z_]*) + *(.data..L*) + } + + .rodata : { + *(.rodata .rodata.[0-9a-zA-Z_]*) + *(.rodata..L*) + } + + .text : { *(.text .text.[0-9a-zA-Z_]*) } +} +#endif + /* bring in arch-specific sections */ #include -- 2.28.0.709.gb0816b6eb0-goog