From patchwork Sun May 11 05:02:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Spelvin X-Patchwork-Id: 4149311 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0A76ABFF02 for ; Sun, 11 May 2014 05:02:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F310D2021A for ; Sun, 11 May 2014 05:02:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 06EC2201BC for ; Sun, 11 May 2014 05:02:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751302AbaEKFCz (ORCPT ); Sun, 11 May 2014 01:02:55 -0400 Received: from ns.horizon.com ([71.41.210.147]:64714 "HELO ns.horizon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751232AbaEKFCy (ORCPT ); Sun, 11 May 2014 01:02:54 -0400 Received: (qmail 19597 invoked by uid 1000); 11 May 2014 01:02:52 -0400 Date: 11 May 2014 01:02:52 -0400 Message-ID: <20140511050252.19596.qmail@ns.horizon.com> From: "George Spelvin" To: linux-kbuild@vger.kernel.org, yann.morin.1998@free.fr Subject: [PATCH] Documentation/kbuild/makefiles.txt: Improve description of lib-* targets Cc: linux@horizon.com, rdunlap@infradead.org In-Reply-To: <536EFC71.3070209@infradead.org> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I had to ask on the mailing list, so save developers the bother of answering the question again. (Wanna-be kernel developers might also be helped, but who cares about them?) Signed-off-by: George Spelvin --- As with most documentation patches, this is also an exercise in eliciting corrections by proposing a wrong answer which will be jumped on. Documentation/kbuild/makefiles.txt | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt index d567a7cc55..f6cc266163 100644 --- a/Documentation/kbuild/makefiles.txt +++ b/Documentation/kbuild/makefiles.txt @@ -237,10 +237,29 @@ more details, with real examples. be included in a library, lib.a. All objects listed with lib-y are combined in a single library for that directory. + + The entire kernel is then linked against these libraries, + so the linker will include the code in the final kernel only + if it is referenced somewhere. Thus, lib-* goals may be + designed with false positives. + Objects that are listed in obj-y and additionally listed in lib-y will not be included in the library, since they will be accessible anyway. - For consistency, objects listed in lib-m will be included in lib.a. + + For consistency, objects listed in lib-m will be included + in lib.a, but this will probably not do what you want. If a + function in lib.a is referenced only from a module, and not from + the main kernel image, the linker will not incorporate it into + the kernel image and later attempts to load the module will fail. + + One solution to this issue are to declare the object boolean + and link it into the kernel with obj-y if it's depended on by + a module. The object's code will be included in the main kernel + but unused until the module is loaded. + + The other is to make the object a module itself, and use an + obj-m goal. Many helper modules in lib are used this way. Note that the same kbuild makefile may list files to be built-in and to be part of a library. Therefore the same directory @@ -252,7 +271,7 @@ more details, with real examples. This will create a library lib.a based on delay.o. For kbuild to actually recognize that there is a lib.a being built, the directory - shall be listed in libs-y. + must be listed in libs-y in its parent makefile. See also "6.4 List directories to visit when descending". Use of lib-y is normally restricted to lib/ and arch/*/lib.