Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp799122ybv; Sat, 22 Feb 2020 15:35:20 -0800 (PST) X-Google-Smtp-Source: APXvYqyDWJKv6/clpCJhfVKxMnoo5GpJQaNrTKZNKqrh1ezpsXwZp8ifV1J3pGtlhXHouX+8BRiG X-Received: by 2002:aca:eccd:: with SMTP id k196mr7292896oih.95.1582414520607; Sat, 22 Feb 2020 15:35:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582414520; cv=none; d=google.com; s=arc-20160816; b=SjDzve6rbyWjtMhmTLHJfsAppiDCQER/vBtLEPoi76Rx0kH+TtKjmttHKusC+VpilO TDDzYdfRCIqjQEzMQ1W0xfwMVFwKIJS/NTuI+CcywUjz5p2s8KYjQI4oc1UW9ELBqzWe 4A+y7ZkXuaHKc6P27v1fRxqib3jyoHI/+7Jn2jtH5kfVGkySpDdBXqzwTmijW44dzdeT isxLRWxcK2vd2+WWSTVKLbhcowS2KKrc8UKpu2O7MInDHX7+rMGIS3P9w3I2wzZkfZc0 Hax8tuRuPpI2ZXAi4GGVUYzKrO2aJIsyT62CYseARh0Xz9tPiZEiD8ZNXEVta/Aa6+CG 9m2Q== 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=uHfmwLnIUqXAiwLNkRBchsGXQLdmwgnefDEPy9uPxHc=; b=rR+ZG2/6Ic9Mn/Malaqfs+rAA+5kXUAdpJZjcn2nipsmZognwXRCpU7udlYwa9X+22 Qurc1uSXsoBvCPA6krjsRD1ZO6zyZV1aofF1mmPa4noGTG+fqWX2cevs62XaXk0Pon13 gVw4p14gt0sm3kgpubTW00SYtB/eZc5kqJ0keCh2PuBzJxFqfRLzUBDNu+Vjq7bv+TuC uPUWvNirfapWKxhMVeN9WthucM8LCcHnKINxqGk7J0QyoP1zFPhKbLIMlI1GdjSVJWGe /WcTNA5MInc6gw0ZNZDqBcVngkmoUtbi7SXeg9y9GVU4XeVSIpEZhCUwcqnEpq5GeNp7 ZlbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=JFIBQ86P; 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 j70si3350001oib.219.2020.02.22.15.35.07; Sat, 22 Feb 2020 15:35:20 -0800 (PST) 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=JFIBQ86P; 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 S1726965AbgBVXdf (ORCPT + 99 others); Sat, 22 Feb 2020 18:33:35 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:46634 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726864AbgBVXdf (ORCPT ); Sat, 22 Feb 2020 18:33:35 -0500 Received: by mail-pl1-f193.google.com with SMTP id y8so2433897pll.13 for ; Sat, 22 Feb 2020 15:33:33 -0800 (PST) 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=uHfmwLnIUqXAiwLNkRBchsGXQLdmwgnefDEPy9uPxHc=; b=JFIBQ86PX40lycOJupY2A+tQRN4Xn1ZW5uQjrBrneSel/4FPHMEYdntyDBW7PLo3en M+gT6aU+wirPeqLwD8EV1EFoQaQacXkxzkSb+e4UN6N3zf2+RU0HExJpwh1VLpkP9aQH LLSd1tMLCOpxMpo0+djX6FzWi4CqPCoF3kYHnKDP2Nzm8hX9U5t/gJsS1BYq/cVOtH88 f5UGJJy0ZJgc53ORJIHxRukvrC1BPLGIq/n178hrxRa9M2l/yV43qrW1MNhlwRP2d3T/ BQ5UGnwLbjxObA+adp4VqrGTgSieF82C3aXvz15IgKMc/YisYk5qpd9DZh0n4r5r5RXG 3LTg== 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=uHfmwLnIUqXAiwLNkRBchsGXQLdmwgnefDEPy9uPxHc=; b=HhzEWmO8bdmk6OcJWRepGQL6kQlZoQKzLjx9Ha2DqfvWrRMcUS9XnV/S6+RC0TFVeM jR3M3SVWS0z/SZXLvkT3vQ03rq0WNhZ7yYQeYosf5iDc5A9WKamaxeecnuk/79LBtFmM 6F2Ywpw+aPINsnsbFAVzpt/kBSw27MiNXiavdVC3IDYDZqOcy7RDU/p8yaE/6whYcpwm SNBZj0JDBJO1kJIQNNzPgHxEAuJS5GGCqYeWIwcLfzKx0fs4pvtufB7qZoKmy3X1f2yW SGSUho76nYZrdU2gjkteSry65jwFlDXBf7y0CfeGPK9sYx1UKnEseK7QfwkVkKMQo4pt HpJw== X-Gm-Message-State: APjAAAVT1FiUKj8fpyXD6Rvz4VKPPLpPgRFZjdQOIasbwH4K2sjnYjLW VsMKi4VRXABckQWJqCdN1XBuPIwONAWHRSH1gYullw== X-Received: by 2002:a17:902:760e:: with SMTP id k14mr41180763pll.119.1582414412419; Sat, 22 Feb 2020 15:33:32 -0800 (PST) MIME-Version: 1.0 References: <20200222164419.GB3326744@rani.riverdale.lan> <20200222171859.3594058-1-nivedita@alum.mit.edu> <20200222181413.GA22627@ubuntu-m2-xlarge-x86> <20200222185806.ywnqhfqmy67akfsa@google.com> <20200222201715.GA3674682@rani.riverdale.lan> <20200222210101.diqw4zt6lz42ekgx@google.com> In-Reply-To: <20200222210101.diqw4zt6lz42ekgx@google.com> From: Nick Desaulniers Date: Sat, 22 Feb 2020 15:33:20 -0800 Message-ID: Subject: Re: [PATCH] x86/boot/compressed: Fix compressed kernel linking with lld To: Arvind Sankar , Borislav Petkov Cc: Nathan Chancellor , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , LKML , clang-built-linux , Michael Matz , Fangrui Song , Kees Cook 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 Sat, Feb 22, 2020 at 1:01 PM 'Fangrui Song' via Clang Built Linux wrote: > > On 2020-02-22, Arvind Sankar wrote: > >On Sat, Feb 22, 2020 at 10:58:06AM -0800, Fangrui Song wrote: > >> On 2020-02-22, Nathan Chancellor wrote: > >> >On Sat, Feb 22, 2020 at 12:18:59PM -0500, Arvind Sankar wrote: > >> >> Commit TBD ("x86/boot/compressed: Remove unnecessary sections from > >> >> bzImage") discarded unnecessary sections with *(*). While this works > >> >> fine with the bfd linker, lld tries to also discard essential sections > >> >> like .shstrtab, .symtab and .strtab, which results in the link failing > >> >> since .shstrtab is required by the ELF specification. .symtab and > >> >> .strtab are also necessary to generate the zoffset.h file for the > >> >> bzImage header. > >> >> > >> >> Since the only sizeable section that can be discarded is .eh_frame, > >> >> restrict the discard to only .eh_frame to be safe. > >> >> > >> >> Signed-off-by: Arvind Sankar > >> >> --- > >> >> Sending as a fix on top of tip/x86/boot. > >> >> > >> >> arch/x86/boot/compressed/vmlinux.lds.S | 4 ++-- > >> >> 1 file changed, 2 insertions(+), 2 deletions(-) > >> >> > >> >> diff --git a/arch/x86/boot/compressed/vmlinux.lds.S b/arch/x86/boot/compressed/vmlinux.lds.S > >> >> index 12a20603d92e..469dcf800a2c 100644 > >> >> --- a/arch/x86/boot/compressed/vmlinux.lds.S > >> >> +++ b/arch/x86/boot/compressed/vmlinux.lds.S > >> >> @@ -74,8 +74,8 @@ SECTIONS > >> >> . = ALIGN(PAGE_SIZE); /* keep ZO size page aligned */ > >> >> _end = .; > >> >> > >> >> - /* Discard all remaining sections */ > >> >> + /* Discard .eh_frame to save some space */ > >> >> /DISCARD/ : { > >> >> - *(*) > >> >> + *(.eh_frame) > >> >> } > >> >> } > >> >> -- > >> >> 2.24.1 > >> >> > >> > > >> >FWIW: > >> > > >> >Tested-by: Nathan Chancellor > >> > >> I am puzzled. Doesn't -fno-asynchronous-unwind-tables suppress > >> .eh_frame in the object files? Why are there still .eh_frame? > >> > >> Though, there is prior art: arch/s390/boot/compressed/vmlinux.lds.S also discards .eh_frame > > > >The compressed kernel doesn't use the regular flags and it seems it > >doesn't have that option. Maybe we should add it in to avoid generating > >those in the first place. Ah, yikes. For reference, please see my commit: commit b059f801a937 ("x86/purgatory: Use CFLAGS_REMOVE rather than reset KBUILD_CFLAGS") I'm of the conviction that reassigning KBUILD_CFLAGS via `:=`, as opposed to strictly filtering flags out of it or appending to it, is an antipattern. We very very carefully construct KBUILD_CFLAGS in top level and arch/ Makefiles, and it's very easy to miss a flag or to when you "reset" KBUILD_CFLAGS. *Boom* Case in point. I meant to audit the rest of the places we do this in the kernel, but haven't had the time to revisit arch/x86/boot/compressed/Makefile. For now, I suggest: 1. revert `Commit TBD ("x86/boot/compressed: Remove unnecessary sections from bzImage")` as it runs afoul differences in `*` for `DISCARD` sections between linkers, as the intent was to remove .eh_frame, of which it's less work to not generate them in the first place via compiler flag, rather than generate then discard via linker. 2. simply add `KBUILD_CFLAGS += -fno-asynchronous-unwind-tables` to arch/x86/boot/compressed/Makefile with Fangrui's Sugguested-by tag. 3. Remind me to revisit my proposed cleanup of arch/x86/boot/compressed/Makefile (which eventually will undo #2). ;) 4. tglx to remind me that my compiler is broken and that I should fix it. :P > > > >The .eh_frame discard in arch/x86/kernel/vmlinux.lds.S does seem > >superfluous though. > > Yes, please do that. I recommend suppressting unneeded sections at > compile time, instead of discarding them at link time. > > https://github.com/torvalds/linux/commit/83a092cf95f28696ddc36c8add0cf03ac034897f > added -Wl,--orphan-handling=warn to arch/powerpc/Makefile . > x86 can follow if that is appropriate. Kees has patches for that; I recommend waiting on his series. > I don't recommend -Wl,--orphan-handling=error, which can unnecessarily > break the builds. Agreed. Until we have CI testing with LLD which is a WIP (action item on me). -- Thanks, ~Nick Desaulniers