From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 604F5C47098 for ; Thu, 3 Jun 2021 17:09:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DB986140B for ; Thu, 3 Jun 2021 17:09:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232105AbhFCRK4 (ORCPT ); Thu, 3 Jun 2021 13:10:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:41344 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231548AbhFCRKB (ORCPT ); Thu, 3 Jun 2021 13:10:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C2FD2613F8; Thu, 3 Jun 2021 17:08:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622740096; bh=2pXrZQ+w0kUNd95luNNtVdcwC/XYQEB9W6Mxs8RIM44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UZo3o9LJ+RTsKX0HTShp95UX4zwB/2ks5ni20Ufhm4AYNxYsOcGFmEob5adViDyey 20yTS4+kb1Fzh3M95nrXd65S1o9yzMEDOXxKhmDKIe9zvTODSwpWvdJ9n6GRaviyT8 lc4ILnZPeuNOWgK6JqTHm1n76811zGMNFm62jW9AAM2UMWpcgRwSsMIumH0JNZ2Mwg GtXTbqaO13+Wosg0+3+5nfP3JRD4SbOCGDH5KdNn+zmUhO9qBP/C/yD1Tz+2czAqq3 418BHzS4fMAX8x9z1AECy/IVB6J00GG3FLUsP5eOs6BS1pxstNrBEbejyiJXvYKiQD WdvjZ6I+6qcgQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Nick Desaulniers , Sami Tolvanen , Candle Sun , Fangrui Song , Kees Cook , Sasha Levin , linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com Subject: [PATCH AUTOSEL 5.12 34/43] Makefile: LTO: have linker check -Wframe-larger-than Date: Thu, 3 Jun 2021 13:07:24 -0400 Message-Id: <20210603170734.3168284-34-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210603170734.3168284-1-sashal@kernel.org> References: <20210603170734.3168284-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nick Desaulniers [ Upstream commit 24845dcb170e16b3100bd49743687648c71387ae ] -Wframe-larger-than= requires stack frame information, which the frontend cannot provide. This diagnostic is emitted late during compilation once stack frame size is available. When building with LTO, the frontend simply lowers C to LLVM IR and does not have stack frame information, so it cannot emit this diagnostic. When the linker drives LTO, it restarts optimizations and lowers LLVM IR to object code. At that point, it has stack frame information but doesn't know to check for a specific max stack frame size. I consider this a bug in LLVM that we need to fix. There are some details we're working out related to LTO such as which value to use when there are multiple different values specified per TU, or how to propagate these to compiler synthesized routines properly, if at all. Until it's fixed, ensure we don't miss these. At that point we can wrap this in a compiler version guard or revert this based on the minimum support version of Clang. The error message is not generated during link: LTO vmlinux.o ld.lld: warning: stack size limit exceeded (8224) in foobarbaz Cc: Sami Tolvanen Reported-by: Candle Sun Suggested-by: Fangrui Song Signed-off-by: Nick Desaulniers Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20210312010942.1546679-1-ndesaulniers@google.com Signed-off-by: Sasha Levin --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index a20afcb7d2bf..476ab5b3adc2 100644 --- a/Makefile +++ b/Makefile @@ -912,6 +912,11 @@ CC_FLAGS_LTO += -fvisibility=hidden # Limit inlining across translation units to reduce binary size KBUILD_LDFLAGS += -mllvm -import-instr-limit=5 + +# Check for frame size exceeding threshold during prolog/epilog insertion. +ifneq ($(CONFIG_FRAME_WARN),0) +KBUILD_LDFLAGS += -plugin-opt=-warn-stack-size=$(CONFIG_FRAME_WARN) +endif endif ifdef CONFIG_LTO -- 2.30.2