From patchwork Thu Jul 25 20:06:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 169750 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp12070798ilk; Thu, 25 Jul 2019 13:07:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqz/vEIenNNRABOA9DXE4rcNMhDOCHkPHIsLcwrqVzFbOPlYqNMe8jDrW3iag8TE9s0o2KfL X-Received: by 2002:a63:903:: with SMTP id 3mr22467890pgj.371.1564085229979; Thu, 25 Jul 2019 13:07:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564085229; cv=none; d=google.com; s=arc-20160816; b=YyS/zE0EmLk8gwJOe4+BWtNCDigxe2OhhPDnOZn1l7de+igrlg7YqQZoyavHVr5O75 wWIXReMO1gW8OvwosuHgEHzoVv6slB9IYCFQuSqK74JjP765xsPQY1SCY/NmzTlLt0if 9MmaMdbRPdibjJ8qJZsJW2wD77P31hEnFgFPsTjEzusHEqL5lh8EvVueNopDYsaQBH4x NFaFbsSEvi5G8CRwPB/TXHKwk0eyURlfrHIdJcJR6ZCGW5A1ABkvB7NKC+eIWpNMdPKu dVQI9gTw/yETqpX2cnIcMzB4J3fSGyhVemayJW/nIZcjl3t4GsVIxZAGqtG+IYz1bw+i mGDQ== 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=tN5OGADsh/gbQB0AixreGdFmpm9j6/fownra3N7HOyA=; b=DkrSP5X4Ot5GV3/wXT0DfN0ATJiu/RDJ0b62QzaeXDn4S6L73NYpJUVfZAQiTq1Ar1 Up5WSm8QRMm6Cq+xuvnLq/FlO9ZtwSIGLvx9cid3IejjNGix2F7xSiM29GyYrUnE9y+j iHaRCadUUYPp8kJRsmGF39SbfsP2TzT/3SgJJWM/Nek+7/9ZmFdzAkDuAFxna0rrtruM JzQq1BArdV+emMVuYhVW8XcBgfU+gID/aUTeM5JXjHL/T74gqHGj35CalGd0lbNp5xH9 rsNwxnxWZxxTbwcq94q3wV3DcBrHesYlyu2oqkNPkx9gW+UEj8xL1PE2FikB/OmgkI+0 SmKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=sAHxJvpR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id a59si18184192plc.319.2019.07.25.13.07.09; Thu, 25 Jul 2019 13:07:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=sAHxJvpR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726586AbfGYUHI (ORCPT + 29 others); Thu, 25 Jul 2019 16:07:08 -0400 Received: from mail-vk1-f201.google.com ([209.85.221.201]:45521 "EHLO mail-vk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726166AbfGYUHI (ORCPT ); Thu, 25 Jul 2019 16:07:08 -0400 Received: by mail-vk1-f201.google.com with SMTP id x83so21971765vkx.12 for ; Thu, 25 Jul 2019 13:07:07 -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=tN5OGADsh/gbQB0AixreGdFmpm9j6/fownra3N7HOyA=; b=sAHxJvpRkEMvpJPKxJwU7iLi4As7kH8MTS2ss9dHMFjBRm47kjVojaV4PcQ2HFDByy +V9UILVlZ1n7FObDzfpl9l3PXkqio4xuKZ0IIRJWYAfzsQEEs8fi21R5pkJYAqG4PS74 O7PkvWIvhdbIh55P0HVKYHp6wiqTj6j3reN3OHVN+5t0C2AwDjT6BoH8PGXcxlpGhQ2C gmSu7ca86eKfArzkksgfLqnxFAVKFP0Xh9ylJNO0w2dpQvnSFX0+EkcbEqyF0CQOKbv0 SDA5hKM5kSG9iu8DRY4L5eyvrSKKZ0iQPF8PkkEOH4JvQhVmrvn+5b0O9P4ooznypCyM iaTw== 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=tN5OGADsh/gbQB0AixreGdFmpm9j6/fownra3N7HOyA=; b=pe4LGCFqwOhQ3I/FVN75Y/+8h6jgHV4SvnsUI4buWGeFhv7KY36SyqyAkDZZlnFP4i 0jeYHz7wTY5nct94LexA5jFIt+REHR5Wkeng+Ixb/mX2TV3Vql9Ew+y5H32QL9f3j3u2 Rphg9sNxTi4WO50M+P77XTrv2bX0ZcpvgmYp/0hYxsPwgtMlt0l8sUK32nggxLq4j0f9 FeQXAKK+KRplJdPMIahn6szZI74oeqhwoh0nVGSLf36Ipzt8H2WzMcUdQe+0T6AXHvRR sCm7wum44tvB/AK8y2tihASJXNt5zrdl0nb7sLG7PXd9deRJASrYo0jT1cL89xYpEnYw U1bg== X-Gm-Message-State: APjAAAW5IvXk6nf+WZuzm77uSjcf3Sw4rVsbacHl9nCOcNpBbDQx2PTK AkG2BsSEVFDtr7xaQ9lTE1b1OTJh8/IYJxLzRA0= X-Received: by 2002:a67:7dd8:: with SMTP id y207mr59917081vsc.67.1564085224802; Thu, 25 Jul 2019 13:07:04 -0700 (PDT) Date: Thu, 25 Jul 2019 13:06:18 -0700 In-Reply-To: <20190725200625.174838-1-ndesaulniers@google.com> Message-Id: <20190725200625.174838-2-ndesaulniers@google.com> Mime-Version: 1.0 References: <20190725200625.174838-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v4 2/2] x86/purgatory: use CFLAGS_REMOVE rather than reset KBUILD_CFLAGS From: Nick Desaulniers To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de Cc: peterz@infradead.org, clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org, yamada.masahiro@socionext.com, Nick Desaulniers , Vaibhav Rustagi , "H. Peter Anvin" , x86@kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org KBUILD_CFLAGS is very carefully built up in the top level Makefile, particularly when cross compiling or using different build tools. Resetting KBUILD_CFLAGS via := assignment is an antipattern. The comment above the reset mentions that -pg is problematic. Other Makefiles use `CFLAGS_REMOVE_file.o = $(CC_FLAGS_FTRACE)` when CONFIG_FUNCTION_TRACER is set. Prefer that pattern to wiping out all of the important KBUILD_CFLAGS then manually having to re-add them. Seems also that __stack_chk_fail references are generated when using CONFIG_STACKPROTECTOR or CONFIG_STACKPROTECTOR_STRONG. Fixes: 8fc5b4d4121c ("purgatory: core purgatory functionality") Reported-by: Vaibhav Rustagi Suggested-by: Peter Zijlstra Suggested-by: Thomas Gleixner Signed-off-by: Nick Desaulniers Tested-by: Vaibhav Rustagi --- Changes v3 -> v4: * Use tabs to align flags (stylistic change only). * Drop stable tag, patch 01/02 doesn't apply earlier than 5.1. * Add tglx's suggested by tag for the tabs. * Carry Vaibhav's tested by tag from v3 since v4 is simply stylistic. Changes v2 -> v3: * Prefer $(CC_FLAGS_FTRACE) which is exported to -pg. * Also check CONFIG_STACKPROTECTOR and CONFIG_STACKPROTECTOR_STRONG. * Cc stable. Changes v1 -> v2: Rather than manually add -mno-sse, -mno-mmx, -mno-sse2, prefer to filter -pg flags. arch/x86/purgatory/Makefile | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) -- 2.22.0.709.g102302147b-goog diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile index 91ef244026d2..940f043a4d97 100644 --- a/arch/x86/purgatory/Makefile +++ b/arch/x86/purgatory/Makefile @@ -20,11 +20,27 @@ KCOV_INSTRUMENT := n # Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That # in turn leaves some undefined symbols like __fentry__ in purgatory and not -# sure how to relocate those. Like kexec-tools, use custom flags. - -KBUILD_CFLAGS := -fno-strict-aliasing -Wall -Wstrict-prototypes -fno-zero-initialized-in-bss -fno-builtin -ffreestanding -c -Os -mcmodel=large -KBUILD_CFLAGS += -m$(BITS) -KBUILD_CFLAGS += $(call cc-option,-fno-PIE) +# sure how to relocate those. +ifdef CONFIG_FUNCTION_TRACER +CFLAGS_REMOVE_sha256.o += $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_purgatory.o += $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_string.o += $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_kexec-purgatory.o += $(CC_FLAGS_FTRACE) +endif + +ifdef CONFIG_STACKPROTECTOR +CFLAGS_REMOVE_sha256.o += -fstack-protector +CFLAGS_REMOVE_purgatory.o += -fstack-protector +CFLAGS_REMOVE_string.o += -fstack-protector +CFLAGS_REMOVE_kexec-purgatory.o += -fstack-protector +endif + +ifdef CONFIG_STACKPROTECTOR_STRONG +CFLAGS_REMOVE_sha256.o += -fstack-protector-strong +CFLAGS_REMOVE_purgatory.o += -fstack-protector-strong +CFLAGS_REMOVE_string.o += -fstack-protector-strong +CFLAGS_REMOVE_kexec-purgatory.o += -fstack-protector-strong +endif $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE $(call if_changed,ld)