Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp5134349rwb; Mon, 8 Aug 2022 12:49:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR4rSTUH7WSAtrd4y4W+KcOR+S2/n7G0fJOHx5szQNIewmaIh7gswsk6HFqsRtjdU9yxuvPa X-Received: by 2002:a17:90b:f97:b0:1f3:7e:4513 with SMTP id ft23-20020a17090b0f9700b001f3007e4513mr21578479pjb.94.1659988188080; Mon, 08 Aug 2022 12:49:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659988188; cv=none; d=google.com; s=arc-20160816; b=h9aIFnc3wzm5UCTfYdWojGAZO0WyojBRNdzIboldQE4j84hmqLjoPD12XIMILlrw+4 PpuSm5+jPxTX0jG7//QL2EuQQgH1gdWSNKywRhIQWVkeZITmn1PUXmgjenofG3JBA8X9 abrZSC9gOJXrzFs2rENybEmMNd8ihaeolr/5rd1WSkrmSzRAWRflEt/3w1dkzdW5u6/Q BKqLWTxsT3MnAiTuzEuFyYqEtYIP1NogI26ZfjWA7Gy30s7OZvKo7kq4juYOzGZPCHko pDf2JFHRXLj9zMQ14NDi2wiSkjrkq79NPNEsNrdl1kz+WNGZvR0WjV24U69QMDk6CHUT Dqjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=esIHhkeNomxmu4HzsfTw4HrannJSy26XwL628pOM3mU=; b=NhnEHHGPWZLMw36l5UC+jmioDQiAzMNG6sRJqN0RpIjT1RYF+zkqASs2LJd330Ja3X 2R7zkP11zWj8adGRcWzppfexi9cBtmN1iAv8NLU5iZi0M+c6gOycG1zDBcfqPcxUzRJr s0b9fMh0Rg4MKXgJTd0sBLWFAOZGBsApRfW0/Lw7qSmn73JMmFJRowU9/ZO17Tf9SILO VoSGM6kv9ge5+PyyiVqpJxgw0nkhQFFilaBjYAPIzSqMyoWogKqnCypTuWvKNDrmTan9 AGZNHHTh0kH1b+e8MnyWAc+0kgPLG/CUBr8aggwCeaHW/ZsQbWmEISlfyG8qKH8JIAnL ZawA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VNHI6WEG; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y9-20020a056a00190900b0052af89712fdsi13461690pfi.142.2022.08.08.12.49.32; Mon, 08 Aug 2022 12:49: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=VNHI6WEG; 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 S243749AbiHHTbn (ORCPT + 99 others); Mon, 8 Aug 2022 15:31:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238106AbiHHTbl (ORCPT ); Mon, 8 Aug 2022 15:31:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E589D5596 for ; Mon, 8 Aug 2022 12:31:40 -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 826E1612D2 for ; Mon, 8 Aug 2022 19:31:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0AA0C433C1; Mon, 8 Aug 2022 19:31:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659987099; bh=kSnUwQkOfKM1Mn7a8k4LcXzj5EZ15JQG3PnKK95YqMk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VNHI6WEGVoxktgaSc/WbQV8uhrfflJVSaOTFQJ8Psp4qOXqsb4/Vrdnvjk7GhjXfK 1XPoqjqd5OVvcNyRG9zaUXjPivkvjtjZ9/047zhjV9TF8xQYZEnZaQaACDM9FxSv+U HmNLA/vBl0O1nUcz3P6386x+ZgVEZW4HIsCexuREEEUKOjy0qlmTTaX51kNfiS33sE KuxslEeSrVZ4szx/arm91N+c/7lW3cGuzTeI5o280XkwXlk7N1OMgRSlMalrp9ZDcf D/QuKwoGHfoztIMTFKGVKx0tTh4l4EPzT6xSt5Rdy1ui1mj7A/owFIythxOOoW72wi iQC3Vi7mfAwJw== Date: Mon, 8 Aug 2022 12:31:37 -0700 From: Nathan Chancellor To: Nick Desaulniers Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Nick Clifton , Fangrui Song , Linus Torvalds , Jens Axboe , x86@kernel.org, "H. Peter Anvin" , Tom Rix , Masahiro Yamada , "Kirill A. Shutemov" , Nicolas Schier , Brijesh Singh , Michael Roth , Kuppuswamy Sathyanarayanan , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH] x86: assemble with -Wa,--noexecstack to avoid BFD 2.39 warning Message-ID: References: <20220808192321.3490995-1-ndesaulniers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220808192321.3490995-1-ndesaulniers@google.com> X-Spam-Status: No, score=-7.7 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 On Mon, Aug 08, 2022 at 12:23:05PM -0700, Nick Desaulniers wrote: > Users of GNU ld (BFD) from binutils 2.39+ will observe multiple instance > of a new warning when linking kernels in the form: > > ld: warning: arch/x86/realmode/rm/bioscall.o: missing .note.GNU-stack > section implies executable stack > ld: NOTE: This behaviour is deprecated and will be removed in a future > version of the linker > > The object files producing these all happen to be out of line assembler > sources (*.S files). > > Generally, we would like to avoid the stack being executable. Because > there could be a need for the stack to be executable, assembler sources > have to opt-in to this security feature via explicit creation of the > .note.GNU-stack feature (which compilers create by default) or command > line flag --noexecstack. > > Boot tested defconfig and i386_defconfig in QEMU. If any assembler > sources do require executable stack, they can be built with > -Wa,--execstack, though the linker warning would have to be disabled. We > might need to extend this more generally to the top level Makefile for > all architectures, but I'm not equipped to test the result of such a > change. > > LLVM's LLD linker defaults to -z noexecstack, so this flag isn't > strictly necessary when linking with LLD, only BFD, but it doesn't hurt > to be explicit here for all linkers IMO. > > Link: https://lore.kernel.org/linux-block/3af4127a-f453-4cf7-f133-a181cce06f73@kernel.dk/ > Link: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=ba951afb99912da01a6e8434126b8fac7aa75107 > Link: https://github.com/llvm/llvm-project/issues/57009 > Reported-by: Jens Axboe > Signed-off-by: Nick Desaulniers FWIW, this warning appears for other architectures, as I have seen it with powerpc and s390 and there is also a patch for ARM: https://lore.kernel.org/20220721204709.445216-1-ben-linux@fluff.org/ Perhaps this should be done for all architectures in the main Makefile? > --- > arch/x86/Makefile | 2 ++ > arch/x86/boot/Makefile | 2 +- > arch/x86/boot/compressed/Makefile | 2 +- > arch/x86/realmode/rm/Makefile | 2 +- > 4 files changed, 5 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/Makefile b/arch/x86/Makefile > index 7854685c5f25..571546775725 100644 > --- a/arch/x86/Makefile > +++ b/arch/x86/Makefile > @@ -159,6 +159,8 @@ else > KBUILD_CFLAGS += -mcmodel=kernel > endif > > +KBUILD_AFLAGS += -Wa,--noexecstack > + > # > # If the function graph tracer is used with mcount instead of fentry, > # '-maccumulate-outgoing-args' is needed to prevent a GCC bug > diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile > index b5aecb524a8a..d7f2130f2277 100644 > --- a/arch/x86/boot/Makefile > +++ b/arch/x86/boot/Makefile > @@ -67,7 +67,7 @@ targets += cpustr.h > # --------------------------------------------------------------------------- > > KBUILD_CFLAGS := $(REALMODE_CFLAGS) -D_SETUP > -KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ > +KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ -Wa,--noexecstack > KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) > KBUILD_CFLAGS += -fno-asynchronous-unwind-tables > GCOV_PROFILE := n > diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile > index 19e1905dcbf6..1587a21a132d 100644 > --- a/arch/x86/boot/compressed/Makefile > +++ b/arch/x86/boot/compressed/Makefile > @@ -57,7 +57,7 @@ KBUILD_CFLAGS += -include $(srctree)/include/linux/hidden.h > # that the compiler finds it even with out-of-tree builds (make O=/some/path). > CFLAGS_sev.o += -I$(objtree)/arch/x86/lib/ > > -KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ > +KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ -Wa,--noexecstack > GCOV_PROFILE := n > UBSAN_SANITIZE :=n > > diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile > index 83f1b6a56449..5f2fdafaa034 100644 > --- a/arch/x86/realmode/rm/Makefile > +++ b/arch/x86/realmode/rm/Makefile > @@ -73,7 +73,7 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE > > KBUILD_CFLAGS := $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \ > -I$(srctree)/arch/x86/boot > -KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ > +KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ -Wa,--noexecstack > KBUILD_CFLAGS += -fno-asynchronous-unwind-tables > GCOV_PROFILE := n > UBSAN_SANITIZE := n > -- > 2.37.1.559.g78731f0fdb-goog >