linux-stable/scripts
Masahiro Yamada 7273ad2b08 kbuild: link lib-y objects to vmlinux forcibly when CONFIG_MODULES=y
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, 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 7f2084fa55 ("[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 <masahiroy@kernel.org>
Reported-by: kbuild test robot <lkp@intel.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
2020-04-09 00:13:45 +09:00
..
atomic locking/atomics: Use sed(1) instead of non-standard head(1) option 2019-06-25 10:17:07 +02:00
basic SPDX patches for 5.7-rc1. 2020-04-03 13:12:26 -07:00
coccinelle mm: remove __krealloc 2020-02-04 03:05:24 +00:00
dtc SPDX patches for 5.7-rc1. 2020-04-03 13:12:26 -07:00
gcc-plugins gcc-plugins: drop support for GCC <= 4.7 2020-04-09 00:13:45 +09:00
gdb .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
genksyms .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
kconfig kconfig: qconf: Fix a few alignment issues 2020-04-09 00:13:45 +09:00
ksymoops
mod Char/Misc driver patches for 5.7-rc1 2020-04-03 13:22:40 -07:00
package kbuild: deb-pkg: fix warning when CONFIG_DEBUG_INFO is unset 2020-03-30 09:23:00 +09:00
selinux SPDX patches for 5.7-rc1. 2020-04-03 13:12:26 -07:00
tracing treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 166 2019-05-30 11:26:39 -07:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
adjust_autoksyms.sh kbuild: split adjust_autoksyms.sh in two parts 2020-03-03 20:49:21 +09:00
asn1_compiler.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 36 2019-05-24 17:27:11 +02:00
bin2c.c kbuild: move bin2c back to scripts/ from scripts/basic/ 2018-07-18 01:18:05 +09:00
bloat-o-meter bloat-o-meter: ignore __addressable_ symbols 2018-12-28 12:11:44 -08:00
bootgraph.pl treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 391 2019-06-05 17:37:11 +02:00
bpf_helpers_doc.py bpf_helpers_doc.py: Fix warning when compiling bpftool 2020-03-13 20:53:40 +01:00
cc-can-link.sh bpfilter: check compiler capability in Kconfig 2018-06-28 13:36:39 +09:00
check-sysctl-docs docs: add a script to check sysctl docs 2020-02-25 03:35:16 -07:00
check_extable.sh
checkincludes.pl
checkkconfigsymbols.py treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 166 2019-05-30 11:26:39 -07:00
checkpatch.pl checkpatch: avoid warning about uninitialized_var() 2020-04-07 10:43:44 -07:00
checkstack.pl scripts/checkstack.pl: Fix arm64 wrong or unknown architecture 2019-06-05 02:33:10 +09:00
checksyscalls.sh checksyscalls: fix up mq_timedreceive and stat exceptions 2019-02-19 21:27:53 +01:00
checkversion.pl
clang-version.sh kbuild: update comment block of scripts/clang-version.sh 2019-03-04 22:34:54 +09:00
cleanfile
cleanpatch
coccicheck coccicheck: return proper error code on fail 2018-08-14 08:58:56 +09:00
config
const_structs.checkpatch
decode_stacktrace.sh scripts/decode_stacktrace: Accept dash/underscore in modules 2019-07-12 11:05:41 -07:00
decodecode scripts/decodecode: set ARCH when running natively on arm/arm64 2018-12-28 12:11:44 -08:00
depmod.sh kbuild: modules_install: warn when missing System.map file 2018-09-09 09:14:07 +09:00
diffconfig
documentation-file-ref-check SCSI misc on 20200402 2020-04-02 17:03:53 -07:00
export_report.pl modpost: move the namespace field in Module.symvers last 2020-03-17 08:59:03 +09:00
extract-cert.c
extract-ikconfig
extract-module-sig.pl
extract-sys-certs.pl
extract-vmlinux treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 378 2019-06-05 17:37:10 +02:00
extract_xc3028.pl treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 339 2019-06-05 17:37:07 +02:00
faddr2line scripts/faddr2line: fix location of start_kernel in comment 2018-11-18 10:15:09 -08:00
file-size.sh kbuild: Use ls(1) instead of stat(1) to obtain file size 2018-03-26 02:01:24 +09:00
find-unused-docs.sh scripts/find-unused-docs: Fix massive false positives 2020-01-27 14:25:06 -07:00
gcc-goto.sh jump_label: move 'asm goto' support test to Kconfig 2019-01-06 09:46:51 +09:00
gcc-ld
gcc-plugin.sh gcc-plugins: drop support for GCC <= 4.7 2020-04-09 00:13:45 +09:00
gcc-version.sh kbuild: clean up scripts/gcc-version.sh 2019-03-04 22:35:04 +09:00
gcc-x86_32-has-stack-protector.sh stack-protector: test compiler capability in Kconfig and drop AUTO mode 2018-06-08 18:56:00 +09:00
gcc-x86_64-has-stack-protector.sh stack-protector: Fix test with 32-bit userland and CONFIG_64BIT=y 2018-06-25 23:21:13 +09:00
gen_autoksyms.sh kbuild: generate autoksyms.h early 2020-03-03 20:49:21 +09:00
gen_compile_commands.py gen_compile_commands: lower the entry count threshold 2019-07-27 12:18:19 +09:00
gen_ksymdeps.sh kbuild: simplify dependency generation for CONFIG_TRIM_UNUSED_KSYMS 2018-12-01 23:13:14 +09:00
get_abi.pl doc: ABI scripts: add a SPDX header file 2019-06-21 16:58:37 +02:00
get_dvb_firmware treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 61 2019-05-24 17:36:45 +02:00
get_maintainer.pl scripts/get_maintainer.pl: deprioritize old Fixes: addresses 2020-02-21 11:22:15 -08:00
gfp-translate treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 166 2019-05-30 11:26:39 -07:00
headerdep.pl
headers_check.pl
headers_install.sh kbuild: re-implement detection of CONFIG options leaked to user-space 2019-08-21 21:05:21 +09:00
insert-sys-cert.c
jobserver-exec docs, parallelism: Rearrange how jobserver reservations are made 2019-11-22 10:35:18 -07:00
kallsyms.c scripts/kallsyms: fix wrong kallsyms_relative_base 2020-03-19 23:40:20 +09:00
Kbuild.include kbuild: remove *.tmp file when filechk fails 2020-01-16 00:26:22 +09:00
Kconfig.include gcc-plugins: drop support for GCC <= 4.7 2020-04-09 00:13:45 +09:00
kernel-doc scripts/kernel-doc: Add support for named variable macro arguments 2019-11-07 13:17:24 -07:00
ld-version.sh
leaking_addresses.pl treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 166 2019-05-30 11:26:39 -07:00
Lindent
link-vmlinux.sh bpf: Support llvm-objcopy for vmlinux BTF 2020-03-19 12:32:38 +01:00
Makefile kbuild: remove -I$(srctree)/tools/include from scripts/Makefile 2020-04-09 00:13:45 +09:00
Makefile.asm-generic kbuild: force all architectures except um to include mandatory-y 2019-03-17 12:56:32 +09:00
Makefile.build kbuild: link lib-y objects to vmlinux forcibly when CONFIG_MODULES=y 2020-04-09 00:13:45 +09:00
Makefile.clean gcc-plugins: drop support for GCC <= 4.7 2020-04-09 00:13:45 +09:00
Makefile.dtbinst kbuild: refactor Makefile.dtbinst more 2020-03-25 10:19:43 +09:00
Makefile.extrawarn kbuild: Enable -Wtautological-compare 2020-04-09 00:13:45 +09:00
Makefile.gcc-plugins gcc-plugins: structleak: Generalize to all variable types 2019-03-04 09:29:41 -08:00
Makefile.headersinst kbuild: move headers_check rule to usr/include/Makefile 2019-11-15 00:23:10 +09:00
Makefile.host gcc-plugins: drop support for GCC <= 4.7 2020-04-09 00:13:45 +09:00
Makefile.kasan kasan/arm64: fix CONFIG_KASAN_SW_TAGS && KASAN_INLINE 2019-08-15 13:24:04 +01:00
Makefile.kcov treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile.lib kbuild: Always validate DT binding examples 2020-03-03 20:49:21 +09:00
Makefile.modfinal kbuild: move modkern_{c,a}flags to Makefile.lib from Makefile.build 2019-08-22 01:14:11 +09:00
Makefile.modinst kbuild: modinst: read modules.order instead of $(MODVERDIR)/*.mod 2019-07-17 22:39:27 +09:00
Makefile.modpost modpost: return error if module is missing ns imports and MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS=n 2020-03-13 10:04:36 +09:00
Makefile.modsign kbuild: modsign: read modules.order instead of $(MODVERDIR)/*.mod 2019-07-17 22:39:27 +09:00
Makefile.package kbuild: Add make dir-pkg build option 2019-11-11 20:10:01 +09:00
Makefile.ubsan ubsan: split "bounds" checker from other options 2020-04-07 10:43:44 -07:00
makelst
markup_oops.pl treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 373 2019-06-05 17:37:10 +02:00
mkcompile_h kbuild: mkcompile_h: Include $LD version in /proc/version 2020-04-09 00:13:45 +09:00
mkmakefile kbuild: get rid of $(realpath ...) from scripts/mkmakefile 2019-08-29 23:54:29 +09:00
mksysmap
mkuboot.sh
module-common.lds
modules-check.sh kbuild: get rid of kernel/ prefix from in-tree modules.{order,builtin} 2019-07-17 22:39:27 +09:00
namespace.pl namespace: fix namespace.pl script to support relative paths 2019-10-05 15:29:49 +09:00
nsdeps scripts/nsdeps: support nsdeps for external module builds 2019-11-11 20:10:01 +09:00
objdiff treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 199 2019-05-30 11:29:23 -07:00
parse-maintainers.pl parse-maintainers: Do not sort section content by default 2020-03-26 15:08:27 -07:00
patch-kernel
profile2linkerlist.pl
prune-kernel
recordmcount.c ARM: 8950/1: ftrace/recordmcount: filter relocation types 2020-01-19 16:08:25 +00:00
recordmcount.h recordmcount: Fix nop_mcount() function 2019-10-12 20:49:33 -04:00
recordmcount.pl treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 166 2019-05-30 11:26:39 -07:00
setlocalversion scripts: setlocalversion: replace backquote to dollar parenthesis 2019-11-11 20:10:01 +09:00
show_delta treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 438 2019-06-05 17:37:17 +02:00
sign-file.c
sorttable.c scripts/sorttable: Implement build-time ORC unwind table sorting 2019-12-13 10:47:58 +01:00
sorttable.h scripts/sorttable: Implement build-time ORC unwind table sorting 2019-12-13 10:47:58 +01:00
spdxcheck-test.sh scripts: add spdxcheck.py self test 2018-12-28 12:11:44 -08:00
spdxcheck.py spdxcheck.py: fix directory structures 2019-06-01 15:51:31 -07:00
spelling.txt scripts/spelling.txt: add more spellings to spelling.txt 2020-04-02 09:35:25 -07:00
sphinx-pre-install scripts/sphinx-pre-install: add '-p python3' to virtualenv 2020-03-02 13:08:11 -07:00
split-man.pl MAINTAINERS & files: Canonize the e-mails I use at files 2018-05-04 06:21:06 -04:00
stackdelta
stackusage
subarch.include selftests: add headers_install to lib.mk 2018-09-05 08:12:09 -06:00
tags.sh kbuild: add a flag to force absolute path for srctree 2019-07-11 00:05:09 +09:00
tools-support-relr.sh scripts/tools-support-relr.sh: un-quote variables 2019-11-13 10:52:05 +00:00
unifdef.c unifdef: use memcpy instead of strncpy 2018-11-30 14:45:01 -08:00
ver_linux ver_linux: Query ld cache for versions of libc/libcpp run-time 2020-02-10 13:35:15 -08:00
xen-hypercalls.sh
xz_wrap.sh