Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1843034pxb; Sat, 27 Feb 2021 01:51:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJwsYB5Bh7F0sjB/t/7ILNzYrA97Har5cKhwcCgBA7G01WT8pWl0He5YFgnFbyKTSlIHcew8 X-Received: by 2002:aa7:cdd2:: with SMTP id h18mr7575539edw.38.1614419501995; Sat, 27 Feb 2021 01:51:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614419501; cv=none; d=google.com; s=arc-20160816; b=pP/LwOTaHYl3nsFjgtEJTK1I+Zw3uEWtO6jCDf8pY6wU0UpmzypfThKbKu5Zk7uoJu cd2E0x3YbTuYT6axCyr2WrPx15xI8EA8tgxngK6RlZLXfCXQ+SyjoJcjLmOa5w3URptl uSVdAAJGHT0jg70qNedfMdfLx8O5SwSum3NBWy+9CzGTFSX67+pXCOTrvi1RBrsAdAIe FIEoldg3XT8vzl9lc7A5dHDpMyxp3tqrzrNq/ZqrlWxW//kwFtUbptdQMNfBwed2juaU bnHlT0QnaiO06cxkYgXDrCpP/9WIlt9h5LXxlnaXVTdV34ELS9l9HEymZM5wh5tEZKCI YBtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=RjC8sWt6UvSuJcH8veTYzBozlM/fxqkUrQD0YLsaVtg=; b=VoqTIaBV1m6bp95YuGAKw+lKeLEFUO/gzx87PlSmMolLTFt7lEPnS/7GkhmGzOK7sm u438mwEEgocoyJgTUbtIWYdUmkx7rwWX0Ra8y+yMAPGca/vUQxKQKfsrAxwXh5J8DMH7 iizznbPWgb/l9+ZhECCXv74ttKKefsm5n0PD3ZuKmU5YMhcwRaLNuNWL2ChlIitt6m3h J7AM5LS/fl2Euvs2EV1q0tIm81IVmBJSafHV9wn6ICAf7Rteos78MARpg9C3IIqAaXpb +FpW/8ukeHlEbWKSLFLyjfva6gDTxZ27a8LXdq8fSOWxCUCXi0p1sPUgEmWWkywgjbB2 84iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=A9aZzVI1; 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 g24si7513662edh.565.2021.02.27.01.51.19; Sat, 27 Feb 2021 01:51:41 -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=A9aZzVI1; 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 S230070AbhB0Juh (ORCPT + 99 others); Sat, 27 Feb 2021 04:50:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:57664 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229795AbhB0Juf (ORCPT ); Sat, 27 Feb 2021 04:50:35 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8BE1764ED5 for ; Sat, 27 Feb 2021 09:49:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614419394; bh=QnCKsmX1z+jo5IvDvC2SRFzXJdLgt9XfSJ423kUZSFc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=A9aZzVI1Rt+R7sLFk7A4CWh68L2/CbKXNmqB+i55w+1FDvnGh/MtfDUQe9/HQqFgC L8+84jfTbsuJk5O63BewbLCU8xLhi1ghr2Lz7awL8Oz9XxIdbkoONOvIuxus8OjpAL sm0LoNyU/NxotiXKxcTcpfTSJvjegoNzQ2S8gj0taHjnfYXzpRKmNMlFSOzYsyt0Uh iYKLWq4KZze0BVEsdok6/Ppb8wwd2qkpG3+kUnUZRMptuMmU0TBcVFXTMZ4E2TMo2v xu2x77wZNQwLKD2fFVj+fu8LR40ldBRX6RUy4yKI/UYtbbhtECW632CdXb9udb9RVZ UhhsLwi2JOduA== Received: by mail-oi1-f172.google.com with SMTP id l64so12544322oig.9 for ; Sat, 27 Feb 2021 01:49:54 -0800 (PST) X-Gm-Message-State: AOAM530okQmbyyu12PrlTgOPY7T487QdVt9wkhwXKeRjvDNZsPBq0iLC syZxMkE6u7DksbclyOzYkVoTI9kTuIPhbrM/oco= X-Received: by 2002:aca:c381:: with SMTP id t123mr3973837oif.4.1614419393843; Sat, 27 Feb 2021 01:49:53 -0800 (PST) MIME-Version: 1.0 References: <20210225112122.2198845-1-arnd@kernel.org> <20210226211323.arkvjnr4hifxapqu@google.com> In-Reply-To: <20210226211323.arkvjnr4hifxapqu@google.com> From: Arnd Bergmann Date: Sat, 27 Feb 2021 10:49:37 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] [RFC] arm64: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION To: Fangrui Song Cc: Catalin Marinas , Will Deacon , Nathan Chancellor , Nick Desaulniers , Arnd Bergmann , Kees Cook , Mark Brown , Vincenzo Frascino , Geert Uytterhoeven , Kristina Martsenko , Ionela Voinescu , Mark Rutland , Andrew Scull , David Brazdil , Marc Zyngier , Ard Biesheuvel , Linux ARM , "linux-kernel@vger.kernel.org" , clang-built-linux , Nicholas Piggin Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 26, 2021 at 10:13 PM 'Fangrui Song' via Clang Built Linux wrote: > > For folks who are interested in --gc-sections on metadata sections, > I want to bring you awareness of the implication of __start_/__stop_ symbols and C identifier name sections. > You can see https://github.com/ClangBuiltLinux/linux/issues/1307 for a summary. > (Its linked blog article has some examples.) > > In the kernel linker scripts, most C identifier name sections begin with double-underscore __. > Some are surrounded by `KEEP(...)`, some are not. > > * A `KEEP` keyword has GC root semantics and makes ld --gc-sections ineffectful. > * Without `KEEP`, __start_/__stop_ references from a live input section > can unnecessarily retain all the associated C identifier name input > sections. The new ld.lld option `-z start-stop-gc` can defeat this rule. > > As an example, a __start___jump_table reference from a live section > causes all `__jump_table` input section to be retained, even if you > change `KEEP(__jump_table)` to `(__jump_table)`. > (If you change the symbol name from `__start_${section}` to something > else (e.g. `__start${section}`), the rule will not apply.) I suspect the __start_* symbols are cargo-culted by many developers copying stuff around between kernel linker scripts, that's certainly how I approach making changes to it normally without a deeper understanding of how the linker actually works or what the different bits of syntax mean there. I see the original vmlinux.lds linker script showed up in linux-2.1.23, and it contained + . = ALIGN(16); /* Exception table */ + __start___ex_table = .; + __ex_table : { *(__ex_table) } + __stop___ex_table = .; + + __start___ksymtab = .; /* Kernel symbol table */ + __ksymtab : { *(__ksymtab) } + __stop___ksymtab = .; originally for arch/sparc, and shortly afterwards for i386. The magic __ex_table section was first used in linux-2.1.7 without a linker script. It's probably a good idea to try cleaning these up by using non-magic start/stop symbols for all sections, and relying on KEEP() instead where needed. > There are a lot of KEEP usage. Perhaps some can be dropped to facilitate > ld --gc-sections. I see a lot of these were added by Nick Piggin (added to Cc) in this commit: commit 266ff2a8f51f02b429a987d87634697eb0d01d6a Author: Nicholas Piggin Date: Wed May 9 22:59:58 2018 +1000 kbuild: Fix asm-generic/vmlinux.lds.h for LD_DEAD_CODE_DATA_ELIMINATION KEEP more tables, and add the function/data section wildcard to more section selections. This is a little ad-hoc at the moment, but kernel code should be moved to consistently use .text..x (note: double dots) for explicit sections and all references to it in the linker script can be made with TEXT_MAIN, and similarly for other sections. For now, let's see if major architectures move to enabling this option then we can do some refactoring passes. Otherwise if it remains unused or superseded by LTO, this may not be required. Signed-off-by: Nicholas Piggin Signed-off-by: Masahiro Yamada which apparently was intentionally cautious. Unlike what Nick expected in his submission, I now think the annotations will be needed for LTO just like they are for --gc-sections. Arnd