Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp117430imu; Thu, 15 Nov 2018 23:15:14 -0800 (PST) X-Google-Smtp-Source: AJdET5eOfssCau4mNDYcPaNTOegmDLWHSIrR1X+dyuu9ZmiF3c1rs4FXBBPly60IfcV3/oIPVetp X-Received: by 2002:a65:63d3:: with SMTP id n19mr9011813pgv.179.1542352514149; Thu, 15 Nov 2018 23:15:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542352514; cv=none; d=google.com; s=arc-20160816; b=eEEy0CSpnhN4v40ItJFFPkSSaxW6BjTA9ms7h/tS25YZ7uuFArqsCSkok9IcdRCmil 5Wwfqt490mIAjoPXXw275guwVllFOVqoOAWaIKwV09Y2phvGIKTHuBYNyrr99JhZO639 FuGdwz1s70bvk5iWJQ9Bvdtwqh3qpKigBuXE/Q30HtBIMLcbKLcdG/lw9RTsolhZAAzB QwE1MJYNRN4u3KLZgJ8TF9N4OBM1/xu35TCZNVJ7kfNTzTjVd5u+VsYBv9WAlCY8oLDn mE28LPDfvTyjP3rgxJKtlyUWSoIDqHYQhLJhu5v00lMc5fPJZS8apFYfqHYK31IXGab5 3EuA== 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:dkim-filter; bh=VwAIx3Eo70JuM1DePhqDSXkBGEkG28c2bnoZdHYjPng=; b=XbWIyeSuhgvjxlcPwkePoffxpOkOevS8fYoLaZczS3eTBGP5P5VtqUJOG+D8wrdbqr iYjmKAdcH04IAyMD3nAyrJgeMaMxfHDHEYbKxJHJWyjCPB8ABFyww7IErb1QZynfMCXx MkL1DzpLylZ0ohFaL/LzMSEnDhnpQMxpFf76zNGOtPEjUbIztOJBPVqi9WRbeb6/k76Z 26jOcRpEZq3u4akbMTqHje9dBb0OJEmvdXLQjdI87IMiIJxV0gcA4UHt4vN4hmliEd+L 7+eAn6pevt69lTpn3X8ZA0miclAmLNc7jVtarENd/uG6xR8ZRsc90CZGShY+O/z3/o8g QnvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=il4+Fhki; 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 u13si8745784plq.268.2018.11.15.23.14.59; Thu, 15 Nov 2018 23:15:14 -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=@nifty.com header.s=dec2015msa header.b=il4+Fhki; 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 S2389350AbeKPRZa (ORCPT + 99 others); Fri, 16 Nov 2018 12:25:30 -0500 Received: from conssluserg-01.nifty.com ([210.131.2.80]:24450 "EHLO conssluserg-01.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727380AbeKPRZ3 (ORCPT ); Fri, 16 Nov 2018 12:25:29 -0500 Received: from mail-vs1-f52.google.com (mail-vs1-f52.google.com [209.85.217.52]) (authenticated) by conssluserg-01.nifty.com with ESMTP id wAG7E9MA025107; Fri, 16 Nov 2018 16:14:10 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-01.nifty.com wAG7E9MA025107 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1542352450; bh=VwAIx3Eo70JuM1DePhqDSXkBGEkG28c2bnoZdHYjPng=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=il4+Fhki/Ny6Y2kEvKB4T7WQIBHEQ5GAChASHid4ELRP68uEW0tnEVegmfNLVuE33 TbiUOGOJZaINu4Dqa0TNgVJfP1kGNDKR0l//CElICazrF2VD7BdTplW4qb0yJYd4BI LfdZ3CMNwzHDR3jb64I39P7DQJwsdwVDQM6bMA5/cQVqW+OmNuo61UmCIFXhknfUtL Kjv5vNeDjVB2CHUajzWyA5htGPmZMKDfcX+MlvOKA50KmcXLOf2tl7NqOCgJhyPjg9 Dl8+XiYnOUximc2zTtsOesi/x4n2GzQ/UARHwGPhCJCC9Na+DBquuB5+y8SkYIZNki Fkz1mX59RCWMA== X-Nifty-SrcIP: [209.85.217.52] Received: by mail-vs1-f52.google.com with SMTP id p74so13227762vsc.0; Thu, 15 Nov 2018 23:14:10 -0800 (PST) X-Gm-Message-State: AGRZ1gLQAha5jCZ57TzJzgI985JbOdRrdPuNirrj/vvBML7Evn0G43lj jj3AomVKIxrcNA0tceZvxLD99aHIYPJSlBPGW/c= X-Received: by 2002:a67:385a:: with SMTP id f87mr4064061vsa.179.1542352449248; Thu, 15 Nov 2018 23:14:09 -0800 (PST) MIME-Version: 1.0 References: <1542270435-11181-1-git-send-email-yamada.masahiro@socionext.com> <1542270435-11181-5-git-send-email-yamada.masahiro@socionext.com> In-Reply-To: From: Masahiro Yamada Date: Fri, 16 Nov 2018 16:13:33 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 4/8] kbuild: simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS To: Nicolas Pitre Cc: Linux Kbuild mailing list , Sam Ravnborg , Rasmus Villemoes , linux-arch , Arnd Bergmann , Michael Ellerman , Linux Kernel Mailing List , Michal Marek , Will Deacon , Ingo Molnar , Ard Biesheuvel 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, Nov 16, 2018 at 2:13 PM Nicolas Pitre wrote: > > On Thu, 15 Nov 2018, Masahiro Yamada wrote: > > > My main motivation of this commit is to clean up scripts/Kbuild.include > > and scripts/Makefile.build. > > > > Currently, CONFIG_TRIM_UNUSED_KSYMS works with a tricky gimmick; > > possibly exported symbols are detected by letting $(CPP) replace > > EXPORT_SYMBOL* with a special string '=== __KSYM_*===', which is > > post-processed by sed, and passed to fixdep. The extra preprocessing > > is costly, and hacking cmd_and_fixdep is ugly. > > > > I came up with a new way to find exported symbols; insert a dummy > > symbol __ksym_marker_* to each potentially exported symbol. Those > > dummy symbols are picked up by $(NM), post-processed by sed, then > > appended to .*.cmd files. I collected the post-process part to a > > new shell script scripts/gen_ksymdeps.sh for readability. The dummy > > symbols are put into the .discard.* section so that the linker > > script rips them off the final vmlinux or modules. > > Brilliant! I really like it. > > Minor comments below. > > > diff --git a/include/asm-generic/export.h b/include/asm-generic/export.h > > index 4d73e6e..294d6ae 100644 > > --- a/include/asm-generic/export.h > > +++ b/include/asm-generic/export.h > > @@ -59,16 +59,19 @@ __kcrctab_\name: > > .endm > > #undef __put > > > > -#if defined(__KSYM_DEPS__) > > - > > -#define __EXPORT_SYMBOL(sym, val, sec) === __KSYM_##sym === > > - > > -#elif defined(CONFIG_TRIM_UNUSED_KSYMS) > > +#if defined(CONFIG_TRIM_UNUSED_KSYMS) > > > > #include > > #include > > > > +.macro __ksym_marker sym > > + .section ".discard.ksym","a" > > +__ksym_marker_\sym: > > + .previous > > Does this work as intended? I have vague memories about having problems > with sections being discarded when they don't allocate any space. What I can tell is, this patch produces the same size kernel (after dropping debug info by 'strip' command). > > +.endm > > + > > #define __EXPORT_SYMBOL(sym, val, sec) \ > > + __ksym_marker sym; \ > > __cond_export_sym(sym, val, sec, __is_defined(__KSYM_##sym)) > > #define __cond_export_sym(sym, val, sec, conf) \ > > ___cond_export_sym(sym, val, sec, conf) > > diff --git a/include/linux/export.h b/include/linux/export.h > > index ce764a5..0413a3d 100644 > > --- a/include/linux/export.h > > +++ b/include/linux/export.h > > @@ -92,22 +92,22 @@ struct kernel_symbol { > > */ > > #define __EXPORT_SYMBOL(sym, sec) > > > > -#elif defined(__KSYM_DEPS__) > > +#elif defined(CONFIG_TRIM_UNUSED_KSYMS) > > + > > +#include > > > > /* > > * For fine grained build dependencies, we want to tell the build system > > * about each possible exported symbol even if they're not actually exported. > > - * We use a string pattern that is unlikely to be valid code that the build > > - * system filters out from the preprocessor output (see ksym_dep_filter > > - * in scripts/Kbuild.include). > > + * We use a symbol pattern __ksym_marker_ that the build system filters > > + * from the $(NM) output (see scripts/gen_ksymdep.sh). These symbols are > > + * discarded in the final link stage. > > */ > > -#define __EXPORT_SYMBOL(sym, sec) === __KSYM_##sym === > > - > > -#elif defined(CONFIG_TRIM_UNUSED_KSYMS) > > - > > -#include > > +#define __ksym_marker(sym) \ > > + static int __ksym_marker_##sym[0] __section(".discard.ksym") __used > > Even if this is discarded during the final link, maybe this could save > a tiny amount of disk space by using a char instead? I am afraid you missed '[0]' after the symbol name. This is actually zero-length array. No memory allocated for this dummy section. As far as I tested, this is working. > > diff --git a/scripts/Makefile.build b/scripts/Makefile.build > > index 7f3ca6e..e5ba9b1 100644 > > --- a/scripts/Makefile.build > > +++ b/scripts/Makefile.build > > @@ -254,9 +254,18 @@ objtool_dep = $(objtool_obj) \ > > $(wildcard include/config/orc/unwinder.h \ > > include/config/stack/validation.h) > > > > +ifdef CONFIG_TRIM_UNUSED_KSYMS > > +cmd_gen_ksymdeps = \ > > + $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ > $(dot-target).tmp; \ > > + cat $(dot-target).tmp >> $(dot-target).cmd; \ > > + rm -f $(dot-target).tmp; > > Why don't you append to $(dot-target).cmd directly? If scripts/gen_ksymdeps.sh fails for some reasons, it will error out immediately thanks to 'set -e' flag. Appending incomplete portion might end up with a corrupted .*.cmd file. Probably, that would not happen, but I just wanted to ensure it. > > Nicolas -- Best Regards Masahiro Yamada