Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2953056ybv; Mon, 24 Feb 2020 15:09:24 -0800 (PST) X-Google-Smtp-Source: APXvYqwSIhVijGCTl5ekdofSU6YA66XtkVlH6BvvsWFaT1bO9WmW6wbC8v2KF/qG+EralFYZ/fqP X-Received: by 2002:a9d:6301:: with SMTP id q1mr40984200otk.299.1582585764726; Mon, 24 Feb 2020 15:09:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582585764; cv=none; d=google.com; s=arc-20160816; b=UsIllvIE0JNyZ+HOEVXUL3cBz9rIyUluhdUO6huLk1hr8T+IzLe4JUzVS0wF3vSL/p HUhTn6TwC8pqoWB7mBhqXugOKloLs6a+1Dv1ufsiTmY7303be6zNBLO3mFrs2nOxYESs OHC6DczA0csTlbiqDlS1ykaMezfEyRsrwM5ASwKgMJQlGc3QxQL8XygP86N9KqNRC6zT YZGraHaUtuz0FFsLUvKnhy6xPIqR6Tvb5fpBIYaRaITpVwuDY+FDV8u1eMwk+RqGl2UF D5T6yO7bnbKbZBci+g4gGYQDDa0p5/1Ujg93Hbs+OOg4/EkJovJ1ts7FMG7S5DtI+t+k 78xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=K/3B2abZ2PBE11q9O8trcN53LJz/Y46vhRJiFNVlNjE=; b=lAPOzphBunydoJysU4XwTycZZ4Jp9rbKjpJmdAcUSJNrCo8m/CC9VDfLwGJ16Z8EE2 CR4undpwbXIYK2F/YVNZws5tDZJYbiisZL1eeXcCOUxn43ApgSHwSETiKMN1314dscVC ThExntMsDi+81oK6xaV1TZ2cbIh7MYti2IZwoFI4SA5H2woLeWllMA+0gWO2a7rSt3iA b7HAar48+yFvYMa44rAZu49Rdcz8H9+8TK2U/epQG15rmbf0Ai14UzSCMRY7+/tOD3L9 rpx3bYGfUgPbztbMzNuf5t6KFIIM6gmSyCf1wtWSCqDpcR/S2/M7v5R50hJAzasunjDd yCZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ZJQfuOa4; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v21si1588749otp.189.2020.02.24.15.09.10; Mon, 24 Feb 2020 15:09:24 -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=fail header.i=@gmail.com header.s=20161025 header.b=ZJQfuOa4; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728434AbgBXXIi (ORCPT + 99 others); Mon, 24 Feb 2020 18:08:38 -0500 Received: from mail-qk1-f196.google.com ([209.85.222.196]:35958 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728357AbgBXXIe (ORCPT ); Mon, 24 Feb 2020 18:08:34 -0500 Received: by mail-qk1-f196.google.com with SMTP id f3so7354604qkh.3 for ; Mon, 24 Feb 2020 15:08:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=K/3B2abZ2PBE11q9O8trcN53LJz/Y46vhRJiFNVlNjE=; b=ZJQfuOa4PmMxgwNEyZ6LbhqGYDrh/NXEos30/OO8oYeHjhLasX46l3geY6DYzl4SoT A5+rgGQX/fo6zsfo0klq8ZAphcq4fDYw3J/MsZtMdR/P1uF0bMd1N6TLLubpi54nddF8 ZV2Lvt6SmVFmJ85zetUMSTb3KQ84s7GRRhjlnyPpkiLEMYOdMem6Cg4n1JTOi5favvdn uGVCcWcdP6vgUY/etcNj4bc++Q4AukRLnsMg54OgNTVY0yP4lcxxmcJhT6igJriEZhu3 +9IrwT87rpdudARyQSlqdXXpOAJKwMrYTiUI+ZvPaeLKokZA3jl7WLFCbXwOosz/Ms4h f7bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=K/3B2abZ2PBE11q9O8trcN53LJz/Y46vhRJiFNVlNjE=; b=USmyCRzXohRBvAZQ+gGAJ5DpXIyixMBg8OwgRQZUygNDDt15ru3jV9lNZUfAqpMKyF tcpaoE8g8ctFOk8JRex6BR0GiCbT565rtKdd/Pm7xEgDSRqQT1FNFuhdrVXgv/m5lT74 5+53tdTOazTobW7gUhC4TLWJ7Mqet6eDhIL+ar1l0VoLuf34nc8xrAsxx6IcoKHj4PiE /jsSSvkZlpjWr7Q4cMdTnjZHUI/X46JaneUWTblVHHYgWD5cX0EyKv3wJNwwQx2KteWB aKZRhv0OHz3s5bHWvNVNIWjUqysNLEkEg2O8iP/hEY3NRwEOaMbtuqTKjejn8DX+vLh7 QWFQ== X-Gm-Message-State: APjAAAU+pS1cZ2XvLIe1sJatsR7I0egm8wEGOkshp/P2mWo/7LFss28Q wzdEbNx3MvNbf4k1QWYCwDA= X-Received: by 2002:a37:40d2:: with SMTP id n201mr53037062qka.211.1582585711270; Mon, 24 Feb 2020 15:08:31 -0800 (PST) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id z18sm2813397qki.8.2020.02.24.15.08.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2020 15:08:31 -0800 (PST) From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Mon, 24 Feb 2020 18:08:29 -0500 To: Fangrui Song Cc: Arvind Sankar , Nick Desaulniers , Michael Matz , Borislav Petkov , Nathan Chancellor , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , LKML , clang-built-linux , Kees Cook Subject: Re: [PATCH 2/2] x86/boot/compressed: Remove unnecessary sections from bzImage Message-ID: <20200224230829.GA586317@rani.riverdale.lan> References: <20200222074254.GB11284@zn.tnic> <20200222162225.GA3326744@rani.riverdale.lan> <20200224212828.xvxl3mklpvlrdtiw@google.com> <20200224214845.GC409112@rani.riverdale.lan> <20200224221703.eqql5hrx4ccngwa5@google.com> <20200224224343.GA572699@rani.riverdale.lan> <20200224225059.2scjklfi4g7wwdkp@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200224225059.2scjklfi4g7wwdkp@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 24, 2020 at 02:50:59PM -0800, Fangrui Song wrote: > On 2020-02-24, Arvind Sankar wrote: > >On Mon, Feb 24, 2020 at 02:17:03PM -0800, Fangrui Song wrote: > >> On 2020-02-24, Arvind Sankar wrote: > >> >On Mon, Feb 24, 2020 at 01:28:28PM -0800, Fangrui Song wrote: > >> >> Hi Michael, please see my other reply on this thread: https://lkml.org/lkml/2020/2/24/47 > >> >> > >> >> Synthesized sections can be matched as well. For example, SECTIONS { .pltfoo : { *(.plt) }} can rename the output section .plt to .pltfoo > >> >> It seems that in GNU ld, the synthesized section is associated with the > >> >> original object file, so it can be written as: > >> >> > >> >> SECTIONS { .pltfoo : { a.o(.plt) }} > >> >> > >> >> In lld, you need a wildcard to match the synthesized section *(.plt) > >> >> > >> >> .rela.dyn is another example. > >> >> > >> > > >> >With the BFD toolchain, file matching doesn't actually seem to work at > >> >least for .rela.dyn. I've tried playing around with it in the past and > >> >if you try to use file-matching to capture relocations from a particular > >> >input file, it just doesn't work sensibly. > >> > >> I think most things are working in GNU ld... > >> > >> /* a.x */ > >> SECTIONS { > >> .rela.pltfoo : { a.o(.rela.plt) } /* *(.rela.plt) with lld */ > >> .rela.dynfoo : { a.o(.rela.data) } /* *(.rela.dyn) with lld */ > >> } > > > >The file matching doesn't do anything sensible. If you split your .data > >section out into b.s, and update the linker script so it filters for > >b.o(.rela.data), .rela.dynfoo doesn't get created, instead the default > >.rela.dyn will contains the .data section relocation. If you keep the > >filter as a.o(.rela.data), you get .rela.dynfoo, even though a.o doesn't > >actually contain any .rela.data section any more. > > I raised the examples to support my viewpoint "synthesized sections can > be matched, as well as input sections." > > If there is really a need (rare, not recommended) to rename output > sections only consisting of synthesized sections (e.g. .plt .rela.dyn), > for linker portability, it is better using a wildcard for the input > filename pattern. Yep, you have to use * for the filename. My comment was only addressing the fact that this part isn't accurate: > >> >> It seems that in GNU ld, the synthesized section is associated with the > >> >> original object file, so it can be written as: I can't make head or tail of how GNU ld decides what file to associate with the synthesized sections. Also, even section name matching doesn't work with all synthesized sections -- it's not possible to match .strtab or .shstrtab with GNU ld in order to rename them, in addition to not being able to discard them, while that does work with LLD. > > As another example, SECTIONS { /DISCARD/ : { *(.rela.*) } } discards synthesized .rela.* > > >> > >> % cat < a.s > >> .globl foo > >> foo: > >> call bar > >> .data > >> .quad quz > >> e > >> % as a.s -o a.o > >> % ld.bfd -T a.x a.o -shared -o a.so