Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1688668pxj; Wed, 19 May 2021 11:30:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyx+gh3gwVlOOkO/t4P86VtJDiikNucX8CS3+KI1NFRg2+HzJOMmaiZ+Q5VXe+YWxCutTDj X-Received: by 2002:a92:4446:: with SMTP id a6mr408290ilm.9.1621449032601; Wed, 19 May 2021 11:30:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621449032; cv=none; d=google.com; s=arc-20160816; b=ep3GX1attAw2TSPDQsOFSiA+3a8wHGft8rmowfT8ESpTuJyW8wyf9Tm/k7F76NMH5j bHu+ciB5GntxQr3rE/Wg6nHcKLzloe89R5uOQ9TmyKlKsZXrjny6oLohFkyMNh0ytGdh sviba14Rw5p2MDRRoyctiDFiP5+4rxOFO55ijeKzUQqdUiVyxZs8FiiouWHg4LtZ4x3s xU+tnW04W67AZ24QeoLykv0krRNwsb+S9DDZokkdcN5XNbU2oJLgi4mUZMAtCaz3rNda mcIrZJAat1e4UGMp0ny4NMvjRcYNUn7R01nB7gCqy02Idm2Pstl8sinZbhMeQ3pVpzu+ 9Ldg== 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=vZGLdt4RdVdNZKk9zbuqcBCpsOHRjQrdQCynoH6OoUg=; b=JOn5DfNSlvdFHnp0oem/S7tPOnB1deO3qZKLPqaQycg1g9e2B5WQh1RoVndamubNLg BD7OX6EkAx0KqlDnxE/mnrmTUPjf1DQIHIPyWeWaITKCYu99SVCdyiYR8nIOsdYkFgEe trDx4rcriNcjABcKz+mVFzoEZFG4unXNJ7i6tqteCEWvJ29m/i13Pr5gycOAS9t7BG1C ZdDei9a9MaB2l/91AN/L9VWgzTxqZt0PNlmf7GAA7NBZkoQ6GzfQrRQdvmi7JzMrXFqy +TC2o9VDuz1ZIaJeK/bdnnDDS9SvuDIjlL+o3ehYKO7qgfgTsaewu3h+u6gMJm+shhs5 c2sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gAFZkQUM; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o21si61347jat.63.2021.05.19.11.30.19; Wed, 19 May 2021 11:30:32 -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=@kernel.org header.s=k20201202 header.b=gAFZkQUM; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239108AbhERTCz (ORCPT + 99 others); Tue, 18 May 2021 15:02:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:49546 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238394AbhERTCy (ORCPT ); Tue, 18 May 2021 15:02:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2366A610E9; Tue, 18 May 2021 19:01:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621364496; bh=N0OYIBjgObbNxtkzADopyy7cdON09mSWl+anyWhDbPY=; h=From:To:Cc:Subject:Date:From; b=gAFZkQUMSOAp5Jd8+egXCbE2xH9HSMjlQjU4nYmhViIMjmP0GMe9puxRUWa7Id5mV 3moE5aBfcMOSIXcEtGhsN33EqnWqtR2PEAZR+DamRe+YeYEvPUxcENh0q8suB9quBG OtLwRbKe+Sf61sz1oXjMfdypCgo2SWvOc4GxUPaYLNzp/uGal7uq2Zy95SgpahR6NZ e4L2q3tWdJbDyIUQVS8LOcMyqyHff9sIMTCdI2kstKfLn1KigvWxNB8gAtwKssiBNI 7df59rgE1xBR7jywcHEeoI+uB1L+jrccfmIRVyZpmv8/xh3W4OzLn/ypgrdMThMcEJ RDUCMjezTv0iA== From: Nathan Chancellor To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, Kees Cook , Sami Tolvanen , Nick Desaulniers Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, Nathan Chancellor , stable@vger.kernel.org, Anthony Ruhier Subject: [PATCH] x86: Fix location of '-plugin-opt=' flags Date: Tue, 18 May 2021 12:01:06 -0700 Message-Id: <20210518190106.60935-1-nathan@kernel.org> X-Mailer: git-send-email 2.32.0.rc0 MIME-Version: 1.0 X-Patchwork-Bot: notify Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit b33fff07e3e3 ("x86, build: allow LTO to be selected") added a couple of '-plugin-opt=' flags to KBUILD_LDFLAGS because the code model and stack alignment are not stored in LLVM bitcode. However, these flags were added to KBUILD_LDFLAGS prior to the emulation flag assignment, which uses ':=', so they were overwritten and never added to $(LD) invocations. The absence of these flags caused misalignment issues in the AMDGPU driver when compiling with CONFIG_LTO_CLANG, resulting in general protection faults. Shuffle the assignment below the initial one so that the flags are properly passed along and all of the linker flags stay together. At the same time, avoid any future issues with clobbering flags by changing the emulation flag assignment to '+=' since KBUILD_LDFLAGS is already defined with ':=' in the main Makefile before being exported for modification here as a result of commit ce99d0bf312d ("kbuild: clear LDFLAGS in the top Makefile"). Cc: stable@vger.kernel.org Fixes: b33fff07e3e3 ("x86, build: allow LTO to be selected") Link: https://github.com/ClangBuiltLinux/linux/issues/1374 Reported-by: Anthony Ruhier Tested-by: Anthony Ruhier Signed-off-by: Nathan Chancellor --- arch/x86/Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index c77c5d8a7b3e..307529417021 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -178,11 +178,6 @@ ifeq ($(ACCUMULATE_OUTGOING_ARGS), 1) KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args,) endif -ifdef CONFIG_LTO_CLANG -KBUILD_LDFLAGS += -plugin-opt=-code-model=kernel \ - -plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8) -endif - # Workaround for a gcc prelease that unfortunately was shipped in a suse release KBUILD_CFLAGS += -Wno-sign-compare # @@ -202,7 +197,12 @@ ifdef CONFIG_RETPOLINE endif endif -KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE) +KBUILD_LDFLAGS += -m elf_$(UTS_MACHINE) + +ifdef CONFIG_LTO_CLANG +KBUILD_LDFLAGS += -plugin-opt=-code-model=kernel \ + -plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8) +endif ifdef CONFIG_X86_NEED_RELOCS LDFLAGS_vmlinux := --emit-relocs --discard-none base-commit: d07f6ca923ea0927a1024dfccafc5b53b61cfecc -- 2.32.0.rc0