From patchwork Wed Mar 11 22:37:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 11432967 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 199096CA for ; Wed, 11 Mar 2020 22:38:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C3CC420746 for ; Wed, 11 Mar 2020 22:38:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583966319; bh=tVph8m/LGo8XOafjuleRQg1aTu5D2sTdBUwn5Og/bag=; h=From:To:Cc:Subject:Date:List-ID:From; b=a4/i2oTMrOGzWJ8ZuLwqz7O4Z6UCa/VQ1IbfaMi2DaV0HAlr9Qfh3J0IHNqZ4zRk5 9kl+iTIVa33Ivrg7OdyMmlhz56L1+0JN0OWcVNuAMBoe2YyeB/aevTOWU8zIkrlNG6 3ivY0wO++GUE2o5pMo+3jZXK2X5TwcUVBP9NcTrg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729997AbgCKWij (ORCPT ); Wed, 11 Mar 2020 18:38:39 -0400 Received: from conuserg-12.nifty.com ([210.131.2.79]:26360 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729881AbgCKWij (ORCPT ); Wed, 11 Mar 2020 18:38:39 -0400 Received: from grover.flets-west.jp (softbank126093102113.bbtec.net [126.93.102.113]) (authenticated) by conuserg-12.nifty.com with ESMTP id 02BMbYqf019805; Thu, 12 Mar 2020 07:37:35 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com 02BMbYqf019805 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1583966255; bh=tiAHJid7/WA3U3683+xwU6rGIWKb4aM8B2wj4c+paIQ=; h=From:To:Cc:Subject:Date:From; b=MV/GMLbmCnGT0J0XdohjNCc2KP58qmnj+qvhKNL/fsrbcvMC3bDunxeqpcOOSGB8o VbnlRGNVZq/4ekRn0VrO25hw3SeikvzgF4LyU555iQJQARlhH/4CJ+K3ktLCLeWAZh DvuWDq1y84t2/htCFsT276osv+/7n3tzeMhNFoQ2/WowYBRwz+rh7Oj5GxqtcRdkXM glOUVtqjY6M1oG7sHZBcwkHNEbx76LVuBZXdzqA2t9HguwSHrbxrkL2eGLCOFmz4kg eJAPbpJ31cLQw2R2QwAUfWSeMK1Fy8XyU80HYst1ZavOuRrXfS+8ujd9GrA8AkyjuU KsFGU67GeGA3w== X-Nifty-SrcIP: [126.93.102.113] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: sparclinux@vger.kernel.org, "David S . Miller" , clang-built-linux@googlegroups.com, Al Viro , Nick Desaulniers , Ilie Halip , Nathan Chancellor , linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH v2 1/2] sparc: revive __HAVE_ARCH_STRLEN for 32bit sparc Date: Thu, 12 Mar 2020 07:37:24 +0900 Message-Id: <20200311223725.27662-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.17.1 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Prior to commit 70a6fcf3283a ("[sparc] unify 32bit and 64bit string.h"), __HAVE_ARCH_STRLEN was defined in both of string_32.h and string_64.h It did not unify __HAVE_ARCH_STRLEN, but deleted it from string_32.h This issue was reported by the kbuild test robot in the trial of forcible linking of $(lib-y) to vmlinux. Fixes: 70a6fcf3283a ("[sparc] unify 32bit and 64bit string.h") Reported-by: kbuild test robot Suggested-by: Nick Desaulniers Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers Acked-by: David S. Miller --- Changes in v2: - Insert a new patch to avoid sparc32 build error arch/sparc/include/asm/string.h | 4 ++++ arch/sparc/include/asm/string_64.h | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/sparc/include/asm/string.h b/arch/sparc/include/asm/string.h index 3d9cd082716b..001a17baf2d5 100644 --- a/arch/sparc/include/asm/string.h +++ b/arch/sparc/include/asm/string.h @@ -37,6 +37,10 @@ void *memmove(void *, const void *, __kernel_size_t); #define __HAVE_ARCH_MEMCMP int memcmp(const void *,const void *,__kernel_size_t); +/* Now the str*() stuff... */ +#define __HAVE_ARCH_STRLEN +__kernel_size_t strlen(const char *); + #define __HAVE_ARCH_STRNCMP int strncmp(const char *, const char *, __kernel_size_t); diff --git a/arch/sparc/include/asm/string_64.h b/arch/sparc/include/asm/string_64.h index ee9ba67321bd..d5c563058a5b 100644 --- a/arch/sparc/include/asm/string_64.h +++ b/arch/sparc/include/asm/string_64.h @@ -12,8 +12,4 @@ #include -/* Now the str*() stuff... */ -#define __HAVE_ARCH_STRLEN -__kernel_size_t strlen(const char *); - #endif /* !(__SPARC64_STRING_H__) */ From patchwork Wed Mar 11 22:37:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 11432969 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EC2FB6CA for ; Wed, 11 Mar 2020 22:38:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AD99D20746 for ; Wed, 11 Mar 2020 22:38:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583966324; bh=oPp4EkQ44kkIEd0r92X5mOvaTzTNgMSALQjfags1c9w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=YY/XU7AfwjxubCQ1Bpv7amJFnCnm6uVYgj/LQL0EfDv5YbsRw8Q3uCgE3gGWkaF2j VQJ7QOrTSsX5K+CITWU+3RpAn49yK6PYoD3ZQGC7iGjVrcBiBXOkBLcU9yspf3xORZ 0IOltBxwgyhEehYvzDUw0afKFnV5JGLWDqCW/7GQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731330AbgCKWil (ORCPT ); Wed, 11 Mar 2020 18:38:41 -0400 Received: from conuserg-12.nifty.com ([210.131.2.79]:26361 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729739AbgCKWik (ORCPT ); Wed, 11 Mar 2020 18:38:40 -0400 Received: from grover.flets-west.jp (softbank126093102113.bbtec.net [126.93.102.113]) (authenticated) by conuserg-12.nifty.com with ESMTP id 02BMbYqg019805; Thu, 12 Mar 2020 07:37:36 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com 02BMbYqg019805 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1583966256; bh=eV641mEtJcxSe/x4CJ7sZRwpUKMRqHWiX6uSM6ikt7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0Qv5mtexJ95oplfw3jKx4O598pCAJ9biXotcsFjwC37RUh5mjkalSW2Su/e7k5GrF CS+dF74fN/6vnlWySkPqixNggjqPy8/vvoeZI/XfCS8+MT55iddwww1YHT2NIcvd9H L7eToIXaLjE/X+We9JBBFEIVZaiI2urFw0llbu8b8UGdOaKOsjXnflKOIXLS9Q+E2r kH2uBh+8b4vIuVYQ3X+EdkrkSfZS8jgjFnNKWw0V3D0sueyPh6wmd3sh66n3b0+dX8 5RI5gFGxW3DikjUcQbcGMRHsUpX/8Lo/z7yIbB73Z3AfdoAWlwm5f5h3JTqnkLXMz8 xLmnzEShuHyjQ== X-Nifty-SrcIP: [126.93.102.113] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: sparclinux@vger.kernel.org, "David S . Miller" , clang-built-linux@googlegroups.com, Al Viro , Nick Desaulniers , Ilie Halip , Nathan Chancellor , linux-kernel@vger.kernel.org, Masahiro Yamada , Michal Marek Subject: [PATCH v2 2/2] kbuild: link lib-y objects to vmlinux forcibly when CONFIG_MODULES=y Date: Thu, 12 Mar 2020 07:37:25 +0900 Message-Id: <20200311223725.27662-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200311223725.27662-1-masahiroy@kernel.org> References: <20200311223725.27662-1-masahiroy@kernel.org> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Kbuild supports not only obj-y but also lib-y to list objects linked to vmlinux. The difference between them is that all the objects from obj-y are forcibly linked to vmlinux by using --whole-archive, whereas the objects from lib-y are linked as needed; if there is no user of a lib-y object, it is not linked. lib-y is intended to list utility functions that may be called from all over the place (and may be unused at all), but it is a problem for EXPORT_SYMBOL(). Even if there is no call-site in the vmlinux, we need to keep exported symbols for the use from loadable modules. Commit 7f2084fa55e6 ("[kbuild] handle exports in lib-y objects reliably") worked around it by linking a dummy object, lib-ksyms.o, which contains references to all the symbols exported from lib.a in that directory. It uses the linker script command, EXTERN. Unfortunately, the meaning of EXTERN of ld.lld is different from that of ld.bfd. Therefore, this does not work with LD=ld.lld (CBL issue #515). Anyway, the build rule of lib-ksyms.o is somewhat tricky. So, I want to get rid of it. At first, I was thinking of accumulating lib-y objects into obj-y (or even replacing lib-y with obj-y entirely), but the lib-y syntax is used beyond the ordinary use in lib/ and arch/*/lib/. Examples: - drivers/firmware/efi/libstub/Makefile builds lib.a, which is linked into vmlinux in the own way (arm64), or linked to the decompressor (arm, x86). - arch/alpha/lib/Makefile builds lib.a which is linked not only to vmlinux, but also to bootloaders in arch/alpha/boot/Makefile. - arch/xtensa/boot/lib/Makefile builds lib.a for use from arch/xtensa/boot/boot-redboot/Makefile. One more thing, adding everything to obj-y would increase the vmlinux size of allnoconfig (or tinyconfig). For less impact, I tweaked the destination of lib.a at the top Makefile; when CONFIG_MODULES=y, lib.a goes to KBUILD_VMLINUX_OBJS, which is forcibly linked to vmlinux, otherwise lib.a goes to KBUILD_VMLINUX_LIBS as before. The size impact for normal usecases is quite small since at lease one symbol in every lib-y object is eventually called by someone. In case you are intrested, here are the figures. x86_64_defconfig: text data bss dec hex filename 19566602 5422072 1589328 26578002 1958c52 vmlinux.before 19566932 5422104 1589328 26578364 1958dbc vmlinux.after The case with the biggest impact is allnoconfig + CONFIG_MODULES=y. ARCH=x86 allnoconfig + CONFIG_MODULES=y: text data bss dec hex filename 1175162 254740 1220608 2650510 28718e vmlinux.before 1177974 254836 1220608 2653418 287cea vmlinux.after Hopefully this is still not a big deal. The per-file trimming with the static library is not so effective after all. If fine-grained optimization is desired, some architectures support CONFIG_LD_DEAD_CODE_DATA_ELIMINATION, which trims dead code per-symbol basis. When LTO is supported in mainline, even better optimization will be possible. Link: https://github.com/ClangBuiltLinux/linux/issues/515 Signed-off-by: Masahiro Yamada Reported-by: kbuild test robot Reported-by: kbuild test robot Reviewed-by: Nick Desaulniers --- Changes in v2: None Makefile | 7 ++++++- scripts/Makefile.build | 17 ----------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 6a538b79e61e..2cdbd4b3e36d 100644 --- a/Makefile +++ b/Makefile @@ -1034,8 +1034,13 @@ init-y := $(patsubst %/, %/built-in.a, $(init-y)) core-y := $(patsubst %/, %/built-in.a, $(core-y)) drivers-y := $(patsubst %/, %/built-in.a, $(drivers-y)) net-y := $(patsubst %/, %/built-in.a, $(net-y)) +libs-y2 := $(patsubst %/, %/built-in.a, $(filter %/, $(libs-y))) +ifdef CONFIG_MODULES +libs-y1 := $(filter-out %/, $(libs-y)) +libs-y2 += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y))) +else libs-y1 := $(patsubst %/, %/lib.a, $(libs-y)) -libs-y2 := $(patsubst %/, %/built-in.a, $(filter-out %.a, $(libs-y))) +endif virt-y := $(patsubst %/, %/built-in.a, $(virt-y)) # Externally visible symbols (used by link-vmlinux.sh) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index a1730d42e5f3..356601994f3a 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -65,7 +65,6 @@ endif ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),) lib-target := $(obj)/lib.a -real-obj-y += $(obj)/lib-ksyms.o endif ifdef need-builtin @@ -410,22 +409,6 @@ $(lib-target): $(lib-y) FORCE targets += $(lib-target) -dummy-object = $(obj)/.lib_exports.o -ksyms-lds = $(dot-target).lds - -quiet_cmd_export_list = EXPORTS $@ -cmd_export_list = $(OBJDUMP) -h $< | \ - sed -ne '/___ksymtab/s/.*+\([^ ]*\).*/EXTERN(\1)/p' >$(ksyms-lds);\ - rm -f $(dummy-object);\ - echo | $(CC) $(a_flags) -c -o $(dummy-object) -x assembler -;\ - $(LD) $(ld_flags) -r -o $@ -T $(ksyms-lds) $(dummy-object);\ - rm $(dummy-object) $(ksyms-lds) - -$(obj)/lib-ksyms.o: $(lib-target) FORCE - $(call if_changed,export_list) - -targets += $(obj)/lib-ksyms.o - endif # NOTE: