Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp629566ybl; Fri, 31 Jan 2020 05:16:37 -0800 (PST) X-Google-Smtp-Source: APXvYqzJCXu79tuYh8vxTVkcnzBLcq+tYeUKIH4hpKtKjaow3XkI/mj/Zhf6JIscCPKwwq7iOY8A X-Received: by 2002:aca:514e:: with SMTP id f75mr6521469oib.103.1580476596595; Fri, 31 Jan 2020 05:16:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580476596; cv=none; d=google.com; s=arc-20160816; b=R67Izgmj/gN8N7zA6Rt7Lp3gJNQjZqlkBSpH4zt1AjAFx+z4lHZ1nKaE3AJepIBmAN y3qQ/KghOb+Vc4iShI9ghMMNr6iZJ6F0Wd/zRtDZG81/lMEGHubp1dlMkJZ5qGU1PXst dCtxYcOUuUj1Jf3mDVBFojw1TM0hpE0Gn3x4lnyK7Uq78Jd5mLbTXmnSL1d6wxlG7S4X BQuPqKJdKXafd1oObzF6MjvqwJo9SQCJklGpkiRjAQfWITpjlc38jmqo4kOBUWht2Vvc G74bSHxBS958xWKdfUUdSM1DIVLpUHvkcXF7vAarprP5HwYAOyn0yGpbysOV5JGGNHDZ ErkQ== 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:from:date:dkim-signature; bh=pMGTkZejcRbIEhm2Fn/SJPdUwbiAKkh35s6KFA9Xsfc=; b=AfybH7ujKCQjlANkjyvdx7X6D9A4PMwwxRI0eGoc6VrcMxbsPYhflLiXwmK8+13nbo lpxgL2sno1EyRcaMpzbpMonPeFiVFicxNx6M9zehXcPr86p/Ct5MyUCrjTjwmCeRgCVI rTkHfn3gGSsmDpLjlU4WevQ71sXYsvYjYNTyuq4OT8o88VkLqThhGcuT8iYdsv5AsAOF ZtE2GzGK7Mfbb+VvM/aDlytl48B3bTGjYMgluu2Wuqo5w0zoNNN1bUIp/ZIU3tyvik+t bfMWZlaafZd7Mn1CWYFAMXe5X/WYHlHZ1NQpHDE+WZUFG7/Vtvn57lJQ0x2J9c7yxktl 4Dew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="qTWgpBB/"; 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 w5si4726174otq.238.2020.01.31.05.16.23; Fri, 31 Jan 2020 05:16:36 -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="qTWgpBB/"; 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 S1728713AbgAaNPN (ORCPT + 99 others); Fri, 31 Jan 2020 08:15:13 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:42038 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728598AbgAaNPM (ORCPT ); Fri, 31 Jan 2020 08:15:12 -0500 Received: by mail-wr1-f67.google.com with SMTP id k11so8536134wrd.9 for ; Fri, 31 Jan 2020 05:15:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=pMGTkZejcRbIEhm2Fn/SJPdUwbiAKkh35s6KFA9Xsfc=; b=qTWgpBB//UBaXqSy1KCaPJm3JRr8VTZAggnZ65FCrQvJlKu+0+Bi5mvlq9DAa6CdKV ff2IQffeB5LC4ayEaBByrsHIRuplJMMM0hFhpAg6dzRxWUm93X9F5yk6Nm1hmChUYBxj /pQralfyEIgACFznJA0cucQmE7eOl3WS41WZ1QpuMEYenS+jwYP1QSN7KzCtntd5V6hN A6/BELU+d/IA8hVP/UPG3/6mDCU1p9EYjVjmCTy96WvA1XF6gZZAL1TY2p78s91t/+73 qFtj09OUOUy3ciHpEeaNFdMp41wzM3UX6Rn6KCBTBHe9dFN+UbIibTOGlMAEaqAbUXma 9dAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=pMGTkZejcRbIEhm2Fn/SJPdUwbiAKkh35s6KFA9Xsfc=; b=DE0G26Yo1g3VvIwi91ZSqX+t6QmSZNBUkeBJKowE1IMHuplHJWjS8FtpbmF1JXVS+C D0xFnN9lVpVq4L3bYlJYqKsymXZScyClX/wIVSVEOUbp3vx1s5/dT5sAgnY4nnDSr2yZ iwsZF/AMiPXWETHpDkxmjf8b1WfROMWSEu0wIQzXHXa6D9JLdauw3HV1HK7z1E/iBEg+ jv3cYlalbbsSNiLStCdbZr2l7rzVVxRhlGL4xC93WNZE6XPVYk0vCEG+n74Dqz6heMtt sro1ymZRGV2qghhBDON02teIV9V5ILk+7/w6va+PxzXNMYg0pxQH5iEeKfrF7JoIPS9h Cakg== X-Gm-Message-State: APjAAAVD7iSgMv2xsTlfngdEBqSJPBcHOucIV2I2CwxMlx3FQhmcM8BL QbfelabloF98M1dM7yUkOmwEMw== X-Received: by 2002:adf:9c92:: with SMTP id d18mr579870wre.82.1580476509291; Fri, 31 Jan 2020 05:15:09 -0800 (PST) Received: from google.com ([2a00:79e0:d:210:e8f7:125b:61e9:733d]) by smtp.gmail.com with ESMTPSA id s65sm11218013wmf.48.2020.01.31.05.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jan 2020 05:15:08 -0800 (PST) Date: Fri, 31 Jan 2020 13:15:08 +0000 From: Matthias Maennich To: Quentin Perret Cc: masahiroy@kernel.org, nico@fluxnic.net, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, kernel-team@android.com, jeyu@kernel.org Subject: Re: [PATCH v2] kbuild: allow symbol whitelisting with TRIM_UNUSED_KSYMS Message-ID: <20200131131508.GH102066@google.com> References: <20200129181541.105335-1-qperret@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200129181541.105335-1-qperret@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 Wed, Jan 29, 2020 at 06:15:41PM +0000, Quentin Perret wrote: >CONFIG_TRIM_UNUSED_KSYMS currently removes all unused exported symbols >from ksymtab. This works really well when using in-tree drivers, but >cannot be used in its current form if some of them are out-of-tree. > >Indeed, even if the list of symbols required by out-of-tree drivers is >known at compile time, the only solution today to guarantee these don't >get trimmed is to set CONFIG_TRIM_UNUSED_KSYMS=n. This not only wastes >space, but also makes it difficult to control the ABI usable by vendor >modules in distribution kernels such as Android. Being able to control >the kernel ABI surface is particularly useful to ship a unique Generic >Kernel Image (GKI) for all vendors. > >As such, attempt to improve the situation by enabling users to specify a >symbol 'whitelist' at compile time. Any symbol specified in this >whitelist will be kept exported when CONFIG_TRIM_UNUSED_KSYMS is set, >even if it has no in-tree user. The whitelist is defined as a simple >text file, listing symbols, one per line. Thank you for working on this! I like the idea! > >Signed-off-by: Quentin Perret > >--- >v2: make sure to quote the whitelist path properly (Nicolas) >--- > init/Kconfig | 12 ++++++++++++ > scripts/adjust_autoksyms.sh | 1 + > 2 files changed, 13 insertions(+) > >diff --git a/init/Kconfig b/init/Kconfig >index a34064a031a5..d9c977ef7de5 100644 >--- a/init/Kconfig >+++ b/init/Kconfig >@@ -2180,6 +2180,18 @@ config TRIM_UNUSED_KSYMS > > If unsure, or if you need to build out-of-tree modules, say N. > >+config UNUSED_KSYMS_WHITELIST >+ string "Whitelist of symbols to keep in ksymtab" >+ depends on TRIM_UNUSED_KSYMS >+ help >+ By default, all unused exported symbols will be trimmed from the >+ build when TRIM_UNUSED_KSYMS is selected. >+ >+ UNUSED_KSYMS_WHITELIST allows to whitelist symbols that must be kept >+ exported at all times, even in absence of in-tree users. The value to >+ set here is the path to a text file containing the list of symbols, >+ one per line. >+ > endif # MODULES > > config MODULES_TREE_LOOKUP >diff --git a/scripts/adjust_autoksyms.sh b/scripts/adjust_autoksyms.sh >index a904bf1f5e67..8e1b7f70e800 100755 >--- a/scripts/adjust_autoksyms.sh >+++ b/scripts/adjust_autoksyms.sh >@@ -48,6 +48,7 @@ cat > "$new_ksyms_file" << EOT > EOT > sed 's/ko$/mod/' modules.order | > xargs -n1 sed -n -e '2{s/ /\n/g;/^$/!p;}' -- | >+cat - "${CONFIG_UNUSED_KSYMS_WHITELIST:-/dev/null}" | This handles absolute paths very well. I wonder whether we can make this more useful for folks that want to maintain such a whitelist in their copy of the tree. Lets say, I have in my sources arch/x86/configs/x86_64_symbol_whitelist and in my config I have CONFIG_UNUSED_KSYMS_WHITELIST="arch/x86/configs/x86_64_symbol_whitelist". If I see it correctly, UNUSED_KSYMS_WHITELIST is currently either an absolute path or a relative path to the current build directory. I would prefer if relative paths would be relative to the source directory to support the above use case. (Note, that scenario above works if I build directly in the sources, but fails if I build O=/somewhere/else.) Cheers, Matthias > sort -u | > sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$new_ksyms_file" > >-- >2.25.0.341.g760bfbb309-goog >