Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp824683ybl; Wed, 29 Jan 2020 10:17:06 -0800 (PST) X-Google-Smtp-Source: APXvYqyyHs9lbyt3gaHp1jZtCauRyfiN+DPgmUR6ebruwPeRh7c/VtAxM0EksQLzPslFzRDRhM4A X-Received: by 2002:aca:62c4:: with SMTP id w187mr164863oib.38.1580321826427; Wed, 29 Jan 2020 10:17:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580321826; cv=none; d=google.com; s=arc-20160816; b=NQWtBnvsJ3MrgaJzPtwNGS3AwvsQ/QTgdoTfPY69cpWeiajqh6sVFXVypj61qYyofr 3Vr1U1kg7C5U1U1VocIazAyzyRLhd4xnCgTpd/2OaHoxHHHQk/O+60EpevkyFCgW7x9k Fw/g5l52vmWE/elG52ss9yJfz3LFYg3GtTJZrHw/uco2FL/yKD6+cHWtBjqjV8oMq94F 4/hgrdaP1Js80iaZApKIrPDguLzSwU3de1M5RAC+7u5aW6YN61TpXOUZImZyS9eH4pAA kMNyN5jfYowAFuwt2qIEAnPv0G+SeEqnA085QOYqXHY32EM4RwaNT5Ux6Go+KBo4zr6n 6Xmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=8OmDOl+HzY7kcK871zVejMIspdUpfLqTD5KCeutuWtI=; b=ZCySRPe1qmKPW4Lx9PWqjuOdEq2tdaY4p8aZ6MhgPYJw6WFfcSEdfiRh4JyabbOcyU Sqx51tn7zhacXWRQovQo1B5zROTsSDlYjwiT7EZzHnMQ/p2taNUasETyqcINlHBHi80+ G5iIkI4olE8x7gUwXzr9erWMrMigRDbA+Yr+zYuv4zXyGS7yUInFSNysfTDBbpV8jHaU hOIYDGwfMD3BYPEIfiChncczliXilYIWyApbYr/9oYA4N8qJGkJLZ/9zg5rhsVRX9LAN 6+xPcq2D6KDB0zS0TD6NL1Rhq48g9/TL0cg4qYA40rmlZangX6s5X0V+hl9D2qWkNHSo dL7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=b89C2vjA; 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 h203si1510770oif.3.2020.01.29.10.16.52; Wed, 29 Jan 2020 10:17:06 -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=b89C2vjA; 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 S1727395AbgA2SPp (ORCPT + 99 others); Wed, 29 Jan 2020 13:15:45 -0500 Received: from mail-qv1-f74.google.com ([209.85.219.74]:51932 "EHLO mail-qv1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726245AbgA2SPp (ORCPT ); Wed, 29 Jan 2020 13:15:45 -0500 Received: by mail-qv1-f74.google.com with SMTP id e10so347991qvq.18 for ; Wed, 29 Jan 2020 10:15:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=8OmDOl+HzY7kcK871zVejMIspdUpfLqTD5KCeutuWtI=; b=b89C2vjAvi8rn6ke4cMrbzWhPNxthh3YpogsX2uEkpXypteStYFa0eHE/vbKpyKJ7c kWBwggD5XvuNwYUWI3HuS2xE8BtlawGJaAre2+1dfgETw9jFkKK6veUMfpnsJgwGEvS2 ewiUCzMI+c7/iBJZ8k++QCDfVxrlW41Rxy71EifgoDosJUOQnNzS2Qu5dfJHfZYldD3U kqYxC9hGbFd+k+7wkbuxYBxMxuFdnt0siR959H1OQ2ZgvBwY85FaMSAPHb0mkKviUm+V jooaRPM1l29+Kfwou3Aigf5v39axWr8UVxi1lWm5JGeUFN4uv0P8fFv+4VJOQHiVLxhF xZLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=8OmDOl+HzY7kcK871zVejMIspdUpfLqTD5KCeutuWtI=; b=keN2owWw5yGJKCvq3YS0pTUYhgCYe7cHYUz0CAv0hKaEpO71vJcQsYZosv2v3UIuS6 jLqlo4+DBI85PSPMa/6r/ar/ZBHzXpjiaM6hNPxKwUDEqN3xc8/fQKuaRX7RTaZsFhpn mh2gjFYOG/Jdi6YKZih1IDmrxQtfgG570KBoFaOvKF8bhrcjONqGLDmpmPtiZCcGPawa s/k0T5xqj5oHMYzKOLnyGWSpd/GwCMZHtMFoBmjhXsDF5q95gmuisTs/vnFvyzq3xxA6 5yySUKF5wj6x21P58so/+vXcMC2XKXFL/E/8jctm67uH7uGKxLHaFmkKL2ztBdFuwkQe cCLA== X-Gm-Message-State: APjAAAXfT8TznNnzF7+SSw+hWLJICS816b4K6ktmfqw6i943+UddKszS gn0lJC+qNWZPjBJ4KDc2mUrBsmmnBihb X-Received: by 2002:ac8:1385:: with SMTP id h5mr461391qtj.59.1580321744050; Wed, 29 Jan 2020 10:15:44 -0800 (PST) Date: Wed, 29 Jan 2020 18:15:41 +0000 Message-Id: <20200129181541.105335-1-qperret@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog Subject: [PATCH v2] kbuild: allow symbol whitelisting with TRIM_UNUSED_KSYMS From: Quentin Perret To: masahiroy@kernel.org, nico@fluxnic.net Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, maennich@google.com, kernel-team@android.com, qperret@google.com, jeyu@kernel.org 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 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. 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}" | sort -u | sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$new_ksyms_file" -- 2.25.0.341.g760bfbb309-goog