• Masahiro Yamada's avatar
    kbuild: do not export LDFLAGS_vmlinux · 3ec8a5b3
    Masahiro Yamada authored
    When you clean the build tree for ARCH=arm, you may see the following
    error message from 'nm' command:
    
    $ 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
    
    Even if you rerun the same command, the error message will not be
    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 unless 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 think 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. Stop shadowing
    LDFLAGS_vmlinux.
    
    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 70fac51f ("unicore32 additional architecture files:
    boot process") was merged before commit 1f2bfbd0 ("kbuild: link of
    vmlinux moved to a script"). So, I rather consider this is a bug fix of
    1f2bfbd0.
    
    arch/xtensa/boot/boot-elf/Makefile is also affected, but this is also
    considered a fix for the same reason. It did not inherit LDFLAGS_vmlinux
    when commit 4bedea94 ("[PATCH] xtensa: Architecture support for
    Tensilica Xtensa Part 2") was merged. I deleted $(LDFLAGS_vmlinux),
    which is now empty.
    Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
    Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
    Tested-by: default avatarNick Desaulniers <ndesaulniers@google.com>
    3ec8a5b3
Makefile 865 Bytes