Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1505625pxu; Thu, 17 Dec 2020 11:31:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSbCsSGpFPO/txkgfLQ3xCjjJhb3tnfojwpQ1Jb37Td20zGs1xIczug5gEaz8Gxq9e3JWj X-Received: by 2002:a17:906:705:: with SMTP id y5mr564185ejb.428.1608233516468; Thu, 17 Dec 2020 11:31:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608233516; cv=none; d=google.com; s=arc-20160816; b=SypwjrZdRkDjOBZYJeRQmol8le55oKNBXcRC72qfiK2mh6aZRJnUrzRJJdjA+v7cVX NmhIZXUU2J6v6n9g9qON3H623MpXh2CE1aTMgypqhdGvqxnWgD4hlbDWMqnxIX5Qdq2C XlPffZN2ToN+AERNQ6Q0J6B/rXkRkKmnyAwv0vspK80yc1PRSumT8w9+3s+VP+fxgIkw yr6RCYic6ONNBxm5Z1XcL11JJWXuhuqdI/E2Mp9KB0zh+Zsxp3AjStHeXapbIwDhFwfK rQioScoHdV1qB44T7z7XMEWN/KtQrjpUUnBGwo0oJPbAVZ1jG/SPd2hftr9HWum21+lL 15Ig== 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:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=kLVgL1txm2869M+qHEoINXYqm+s85l4eqyCmuAhMPf8=; b=wY/oDfnCDnaoDV5S501k7yzuhydlHjj1ohUxiCYjvHmAzCxAmOC5kexPoUPm/oA1Cv i5ZovgO5SUL5ogoZT8bj401kG6tUNM4Ph/5kMo10Qmry2f0dTBt8shuE6VaCcZo9Nugi cEVKt2xVfS8Z8BFgHSnNSBoeTF7meXMFv2E8cGLB2zUM7pp24xxTurTiMFlrgK0QneKK eX2RjPybs8+j/so0k+P5wwDPcYZnbnYtbC2gMuTE1STQYQbFCPG0LUaU674jpZCT3g4c tu3TdsXYW+bZMbsKTRQefWAnUifHkcMihK8O3eK7oUKm9Jzqn+o3NZ/BXmS8L/6v0eSP w8Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tM3fpjtJ; 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 e15si4849914edr.313.2020.12.17.11.31.31; Thu, 17 Dec 2020 11:31:56 -0800 (PST) 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=tM3fpjtJ; 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 S1727857AbgLQTa3 (ORCPT + 99 others); Thu, 17 Dec 2020 14:30:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:49418 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725468AbgLQTa2 (ORCPT ); Thu, 17 Dec 2020 14:30:28 -0500 X-Gm-Message-State: AOAM531jhmcd5QMKEaZnxNxiAcD2kX0u3SAYaHxgGm+buQuwC7p9mMgX cy7GwwHOhkBCsIX0MoYFY9FxgWBDvR4BiObGM9Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1608233387; bh=HRY8YeVLSHAvObD2gzi1HyscgTfOcaMV6u6OwjX/7Vo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=tM3fpjtJciyI5a8jL4IU2Yi9/zPHcWryWiiJczOp7eL2q4Ygc3zJqn/a2+DUhntrJ BELyh8lz0GqKdx3emD/xgKVXlp/AQYf2KYJt/+74jcEk8kXHQ74S5G8MgabaLzYYYN zfTGYOmRAN45wSNaoTGJP1xOOyUI1yAg+gcMPsBV/vQVF190pPHUAb3Fv7EmXlLRSR Vfund6xxHGGiwurZ6MGcAWdOr4IGw/MBpiH36Tr7dlwKrxoMkylSOZjwc0DnbfxBDp ADmPcigMY+umWLN2ETAKhygS9rK8ezLQ/4zUysQzlFU+eLtIWfufHLPkR9DlIjYIHZ 9OsGggSdj1UbA== X-Received: by 2002:a05:6830:1c24:: with SMTP id f4mr362030ote.108.1608233386622; Thu, 17 Dec 2020 11:29:46 -0800 (PST) MIME-Version: 1.0 References: <20201217004051.1247544-1-ndesaulniers@google.com> In-Reply-To: <20201217004051.1247544-1-ndesaulniers@google.com> From: Ard Biesheuvel Date: Thu, 17 Dec 2020 20:29:35 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] arm64: link with -z norelro for LLD or aarch64-elf To: Nick Desaulniers Cc: Catalin Marinas , Will Deacon , kernel-team , Peter Smith , clang-built-linux , stable , =?UTF-8?B?RsSBbmctcnXDrCBTw7JuZw==?= , Quentin Perret , Alan Modra , "kernelci . org bot" , Linux ARM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 17 Dec 2020 at 01:41, Nick Desaulniers wr= ote: > > With newer GNU binutils, 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 relocation types, and -z relro or -z norelro is passed. > RELRO is not a relocation type, it is a type of program header which we might simply ignore, if it weren't for the fact that it can only be emitted if the layout of the sections adheres to certain rules (and ours doesn't), and we get an error otherwise. It amounts to implicit __ro_after_init annotations for statically initialized const pointers, but given that we don't compile with -fpie, those const pointers reside in .rodata already, so RELRO adds no value for us. > 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=3Darm64 kernel prefers -maarch64elf, but may fall back to > -maarch64linux based on the toolchain configuration. > > LLD will always create RELRO relocation types regardless of target > emulation. > RELRO program header > To avoid the above warning when linking with BFD, pass -z norelro only > when linking with LLD or with -maarch64linux. > > Cc: Alan Modra > Cc: Ard Biesheuvel > Cc: F=C4=81ng-ru=C3=AC S=C3=B2ng > Fixes: 3b92fa7485eb ("arm64: link with -z norelro regardless of CONFIG_RE= LOCATABLE") > Reported-by: kernelci.org bot > Reported-by: Quentin Perret > Signed-off-by: Nick Desaulniers With mentions of 'RELRO relocation types' fixed: Acked-by: Ard Biesheuvel > --- > arch/arm64/Makefile | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > 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 :=3D--no-undefined -X -z norelro > +LDFLAGS_vmlinux :=3D--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 +=3D -mbig-endian > CHECKFLAGS +=3D -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 +=3D -EB $(call ld-option, -maarch64elfb, -maarch64linuxb= ) > +KBUILD_LDFLAGS +=3D -EB $(call ld-option, -maarch64elfb, -maarch64linuxb= -z norelro) > UTS_MACHINE :=3D aarch64_be > else > KBUILD_CPPFLAGS +=3D -mlittle-endian > CHECKFLAGS +=3D -D__AARCH64EL__ > # Same as above, prefer ELF but fall back to linux target if needed. > -KBUILD_LDFLAGS +=3D -EL $(call ld-option, -maarch64elf, -maarch64linux) > +KBUILD_LDFLAGS +=3D -EL $(call ld-option, -maarch64elf, -maarch64linux -= z norelro) > UTS_MACHINE :=3D aarch64 > endif > > +ifeq ($(CONFIG_LD_IS_LLD), y) > +KBUILD_LDFLAGS +=3D -z norelro > +endif > + > CHECKFLAGS +=3D -D__aarch64__ > > ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_REGS),y) > -- > 2.29.2.684.gfbc64c5ab5-goog >