Received: by 10.213.65.68 with SMTP id h4csp1498889imn; Thu, 15 Mar 2018 01:02:50 -0700 (PDT) X-Google-Smtp-Source: AG47ELvozQ0dEmbagxqbj3Mm0YhC8s2Hs/FTBtdYbjJQ0aIdSdPk4m3+mX43w6vXcCIhn3TNXioM X-Received: by 10.98.73.205 with SMTP id r74mr4070148pfi.111.1521100970428; Thu, 15 Mar 2018 01:02:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521100970; cv=none; d=google.com; s=arc-20160816; b=Myi5/MGuo565u6UvIlCW3tD7IgRW3kzxf9TGcoo79AF0yYUIvZ1Z2/DD2TwcR040G0 5DjBy3p0tw4B42H+nK4B92I79Otf050+BYhA8S9TQCmAKPX/T3h94GVkblPbLw+r1MVl N3NSonszwHOd0eYX/3/GYcr6HTpoy+XwwndJhnq6VTjgNNfZMCIE8BeO+qWY04GghFmO L1tmTqqBqxjHEaJt6844E381lsb1J/t7Rrp/l9AhCnHGdpr8JUWVLw++rM0UtrUUPkSA YdUC8usls3LLLgSIyq8D8/lQsDTWM098UEJDffqxyB5xBl2NEPWa0JOZ1ATBHXfAlgCm 2UQQ== 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 :references:in-reply-to:mime-version:dkim-signature:dkim-filter :arc-authentication-results; bh=ffuzEY06SvQfoDZEPlmFf4aYHFPUzQ+h7iPP9jHAcTs=; b=rdKBAvwHa1sssSTZZ5vHPC2E23SDU242TfBnSsvNa+xoEnRV3sNn2EAYlQARTe2i10 Rd2U5g8oRwp35OJwHSSEJ8SnwytscCAnijZy4BR0zdxgXZjQdkQIluPcrBOOGJxtrNFB Bf51TSi+6noFgtr4HOrspOoFKbBZbb0NBLdvUF9EvCsmlE/9uo7qHbSro3VkrIu99ePv NwclpTxzosecqjVMMQW6l3MftpRS+tGTycf120Sflgzvr0F393VVIx3q44rwSJMGwmd/ l8beK0fg7vMTffKu9ka6wLB/omr/0xj30dd8NhlfMwEbxIE518ylPH1tHZba3J/8HPC7 zH3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=QwpKJw06; 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 v15si3121693pgt.635.2018.03.15.01.02.35; Thu, 15 Mar 2018 01:02:50 -0700 (PDT) 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=QwpKJw06; 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 S1751652AbeCOIBX (ORCPT + 99 others); Thu, 15 Mar 2018 04:01:23 -0400 Received: from conssluserg-05.nifty.com ([210.131.2.90]:47367 "EHLO conssluserg-05.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750777AbeCOIBV (ORCPT ); Thu, 15 Mar 2018 04:01:21 -0400 Received: from mail-ua0-f174.google.com (mail-ua0-f174.google.com [209.85.217.174]) (authenticated) by conssluserg-05.nifty.com with ESMTP id w2F817h1000761; Thu, 15 Mar 2018 17:01:08 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-05.nifty.com w2F817h1000761 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1521100868; bh=ffuzEY06SvQfoDZEPlmFf4aYHFPUzQ+h7iPP9jHAcTs=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=QwpKJw064hu1Gs7Vlmf9m5UlQSQAnjkfS9PnQvwbyOVtWf/tayYWRlyGXvdipuzkJ +Pj5kgc7bvPnRvY2GsWOQZsi4v/apwb9Nk0/bOGPnIBI2j6EPKjA2o1X9VyA9m9czI b1FihdgbSluRPxwSK9jmv77zg5DHiBQFhpz3JmRp8YAjxlBZiDTYFBDRIWODKL/ibI CNrLoNS/YCbm+/89dGI8a/zOPbfkAPSzCQO9A8fOiy9ae6Cq+mU+cARIAaQmnSDFEc rePB0DyWolE6gnxyKJP+Jf/2KtIU8ZcUc07WB1yEShG1r583Y4qsZjE+JpusV+voQF oYrOVIhlxMrkg== X-Nifty-SrcIP: [209.85.217.174] Received: by mail-ua0-f174.google.com with SMTP id i21so538470uak.8; Thu, 15 Mar 2018 01:01:08 -0700 (PDT) X-Gm-Message-State: AElRT7GQnGaJpyT/SolaDt3eRsM5PMhcXUJ402p/ANOx7MYWg4CmmdTS fN6dRXUf3c3onq+WZvOXQ0ujbBVrF04OiTXPImE= X-Received: by 10.159.49.179 with SMTP id v48mr5444221uad.17.1521100867129; Thu, 15 Mar 2018 01:01:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.176.32.138 with HTTP; Thu, 15 Mar 2018 01:00:26 -0700 (PDT) In-Reply-To: References: <1521045861-22418-1-git-send-email-yamada.masahiro@socionext.com> <1521045861-22418-8-git-send-email-yamada.masahiro@socionext.com> From: Masahiro Yamada Date: Thu, 15 Mar 2018 17:00:26 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 7/7] kbuild: link vmlinux just once for CONFIG_TRIM_UNUSED_KSYMS To: Nicolas Pitre Cc: Linux Kbuild mailing list , Jarod Wilson , Prarit Bhargava , Michal Marek , Linux Kernel Mailing List 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 2018-03-15 4:06 GMT+09:00 Nicolas Pitre : > On Thu, 15 Mar 2018, Masahiro Yamada wrote: > >> If CONFIG_TRIM_UNUSED_KSYMS is enabled and the kernel is built from >> a pristine state, the vmlinux is linked twice. >> >> [1] A user runs "make" >> >> [2] First build with empty autoksyms.h >> >> [3] adjust_autoksyms.sh updates autoksyms.h and recurses "make vmlinux" >> >> --------(begin sub-make)-------- >> [4] Second build with new autoksyms.h >> >> [5] link-vmlinux.sh is invoked because "vmlinux" is missing >> ---------(end sub-make)--------- >> >> [6] link-vmlinux.sh is invoked again despite "vmlinux" is up-to-date. >> >> The reason of [6] is probably because Make already decided to update >> "vmlinux" at the time of [2] because "vmlinux" was missing when Make >> generated the dependency list. > > But the dependency list for vmlinux contains FORCE so the target is > always remade in (2) anyway. The decision to actually invoke > link-vmlinux.sh comes from "if_changed". Why is $(call if_changed,...) > in (6) not noticing that vmlinux is up to date? if_changed (more specifically 'any-prereq') is implemented based on '$?'. So, this problem can be narrowed down to how Make decides '$?'. If you apply the first 6 patches, and put the following debug code, you will see what has happened to $? @@ -1024,6 +1026,7 @@ cmd_link-vmlinux = \ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) vmlinux: scripts/link-vmlinux.sh vmlinux_prereq $(vmlinux-deps) FORCE + @echo newer deps: $? +$(call if_changed,link-vmlinux) # Build samples along the rest of the kernel I am not familiar with Make internal, but I can test it with simple code. [Test Makefile] A: B cp B A echo $? B: C cp C B touch A [Result] $ rm -rf A B C $ touch C $ make cp C B touch A cp B A echo B B In the recipe of 'B', 'A' is touched, so the dependency 'A: B' has already been met before the recipe of 'A' is executed, but Make does not notice that fact, then tries to update 'A'. The situation is the same. vmlinux has been updated in the recursed sub-make, but it is not noticed. >> >> link-vmlinus.sh is costly, so it is better to not run it when unneeded. >> Split CONFIG_TRIM_UNUSED_KSYMS handling to a dedicated target. >> >> The reason of commit 2441e78b1919 ("krbuild: better abstract vmlinux >> sequential prerequisites") was to cater to CONFIG_BUILD_DOCSRC, but >> it was later removed by commit 184892925118 ("samples: move blackfin >> gptimers-example from Documentation"). >> >> I also changed adjust_autoksyms.sh to simply exit with 1 or 0 to make >> it look straightforward. > > That is wrong. If the script fails for some reason (it runs with -e set) > then this will trigger an endless recursive make instead of failing the > build. Sorry, I missed this case. You are right. I will restore the original code. -- Best Regards Masahiro Yamada