Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4542079pxa; Mon, 10 Aug 2020 11:36:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4FJusb7q53REopZUDR9/FeRRWWjY6hTJzATV76YgNaFds4l+r1XoAcAKv9w/ykHCxaVlY X-Received: by 2002:a17:906:454f:: with SMTP id s15mr21643197ejq.130.1597084562988; Mon, 10 Aug 2020 11:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597084562; cv=none; d=google.com; s=arc-20160816; b=P2leFjBTh9Qh4XgmKq7LxRuBglXQf47hk5FQ5fnaOMRZLF6SUz00UYe4gp+tAE2AId hGpDmq9WD0EZgx40mXu9FqUHzhQq/fiZkNq+cOwuyA2f91ir7X3z+qveNp8zQJFu0WBe 6DHY0L0S8opTrCHWme8skgS88seUyjC8VHIWxGsjZBMSL5let44xC28GZ4npD51983FR y9KzyiAr8f9xrWHqNvWseikAevN6RQqTUeVqg1A+OUeoKlypqZZbGAV1KDDhhxA80F0w Q2iWiQG6eKCXGJFikEWDU8jRU+qT0kBF4L0LiQQaNCcekZyXW3MCLUFpi457D7fX5PY2 oPGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Ut33wnU3evyQXWlinpE8dvgKmV5UI4ScBRUoelbVE5c=; b=Atpr7wkS8OELbQW9r7hEglIfU3dfAhpAeY7HfJAqpebz1GntoOll3AyyGTshLGVU1p qitvmUXZOaxFTsud8xGAkCnu1HjxTLpzz68mfmM7DYMDcIQ+GeXquJucZKe+PnKx+fhq 1TZ3dGXRT0t8TitifMmLg/ssIxX4NtyXN0JPjlKPqo8ZUCHtB2pFpQa8QJJsu21lu1eV t5V6kPoJ6WzNPU1tItqTQqAx0pFG4OYG1ayQZtjtEe5M2oi3qV+S6kf2J768Hb8XRkFb qMGOpDohSXD3iV8I99OPD3alm7WAZlLyIRvNPwppr3Ig6fPYXRetOGUjxT3RpjF5e0zD 8pRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=nUJZ+7e+; 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=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 d9si9908589edl.400.2020.08.10.11.35.40; Mon, 10 Aug 2020 11:36:02 -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=@google.com header.s=20161025 header.b=nUJZ+7e+; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728189AbgHJSdJ (ORCPT + 99 others); Mon, 10 Aug 2020 14:33:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728103AbgHJSdH (ORCPT ); Mon, 10 Aug 2020 14:33:07 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD196C061787 for ; Mon, 10 Aug 2020 11:33:07 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id bh1so5457217plb.12 for ; Mon, 10 Aug 2020 11:33:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Ut33wnU3evyQXWlinpE8dvgKmV5UI4ScBRUoelbVE5c=; b=nUJZ+7e+ugKadp89+aDttSKsNbyKiECi6l1q0lnNDnjAHdqrNOwHUJFShF0dRdANUC gFVN0wlLIaiMLfXT3LbqH99WySabzY6sZHcBIVsV3SIZnMlxZRadKWP31AAbygRHAPIg /1UuneFNUiR6Rsw12+LO9R5mV6zWrzJ3ZPWrM5RCsEhDT66+2muKAhiXRW4phT7H1Eeq pjos4h9KBBchONnzeGpCAh/QpxUhAFlF9EalPcQeBf0ACfS0uYm1LOutdNJy+quUajhM pqwR01v5BN0Spk3TMk4owmlDK65JXycdECNCzR8SsfnzbMpBXjjPNbtSMcQbcTTNXhXj PrIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ut33wnU3evyQXWlinpE8dvgKmV5UI4ScBRUoelbVE5c=; b=cik93Bv3udW5U9PRu/2zD97idh2rIYrIPzNDrslZhyP520LjOXzN45Yum4qpVneDBA Bdax1EDcJy3Vg99NQkX0NysvO3z97jVGdIjmpjGNL2WvGb3Xe4on3m80dwHhZyXOG3JH 5O47mPyq8JPFI4Ytkg+b8gXKtKpGykwx2gbta75JY4FQIIbfnipXORanE5rlNZFbKAcl +lI0FFS7pmHHUPb8eNYFnoocC6b8G48KnAeIvSrpHTFVU0Mbch05qqpD8h7mgrKyDarh ddFzTCHT/PkyGukcFpFLqlKt89iivGkHt+lXl8SIWUHeBIkG4fjH3Z2PTdEDsBNP0zEi hO/w== X-Gm-Message-State: AOAM530TUhv8C9DRj7Cpe5dJ0LxXmuG5np/4kdE2XHjxB8MBIvq0gILH Hl8T9NXN20pHSgiOWaKLSxcCOTPl67N5Qq07kBD0hQ== X-Received: by 2002:a17:90a:fc98:: with SMTP id ci24mr639051pjb.101.1597084386868; Mon, 10 Aug 2020 11:33:06 -0700 (PDT) MIME-Version: 1.0 References: <20200807194100.3570838-1-ndesaulniers@google.com> <20200807212914.GB1454138@rani.riverdale.lan> <20200808014327.GA1925552@rani.riverdale.lan> In-Reply-To: <20200808014327.GA1925552@rani.riverdale.lan> From: Nick Desaulniers Date: Mon, 10 Aug 2020 11:32:55 -0700 Message-ID: Subject: Re: [PATCH] x86/boot: avoid relaxable symbols with Clang To: Arvind Sankar Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Fangrui Song , clang-built-linux , e5ten.arch@gmail.com, "# 3.4.x" , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , Masahiro Yamada , Ard Biesheuvel , Kees Cook , Dmitry Golovin , Marco Elver , Nick Terrell , Daniel Kiper , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 7, 2020 at 6:43 PM Arvind Sankar wrote: > > On Fri, Aug 07, 2020 at 02:54:39PM -0700, Nick Desaulniers wrote: > > On Fri, Aug 7, 2020 at 2:29 PM Arvind Sankar wrote: > > > > > > On Fri, Aug 07, 2020 at 12:41:00PM -0700, Nick Desaulniers wrote: > > > > A recent change to a default value of configuration variable > > > > (ENABLE_X86_RELAX_RELOCATIONS OFF -> ON) in LLVM now causes Clang's > > > > integrated assembler to emit R_X86_64_GOTPCRELX/R_X86_64_REX_GOTPCRELX > > > > relocations. LLD will relax instructions with these relocations based on > > > > whether the image is being linked as position independent or not. When > > > > not, then LLD will relax these instructions to use absolute addressing > > > > mode (R_RELAX_GOT_PC_NOPIC). This causes kernels built with Clang > > > > and linked with LLD to fail to boot. > > > > > > It could also cause kernels compiled with gcc and linked with LLD to > > > fail in the same way, no? The gcc/gas combination will generate the > > > relaxed relocations from I think gas-2.26 onward. Although the only > > > troublesome symbol in the case of gcc/gas is trampoline_32bit_src, > > > referenced from pgtable_64.c (gcc doesn't use a GOTPC reloc for _pgtable > > > etc). > > > > Thanks for taking a look, and the feedback. I appreciate it! > > > > $ gcc --version | head -n 1 > > gcc (Debian 9.3.0-11) 9.3.0 > > $ make -j71 clean defconfig bzImage > > $ llvm-readelf -r arch/x86/boot/compressed/*.o | grep -e > > R_X86_64_GOTPCRELX -e R_X86_64_REX_GOTPCRELX > > 0000000000000114 000000120000002a R_X86_64_REX_GOTPCRELX > > 0000000000000000 trampoline_32bit_src - 4 > > $ llvm-readelf -r arch/x86/boot/compressed/vmlinux | grep -e > > R_X86_64_GOTPCRELX -e R_X86_64_REX_GOTPCRELX > > $ > > > > So it looks like yes. I guess then we'd need to add a check for > > CONFIG_LD_IS_LLD and CONFIG_CC_IS_GCC and binutils version is 2.26+? > > I don't mind adding support for that combination, but I'd like to skip > > it in this patch for the sake of backporting something small to stable > > to get our CI green ASAP, since CONFIG_LD_IS_LLD probably doesn't > > exist for those stable branches, which will complicate the backport of > > such a patch. So I'd do it in a follow up patch if we're cool with > > that? > > > > What if we did it only if we couldn't enable -pie, like the below patch? > I think this should cover all the cases without needing LD_IS_LLD > checks. > > For BFD, the only case that should change is binutils-2.26, which > supports relaxations but not -z noreloc-overflow, and will now have > relax-relocations disabled. It currently works (with gcc) only because > the relaxation of > movq foo@GOTPCREL(%rip), %reg > to > movq $foo, %reg > in the non-pie case was only added in 2.27, which is also when -z > noreloc-overflow was added, allowing -pie to be enabled. With 2.26, it > only gets relaxed to > leaq foo(%rip), %reg > which is all LLD currently does as well. Sure, that will work, too. If you'd like to send it along, please add my: Reviewed-by: Nick Desaulniers Tested-by: Nick Desaulniers > > diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile > index 8abc30b27ba3..d25bb71f195a 100644 > --- a/arch/x86/boot/compressed/Makefile > +++ b/arch/x86/boot/compressed/Makefile > @@ -60,6 +60,13 @@ else > KBUILD_LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \ > && echo "-z noreloc-overflow -pie --no-dynamic-linker") > endif > + > +# Disable relocation relaxation if not building as PIE > +ifeq ($(filter -pie,$(KBUILD_LDFLAGS)),) > +KBUILD_CFLAGS += $(call as-option, -Wa$(comma)-mrelax-relocations=no) > +KBUILD_AFLAGS += $(call as-option, -Wa$(comma)-mrelax-relocations=no) > +endif > + > LDFLAGS_vmlinux := -T > > hostprogs := mkpiggy -- Thanks, ~Nick Desaulniers