Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp759926ybl; Wed, 29 Jan 2020 09:12:50 -0800 (PST) X-Google-Smtp-Source: APXvYqzuuoQlDqkpWRUJwJm9TxybApdXd4uL9ch9oNhGah8Kc+2LJsOeWP3YAjJqkxDzE+n2bMRY X-Received: by 2002:a54:448b:: with SMTP id v11mr6917928oiv.74.1580317970370; Wed, 29 Jan 2020 09:12:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580317970; cv=none; d=google.com; s=arc-20160816; b=tTHQK/8PALuUjqqi3pcdBfo+WfcdviKypA2b/DIj09W6OdrgBe8V+y9wTx86uhbyvh qwVXP4FBnmlT9IbSc+2NZ5w5LQ99Wk/EIHAv80xPgi2a5ebAM+ULExXQwoN5wKr1jeMy eEqgpRBj/2QQgN47utTOJV9mTRVSzNhzd7s/wfJNjksbK2/tYxakWLoyrpLA/0I0jamg OVSYRi7ViWxPdtIYhncMwxCab4Ej6nN7CnPJgkGLxE72EWVGzm1kMraR+stdKTNAwbm6 HxCjJ/ZjiTluS/KO0KakpTiJ2+pNxA6QClBDMXjhIEj2s3Nrat2nsmi36kWDpaGg+lU4 Ephg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=NNy65g8Tj8JplrZaOzfzmSD/qiSvD4Evjzg9nPH/SBQ=; b=gbj3XHJA6baER3RSdzkP8evHs3i7PxejqsTt3mbTGTeJW9Y/NVjZ4Feo3fxP33a+Gb jWJQF+HGkNlfv0Oew8gxB4uGJSeFhlQcg0NI2XKG4tjoqHjrZ75E5sf403kqs2Xwbd8A F0sqOOS7jIJtkHMxtplRT7pXZ5ybeTj7CP75iBvpiQ5NV87dnbEmzBATa82N72sJVHW2 Kh7A1TLC9pJ5cgem+34e/Q8KzFERtTfknLmlU0NZulwVr59+tJGhq08QilWHUkE7pRbG CTd56XPO01QpXURJlRvfbX+Oy3BQpMRYoxq5gkW9fG2/A1bvrNjV/rOU5sPLua96kYbJ uWeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pobox.com header.s=sasl header.b=WVZsbjym; dkim=temperror (no key for signature) header.i=@fluxnic.net header.s=2016-12.pbsmtp header.b=YpLyGfzm; 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 c196si1380012oib.36.2020.01.29.09.12.37; Wed, 29 Jan 2020 09:12:50 -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=@pobox.com header.s=sasl header.b=WVZsbjym; dkim=temperror (no key for signature) header.i=@fluxnic.net header.s=2016-12.pbsmtp header.b=YpLyGfzm; 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 S1727193AbgA2RLT (ORCPT + 99 others); Wed, 29 Jan 2020 12:11:19 -0500 Received: from pb-smtp20.pobox.com ([173.228.157.52]:52474 "EHLO pb-smtp20.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726647AbgA2RLT (ORCPT ); Wed, 29 Jan 2020 12:11:19 -0500 Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 4FBA4B7BF5; Wed, 29 Jan 2020 12:11:17 -0500 (EST) (envelope-from nico@fluxnic.net) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=date:from:to :cc:subject:in-reply-to:message-id:references:mime-version :content-type; s=sasl; bh=yhpprhRgYxzLs+VKpBm5f0Z6eus=; b=WVZsbj ymcLJjf3ZB9GMSGBhB6rfJdNgHo71cWLjttm4HZ6t/V93kD+p3aAqKP+H27y06h8 mbDK3a+/p52ByA3lOwkN0x6PEx8TnAv3TTgMK3NFKfC2chAv7LFW89Lnjn2FTj4V Yna4h5LICSO4yyy6QhLo9jp/Ur9chpID+cQT0= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 48010B7BF4; Wed, 29 Jan 2020 12:11:17 -0500 (EST) (envelope-from nico@fluxnic.net) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=fluxnic.net; h=date:from:to:cc:subject:in-reply-to:message-id:references:mime-version:content-type; s=2016-12.pbsmtp; bh=9iQOHCEK505gx5TM5IZMQO697Nr7FynB48JFpUkroME=; b=YpLyGfzmEhwRoF8A3FbVzcF1Ft0fW4SDDazy4+2dtpaxEaFHx8Qm30GEnVpiOqfVkDJWH2hKQSbAxQ3hKT3chHLKOBiHpap4yfKEhGALHeWen54EyBmCJw1242ODfSoqRbbygUyCG/K6nhJ1ln6sZV+NQjIemzvTpTKcaTe+8cY= Received: from yoda.home (unknown [24.203.50.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 36C85B7BF3; Wed, 29 Jan 2020 12:11:14 -0500 (EST) (envelope-from nico@fluxnic.net) Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTPSA id 608852DA013B; Wed, 29 Jan 2020 12:11:12 -0500 (EST) Date: Wed, 29 Jan 2020 12:11:12 -0500 (EST) From: Nicolas Pitre To: Quentin Perret cc: masahiroy@kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, maennich@google.com, kernel-team@android.com Subject: Re: [PATCH] kbuild: allow symbol whitelisting with TRIM_UNUSED_KSYMS In-Reply-To: <20200129150612.19200-1-qperret@google.com> Message-ID: References: <20200129150612.19200-1-qperret@google.com> User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Pobox-Relay-ID: 5AC4AC00-42BA-11EA-95E9-B0405B776F7B-78420484!pb-smtp20.pobox.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 29 Jan 2020, 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. The idea is sound to me. But... > diff --git a/scripts/adjust_autoksyms.sh b/scripts/adjust_autoksyms.sh > index a904bf1f5e67..1a6f7f377230 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 | This is a nice trick, however it'll fail if the file path contains spaces or other shell special characters. You could try something like this: [ -z "$CONFIG_UNUSED_KSYMS_WHITELIST" ] \ && whitelist= \ || whitelist="\"$CONFIG_UNUSED_KSYMS_WHITELIST\"" And then... eval cat - $whitelist | ... This way, if $CONFIG_UNUSED_KSYMS_WHITELIST is non empty, it'll get quoted. Nicolas