Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1043068ybt; Wed, 1 Jul 2020 17:09:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhHS8sxyqHWejaY5eP3tJ+7vBFcFpxU6Lea2nBVPiSGW6wQPlJIppmYLUN30FS+/RRrDCS X-Received: by 2002:a17:906:6dda:: with SMTP id j26mr25824877ejt.336.1593648542044; Wed, 01 Jul 2020 17:09:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593648542; cv=none; d=google.com; s=arc-20160816; b=rsyp+z8qpGwfOhKf8d12iL/eaWqHny+x0QbKPu4qoUrR+8tMx0c1P1Jwe21iCyT06b iPuWu2vjSNBAmWRr+S2jm5s6Z2+ZD4g+kMKOQpcVUKVaFASmpznpVTXFMda8/BsG2SRf SCa4jHhQ989/m4zPf1/wDkmlfMHK8NBaBYSmAe53to5vu2UWHvm7ZMXt+uPI/mPzxFJ8 dZIiNahed8fsMVvZAKACSE9glKmt3JBPfdI60IQBTVJ80kUBtoJ/V/uzgQaWq+rk67Jb fuDGf5rIo5ZXaVlgTvOJ3mEkBwax/UG2N1JyShjikEUpweUNN9DxEOn4r+4s3vGtpF6o 6tYw== 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 :in-reply-to:references:mime-version:dkim-signature; bh=T7hL8oTAJrT5pDPCgIg1OSRZK1ha79xq6AjDa0eoWzM=; b=tMFMSXogYkP3dN1zWHXOKEBZm96VuUw7NwYKE42/v79ZtJHaZFxjMWksD1ZQ16criu 3njGqN9zvU1kRQkD+nczmR7LJJfXTFpZOI7aN7FmvbcpGo3ftW32gb1Jhb4FWww5zatW zm3SXXWl6vfZAa1WH/GxOqZw8hSUuX+Zx+b4vBSvgYlpkO/afvOjr1dfWs5xeb17NqnD j6ZsrOV14kl9J7CCyez9/pJOKaqmmOBk9E7zHg6yMxSMur4ENg6pk1GewEt49bY6+0/P F4M/3alYVStEItdrRkg+GU2MX18LhZi5O1/i/6s1wG9BwvgO1qZCB64dFbTUS98piwWf WRvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LEnbYfoJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id o3si4648452eje.601.2020.07.01.17.08.36; Wed, 01 Jul 2020 17:09:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LEnbYfoJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727852AbgGBAIW (ORCPT + 99 others); Wed, 1 Jul 2020 20:08:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727073AbgGBAIV (ORCPT ); Wed, 1 Jul 2020 20:08:21 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75E7FC08C5C1 for ; Wed, 1 Jul 2020 17:08:21 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id t11so6843237pfq.11 for ; Wed, 01 Jul 2020 17:08:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=T7hL8oTAJrT5pDPCgIg1OSRZK1ha79xq6AjDa0eoWzM=; b=LEnbYfoJKkXege/aZzvcuMIoxLycA71bdbZUWiA0LKPJBzkLr1NjDtTji/yDoZuqmG SgutKsd0nQlY6f/Oma3BlcuhwG05exEmsXqQ9208gaTQunAfOLKywX4jv0Fxzew26g2a wZCM0ff+knpkbcgFiJb+L/92Q0VSD2dUJMOhWCnX7NILxMlN5brpRMEGbfeKN7eN+ZAY mMcn0I7Ug79H/4rZYHVtjSvBxZTLkvVDDOWGIFcSsdjeibceFDUt13Yt14N0UjY3jNM6 sU0WepShcec2/AjUp2bPrUQpBQumxh6+j8IXJ8nJl4Qt+2UK3tXlGWn/E2V7J/4V6BhJ Lz1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=T7hL8oTAJrT5pDPCgIg1OSRZK1ha79xq6AjDa0eoWzM=; b=io1VpWy9JrI5dyX2nL+WSIagHmn5MWF0VUnfNtyb7iaWVlEJrg7grM+I3cESRxmy8l tq2jDzNaNK1Ojt+cdKTy0sQqZGZvOAzZ2jZOdI5iNb+89BIMTJck/E5Zt1566vmPgadD tTuiga3snEowZ1tINcarQD8KetZ8MwFSwiHXaKaghqQbLipfIjmYvC7kcMXtnWau9FUN wr2+YSn9t31sHd+GMPzrwWv5cPB8EzNmpvFvvFHOQjD7SSxr0BhcMozBLPOGa9VrEMAq cx84zBIpb1KQOtXeluIIZlKPpSicqvGNKpXM7Co53tWei12Nhp3qyzwMvxfmqAgaW47l gZbA== X-Gm-Message-State: AOAM532RiA4hNAYI5vqnhF9qV+2q8xT3C65HJjCKPsFEAL7V7dtpeEKx euTW45ZpdeUwfL7Y0gcMhMhbqRTMh0cjXOh/ZExdnw== X-Received: by 2002:aa7:9303:: with SMTP id 3mr17081569pfj.108.1593648500571; Wed, 01 Jul 2020 17:08:20 -0700 (PDT) MIME-Version: 1.0 References: <20200701192936.1397152-1-masahiroy@kernel.org> In-Reply-To: <20200701192936.1397152-1-masahiroy@kernel.org> From: Nick Desaulniers Date: Wed, 1 Jul 2020 17:08:07 -0700 Message-ID: Subject: Re: [PATCH] kbuild: do not export LDFLAGS_vmlinux To: Masahiro Yamada Cc: Linux Kbuild mailing list , Sam Ravnborg , LKML , Chris Zankel , Max Filippov , linux-xtensa@linux-xtensa.org, Guan Xuetao , Michal Marek 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 On Wed, Jul 1, 2020 at 12:30 PM Masahiro Yamada wrote: > > When you clean the build tree for ARCH=arm, you may see the following > error message: > > $ make -j24 ARCH=arm clean > CLEAN arch/arm/crypto > CLEAN arch/arm/kernel > CLEAN arch/arm/mach-at91 > CLEAN arch/arm/mach-omap2 > CLEAN arch/arm/vdso > CLEAN certs > CLEAN lib > CLEAN usr > CLEAN net/wireless > CLEAN drivers/firmware/efi/libstub > nm: 'arch/arm/boot/compressed/../../../../vmlinux': No such file > /bin/sh: 1: arithmetic expression: expecting primary: " " > CLEAN arch/arm/boot/compressed > CLEAN drivers/scsi > CLEAN drivers/tty/vt > CLEAN arch/arm/boot > CLEAN vmlinux.symvers modules.builtin modules.builtin.modinfo Thanks for the patch, Masahiro. This fixes the issue I was also observing. Curious case of shadowing env vars. Reviewed-by: Nick Desaulniers Tested-by: Nick Desaulniers > > Even if you run the same command again, the error message is not shown > despite vmlinux is already gone. > > To reproduce it, the parallel option -j is needed. Single thread > cleaning always executes 'archclean', 'vmlinuxclean' in this order, > so vmlinux still exists when arch/arm/boot/compressed/ is cleaned. > > Looking at arch/arm/boot/compressed/Makefile does not help understand > the reason of the error message. Both KBSS_SZ and LDFLAGS_vmlinux are > assigned with '=' operator, hence, they are not expanded until they are > used. Obviously, 'make clean' does not use them. > > In fact, the root cause exists in the top Makefile: > > export LDFLAGS_vmlinux > > Since LDFLAGS_vmlinux is an exported variable, LDFLAGS_vmlinux in > arch/arm/boot/compressed/Makefile is expanded when scripts/Makefile.clean > has a command to execute. This is why the error message shows up only > when there exist build artifacts in arch/arm/boot/compressed/. > > Adding 'unexport LDFLAGS_vmlinux' to arch/arm/boot/compressed/Makefile > will fix it as far as ARCH=arm is concerned, but I believe the proper > fix is to get rid of 'export LDFLAGS_vmlinux' from the top Makefile. > > LDFLAGS_vmlinux in the top Makefile contains linker flags for the top > vmlinux. LDFLAGS_vmlinux in arch/arm/boot/compressed/Makefile is for > arch/arm/boot/compressed/vmlinux. They just happen to have the same > variable name, but are used for different purposes. Exporting the former > bothers the decompressor Makefiles. > > This commit passes LDFLAGS_vmlinux to scripts/link-vmlinux.sh via a > command line parameter instead of via an environment variable. LD and > KBUILD_LDFLAGS are exported, but I did the same for consistency. Anyway, > they must be included in cmd_link-vmlinux to allow if_changed to detect > the changes in LD or KBUILD_LDFLAGS. > > The following Makefiles are not affected: > > arch/arm/boot/compressed/Makefile > arch/h8300/boot/compressed/Makefile > arch/nios2/boot/compressed/Makefile > arch/parisc/boot/compressed/Makefile > arch/s390/boot/compressed/Makefile > arch/sh/boot/compressed/Makefile > arch/sh/boot/romimage/Makefile > arch/x86/boot/compressed/Makefile > > They use ':=' or '=' to clear the LDFLAGS_vmlinux inherited from the > top Makefile. > > We need to take a closer look at the impact to unicore32 and xtensa. > > arch/unicore32/boot/compressed/Makefile only uses '+=' operator for > LDFLAGS_vmlinux. So, the decompressor previously inherited the linker > flags from the top Makefile. > > However, commit 70fac51feaf2 ("unicore32 additional architecture files: > boot process") was merged before commit 1f2bfbd00e46 ("kbuild: link of > vmlinux moved to a script"). So, I believe this is rather a bug fix of > 1f2bfbd00e46. > > arch/xtensa/boot/boot-elf/Makefile is also affected, but this is a fix > for the same reason. It did not inherit LDFLAGS_vmlinux when commit > 4bedea945451 ("[PATCH] xtensa: Architecture support for Tensilica Xtensa > Part 2") was merged. I deleted $(LDFLAGS_vmlinux), which is now empty. > > Signed-off-by: Masahiro Yamada > --- > > Makefile | 3 +-- > arch/xtensa/boot/boot-elf/Makefile | 2 +- > scripts/link-vmlinux.sh | 4 ++++ > 3 files changed, 6 insertions(+), 3 deletions(-) > > diff --git a/Makefile b/Makefile > index 5496a32dffa6..075f2f943180 100644 > --- a/Makefile > +++ b/Makefile > @@ -1100,7 +1100,6 @@ KBUILD_VMLINUX_OBJS += $(patsubst %/,%/built-in.a, $(drivers-y)) > > export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS > export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds > -export LDFLAGS_vmlinux > # used by scripts/Makefile.package > export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) LICENSES arch include scripts tools) > > @@ -1132,7 +1131,7 @@ ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) > > # Final link of vmlinux with optional arch pass after final link > cmd_link-vmlinux = \ > - $(CONFIG_SHELL) $< $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_vmlinux) ; \ > + $(CONFIG_SHELL) $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)"; \ > $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) > > vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE > diff --git a/arch/xtensa/boot/boot-elf/Makefile b/arch/xtensa/boot/boot-elf/Makefile > index 12ae1e91cb75..c6538d3321b9 100644 > --- a/arch/xtensa/boot/boot-elf/Makefile > +++ b/arch/xtensa/boot/boot-elf/Makefile > @@ -25,7 +25,7 @@ $(obj)/Image.o: vmlinux.bin $(OBJS) > $(OBJS) $@ > > $(obj)/../Image.elf: $(obj)/Image.o $(obj)/boot.lds > - $(Q)$(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_vmlinux) \ > + $(LD) $(KBUILD_LDFLAGS) \ > -T $(obj)/boot.lds \ > --build-id=none \ > -o $@ $(obj)/Image.o > diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh > index 7eaf70d58488..16c7818b3e19 100755 > --- a/scripts/link-vmlinux.sh > +++ b/scripts/link-vmlinux.sh > @@ -30,6 +30,10 @@ > # Error out on error > set -e > > +LD="$1" > +KBUILD_LDFLAGS="$2" > +LDFLAGS_vmlinux="$3" > + > # Nice output in kbuild format > # Will be supressed by "make -s" > info() > -- > 2.25.1 > -- Thanks, ~Nick Desaulniers