From patchwork Fri Dec 18 00:24:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 345445 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp1702056ejs; Thu, 17 Dec 2020 16:29:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJwh5NKmRaW83lyN7+t1GhEBb0LVBxonFh7lMq02/lLnik9O0BAsAi4kQztIKul3ISE/ui1t X-Received: by 2002:a17:906:4bd2:: with SMTP id x18mr1540377ejv.464.1608251370748; Thu, 17 Dec 2020 16:29:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608251370; cv=none; d=google.com; s=arc-20160816; b=aSNFvLn6aHsnrRqGL03Kj4R26MsYFOb0hjbc9IKdA6N6YM+O+exuM1qVs7V/Z92Xn9 z/65Avz4jWxchtER4T/Sxpre3zxn0DKXmiy0SfgTG3YFSy7n2Y3j5A7g8dUwkiLkaTpi 29Kxy3fpFvwZDHG13mEnSp6Yi3KFYOnNiflE6sM1xOt1VtNU80F/x3jz+rk7HfITJMC5 bG1RyCbtzTHVgGbv8Qc1+ZMEf9/zqtlwXAnoNL1o/HqkgRNcfzt0aEeUGm/rYNgnAa/U UMQI7MODkWZ5pCDa7eWR7SzQholyvTucZOkBlPG7pDIOUgLq/Xjnj2s0rH0gFI6QcMlr YXBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :references:mime-version:message-id:in-reply-to:date:sender :dkim-signature; bh=ERR2VE2oCwVj0NVrLHMHrJrZvp//bs46UVD4KXEsUV4=; b=pgZAqcffMFnv9p/Pnj7lP18/QF/ERgefeSRB70tmQuKZI5Y9hthNlFDsSDIeq5PgCK u7DJGf1bde/9PQsVjSSet4xBCVIv80cDGTqn+kR6mkVxJ99Outi3wNScuaaPRj3JaLf/ WIFpWnzqUVHZsmxSHrVb1vYYJvDxZ+GqyR1KSz5u3UfJYyfHhiIIqvRgAn15BzSAkPM4 AUDLIj0cMIgE+SzbCmkoH4B0QvEd6Nhcd6hTqiCbbtPGqVGVLGPzqdvWoSkj8gqph/HJ JOnlR7+D2WoiSiYL0yBJk5C/3o3VHaayIYyfdUlrBmkLIojRs+qPEyN6GR/RoQksWXr9 nc6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kGo+noPT; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 k26si5180699edx.279.2020.12.17.16.29.28; Thu, 17 Dec 2020 16:29:30 -0800 (PST) Received-SPF: pass (google.com: domain of stable-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=kGo+noPT; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S1732048AbgLRAZW (ORCPT + 14 others); Thu, 17 Dec 2020 19:25:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731130AbgLRAZW (ORCPT ); Thu, 17 Dec 2020 19:25:22 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D05E7C0617A7 for ; Thu, 17 Dec 2020 16:24:41 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id z1so457559ybg.22 for ; Thu, 17 Dec 2020 16:24:41 -0800 (PST) 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:content-transfer-encoding; bh=ERR2VE2oCwVj0NVrLHMHrJrZvp//bs46UVD4KXEsUV4=; b=kGo+noPT2sAcMd9H4DHcFIPyvTbkVbBAZXLSRZGw92t40O6jtpQ1pVyIsyVdt/EG1O kB2HpGKjev7+TPuMeWx9py1VLcPFBxqGVDMMHkrcVA8O9VHU2Xb+HjmoClG2L+KlBDb3 mQpC281cO1ZSrRuj4nL0zI3rEChn24EiDyuwL0WZ3ia9eaMMUEhC96Z0hjYY5FiqhNiy s73i34Blc94eiBPAPtC4hiG4HAvhuO0rmRwZNV5G6df847xe/pOxBbTEnLoZK9BRrFUH zAPODaE3aZi/5c+v+R+Dv/mM1tIUbV1vpQBh4BzAhFTRdHFUFjFd2BLcgZzkvvkBF6GL 40Sg== 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:content-transfer-encoding; bh=ERR2VE2oCwVj0NVrLHMHrJrZvp//bs46UVD4KXEsUV4=; b=a0qWuYsb0jRtvekyQtxjZRIt6L3PzkZEv9BORyM9x8yWemwjm4/akgd30WD98vyMR7 STQbbHSgHtybGfiqokXtYzTjWkFxRSm/A/509p/YhnVb7uqnfatksKUnD0r4UPQWnpse l5OHNRWVBMYSnvgHwClmUOlc4apkuQWGzY/s6j27tv8rWLUl8vmz5hIRYhuutn9+Z++m 6idgxUmRhdF207kn1LwTw4e5103iG2sq7U5mQbrBjRE9by28L9z8Aw9O+nFShXcrkzCu TxQRZlE0N5Ru+GkZd0DEaZLhZ9FIcT3VakYq4+Gqzj8tI3Tg/6iVG8F7F5yaBrTqOE7N 5DSg== X-Gm-Message-State: AOAM532MYNPuTKg9V+VggPtKj3XxxFCV/7okawM5CMNszQglg4hJWL+w 93QeXeEpERqxYSnwE+Cztzsxcy4PGdlHXG/l7lw= Sender: "ndesaulniers via sendgmr" X-Received: from ndesaulniers1.mtv.corp.google.com ([2620:15c:211:202:f693:9fff:fef4:4d25]) (user=ndesaulniers job=sendgmr) by 2002:a5b:b0b:: with SMTP id z11mr2665128ybp.164.1608251080932; Thu, 17 Dec 2020 16:24:40 -0800 (PST) Date: Thu, 17 Dec 2020 16:24:32 -0800 In-Reply-To: Message-Id: <20201218002432.788499-1-ndesaulniers@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.684.gfbc64c5ab5-goog Subject: [PATCH v2] arm64: link with -z norelro for LLD or aarch64-elf From: Nick Desaulniers To: Catalin Marinas , Will Deacon Cc: kernel-team , Peter Smith , clang-built-linux , stable , Ard Biesheuvel , "=?UTF-8?q?F=C4=81ng-ru=C3=AC=20S=C3=B2ng?=" , Quentin Perret , Alan Modra , Nick Desaulniers , "kernelci . org bot" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org With GNU binutils 2.35+, linking with BFD produces warnings for vmlinux: aarch64-linux-gnu-ld: warning: -z norelro ignored BFD can produce this warning when the target emulation mode does not support RELRO program headers, and -z relro or -z norelro is passed. Alan Modra clarifies: The default linker emulation for an aarch64-linux ld.bfd is -maarch64linux, the default for an aarch64-elf linker is -maarch64elf. They are not equivalent. If you choose -maarch64elf you get an emulation that doesn't support -z relro. The ARCH=arm64 kernel prefers -maarch64elf, but may fall back to -maarch64linux based on the toolchain configuration. LLD will always create RELRO program header regardless of target emulation. To avoid the above warning when linking with BFD, pass -z norelro only when linking with LLD or with -maarch64linux. Cc: Alan Modra Cc: Fāng-ruì Sòng Fixes: 3b92fa7485eb ("arm64: link with -z norelro regardless of CONFIG_RELOCATABLE") Reported-by: kernelci.org bot Reported-by: Quentin Perret Acked-by: Ard Biesheuvel Signed-off-by: Nick Desaulniers --- Changes V1 -> V2: * s/relocation types/program headers/ * s/newer GNU binutils/GNU binutils 2.35+/ * Pick up Ard's Ack. Note: maintainers may want to pick up the following tag: Fixes: 3bbd3db86470 ("arm64: relocatable: fix inconsistencies in linker script and options") or drop the existing fixes tag (this patch is more so in response to change to BFD to warn than fix a kernel regression, IMO, but I don't care). Either way, it would be good to fix this for the newly minted v5.10.y. I'll probably be offline for the next two weeks for the holidays, so no promises on quick replies. Happy holidays+new year! arch/arm64/Makefile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) -- 2.29.2.684.gfbc64c5ab5-goog Reviewed-by: Nathan Chancellor diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 6be9b3750250..90309208bb28 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -10,7 +10,7 @@ # # Copyright (C) 1995-2001 by Russell King -LDFLAGS_vmlinux :=--no-undefined -X -z norelro +LDFLAGS_vmlinux :=--no-undefined -X ifeq ($(CONFIG_RELOCATABLE), y) # Pass --no-apply-dynamic-relocs to restore pre-binutils-2.27 behaviour @@ -115,16 +115,20 @@ KBUILD_CPPFLAGS += -mbig-endian CHECKFLAGS += -D__AARCH64EB__ # Prefer the baremetal ELF build target, but not all toolchains include # it so fall back to the standard linux version if needed. -KBUILD_LDFLAGS += -EB $(call ld-option, -maarch64elfb, -maarch64linuxb) +KBUILD_LDFLAGS += -EB $(call ld-option, -maarch64elfb, -maarch64linuxb -z norelro) UTS_MACHINE := aarch64_be else KBUILD_CPPFLAGS += -mlittle-endian CHECKFLAGS += -D__AARCH64EL__ # Same as above, prefer ELF but fall back to linux target if needed. -KBUILD_LDFLAGS += -EL $(call ld-option, -maarch64elf, -maarch64linux) +KBUILD_LDFLAGS += -EL $(call ld-option, -maarch64elf, -maarch64linux -z norelro) UTS_MACHINE := aarch64 endif +ifeq ($(CONFIG_LD_IS_LLD), y) +KBUILD_LDFLAGS += -z norelro +endif + CHECKFLAGS += -D__aarch64__ ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_REGS),y)