My main motivation of this commit is to clean up scripts/Kbuild.include and scripts/Makefile.build. Currently, CONFIG_TRIM_UNUSED_KSYMS works with a tricky gimmick; possibly exported symbols are detected by letting $(CPP) replace EXPORT_SYMBOL* with a special string '=== __KSYM_*===', which is post-processed by sed, and passed to fixdep. The extra preprocessing is costly, and hacking cmd_and_fixdep is ugly. I came up with a new way to find exported symbols; insert a dummy symbol __ksym_marker_* to each potentially exported symbol. Those dummy symbols are picked up by $(NM), post-processed by sed, then appended to .*.cmd files. I collected the post-process part to a new shell script scripts/gen_ksymdeps.sh for readability. The dummy symbols are put into the .discard.* section so that the linker script rips them off the final vmlinux or modules. A nice side-effect is building with CONFIG_TRIM_UNUSED_KSYMS will be much faster.
Showing the changes to scripts (4 of 6 files). Show all
Unified · Split
| @@ -260,39 +260,11 @@ if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \ · 259 unmodified lines | ||
| 260 | 260 | @set -e; \ |
| 261 | 261 | $(cmd_and_fixdep), @:) |
| 262 | 262 | |
| 263 | −ifndef CONFIG_TRIM_UNUSED_KSYMS | |
| 264 | − | |
| 265 | 263 | cmd_and_fixdep = \ |
| 266 | 264 | $(echo-cmd) $(cmd_$(1)); \ |
| 267 | 265 | scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\ |
| 268 | 266 | rm -f $(depfile); |
| 269 | 267 | |
| 270 | −else | |
| 271 | − | |
| 272 | −# Filter out exported kernel symbol names from the preprocessor output. | |
| 273 | −# See also __KSYM_DEPS__ in include/linux/export.h. | |
| 274 | −# We disable the depfile generation here, so as not to overwrite the existing | |
| 275 | −# depfile while fixdep is parsing it. | |
| 276 | −flags_nodeps = $(filter-out -Wp$(comma)-M%, $($(1))) | |
| 277 | −ksym_dep_filter = \ | |
| 278 | − case "$(1)" in \ | |
| 279 | − cc_*_c|cpp_i_c) \ | |
| 280 | − $(CPP) $(call flags_nodeps,c_flags) -D__KSYM_DEPS__ $< ;; \ | |
| 281 | − as_*_S|cpp_s_S) \ | |
| 282 | − $(CPP) $(call flags_nodeps,a_flags) -D__KSYM_DEPS__ $< ;; \ | |
| 283 | − boot*|build*|cpp_its_S|*cpp_lds_S|dtc|host*|vdso*) : ;; \ | |
| 284 | − *) echo "Don't know how to preprocess $(1)" >&2; false ;; \ | |
| 285 | − esac | tr ";" "\n" | sed -n 's/^.*=== __KSYM_\(.*\) ===.*$$/_\1/p' | |
| 286 | − | |
| 287 | −cmd_and_fixdep = \ | |
| 288 | − $(echo-cmd) $(cmd_$(1)); \ | |
| 289 | − $(ksym_dep_filter) | \ | |
| 290 | − scripts/basic/fixdep -e $(depfile) $@ '$(make-cmd)' \ | |
| 291 | − > $(dot-target).cmd; \ | |
| 292 | − rm -f $(depfile); | |
| 293 | − | |
| 294 | −endif | |
| 295 | − | |
| 296 | 268 | # Usage: $(call if_changed_rule,foo) |
| 297 | 269 | # Will check if $(cmd_foo) or any of the prerequisites changed, |
| 298 | 270 | # and if so will execute $(rule_foo). |
| @@ -254,9 +254,15 @@ objtool_dep = $(objtool_obj) \ · 253 unmodified lines | ||
| 254 | 254 | $(wildcard include/config/orc/unwinder.h \ |
| 255 | 255 | include/config/stack/validation.h) |
| 256 | 256 | |
| 257 | +ifdef CONFIG_TRIM_UNUSED_KSYMS | |
| 258 | +cmd_gen_ksymdeps = \ | |
| 259 | + $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd; | |
| 260 | +endif | |
| 261 | + | |
| 257 | 262 | define rule_cc_o_c |
| 258 | 263 | $(call echo-cmd,checksrc) $(cmd_checksrc) \ |
| 259 | 264 | $(call cmd_and_fixdep,cc_o_c) \ |
| 265 | + $(cmd_gen_ksymdeps) \ | |
| 260 | 266 | $(cmd_checkdoc) \ |
| 261 | 267 | $(call echo-cmd,objtool) $(cmd_objtool) \ |
| 262 | 268 | $(cmd_modversions_c) \ |
| @@ -265,6 +271,7 @@ endef · 2 unmodified lines | ||
| 265 | 271 | |
| 266 | 272 | define rule_as_o_S |
| 267 | 273 | $(call cmd_and_fixdep,as_o_S) \ |
| 274 | + $(cmd_gen_ksymdeps) \ | |
| 268 | 275 | $(call echo-cmd,objtool) $(cmd_objtool) \ |
| 269 | 276 | $(cmd_modversions_S) |
| 270 | 277 | endef |
| @@ -105,8 +105,7 @@ · 104 unmodified lines | ||
| 105 | 105 | |
| 106 | 106 | static void usage(void) |
| 107 | 107 | { |
| 108 | − fprintf(stderr, "Usage: fixdep [-e] <depfile> <target> <cmdline>\n"); | |
| 109 | − fprintf(stderr, " -e insert extra dependencies given on stdin\n"); | |
| 108 | + fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n"); | |
| 110 | 109 | exit(1); |
| 111 | 110 | } |
| 112 | 111 | |
| @@ -131,21 +130,6 @@ static void print_dep(const char *m, int slen, const char *dir) · 18 unmodified lines | ||
| 131 | 130 | printf(".h) \\\n"); |
| 132 | 131 | } |
| 133 | 132 | |
| 134 | −static void do_extra_deps(void) | |
| 135 | −{ | |
| 136 | − char buf[80]; | |
| 137 | − | |
| 138 | − while (fgets(buf, sizeof(buf), stdin)) { | |
| 139 | − int len = strlen(buf); | |
| 140 | − | |
| 141 | − if (len < 2 || buf[len - 1] != '\n') { | |
| 142 | − fprintf(stderr, "fixdep: bad data on stdin\n"); | |
| 143 | − exit(1); | |
| 144 | − } | |
| 145 | − print_dep(buf, len - 1, "include/ksym"); | |
| 146 | − } | |
| 147 | −} | |
| 148 | − | |
| 149 | 133 | struct item { |
| 150 | 134 | struct item *next; |
| 151 | 135 | unsigned int len; |
| @@ -293,7 +277,7 @@ static int is_ignored_file(const char *s, int len) · 141 unmodified lines | ||
| 293 | 277 | * assignments are parsed not only by make, but also by the rather simple |
| 294 | 278 | * parser in scripts/mod/sumversion.c. |
| 295 | 279 | */ |
| 296 | −static void parse_dep_file(char *m, const char *target, int insert_extra_deps) | |
| 280 | +static void parse_dep_file(char *m, const char *target) | |
| 297 | 281 | { |
| 298 | 282 | char *p; |
| 299 | 283 | int is_last, is_target; |
| @@ -369,9 +353,6 @@ static void parse_dep_file(char *m, const char *target, int insert_extra_deps) · 69 unmodified lines | ||
| 369 | 353 | exit(1); |
| 370 | 354 | } |
| 371 | 355 | |
| 372 | − if (insert_extra_deps) | |
| 373 | − do_extra_deps(); | |
| 374 | − | |
| 375 | 356 | printf("\n%s: $(deps_%s)\n\n", target, target); |
| 376 | 357 | printf("$(deps_%s):\n", target); |
| 377 | 358 | } |
| @@ -379,13 +360,9 @@ static void parse_dep_file(char *m, const char *target, int insert_extra_deps) · 1 unmodified line | ||
| 379 | 360 | int main(int argc, char *argv[]) |
| 380 | 361 | { |
| 381 | 362 | const char *depfile, *target, *cmdline; |
| 382 | − int insert_extra_deps = 0; | |
| 383 | 363 | void *buf; |
| 384 | 364 | |
| 385 | − if (argc == 5 && !strcmp(argv[1], "-e")) { | |
| 386 | − insert_extra_deps = 1; | |
| 387 | − argv++; | |
| 388 | − } else if (argc != 4) | |
| 365 | + if (argc != 4) | |
| 389 | 366 | usage(); |
| 390 | 367 | |
| 391 | 368 | depfile = argv[1]; |
| @@ -395,7 +372,7 @@ int main(int argc, char *argv[]) · 3 unmodified lines | ||
| 395 | 372 | printf("cmd_%s := %s\n\n", target, cmdline); |
| 396 | 373 | |
| 397 | 374 | buf = read_file(depfile); |
| 398 | − parse_dep_file(buf, target, insert_extra_deps); | |
| 375 | + parse_dep_file(buf, target); | |
| 399 | 376 | free(buf); |
| 400 | 377 | |
| 401 | 378 | return 0; |
| @@ -0,0 +1,25 @@ | ||
| 1 | +#!/bin/sh | |
| 2 | +# SPDX-License-Identifier: GPL-2.0 | |
| 3 | + | |
| 4 | +set -e | |
| 5 | + | |
| 6 | +# List of exported symbols | |
| 7 | +ksyms=$($NM $1 | sed -n 's/.*__ksym_marker_\(.*\)/\1/p' | tr A-Z a-z) | |
| 8 | + | |
| 9 | +if [ -z "$ksyms" ]; then | |
| 10 | + exit 0 | |
| 11 | +fi | |
| 12 | + | |
| 13 | +echo | |
| 14 | +echo "ksymdeps_$1 := \\" | |
| 15 | + | |
| 16 | +for s in $ksyms | |
| 17 | +do | |
| 18 | + echo $s | sed -e 's:^_*: $(wildcard include/ksym/:' \ | |
| 19 | + -e 's:__*:/:g' -e 's/$/.h) \\/' | |
| 20 | +done | |
| 21 | + | |
| 22 | +echo | |
| 23 | +echo "$1: \$(ksymdeps_$1)" | |
| 24 | +echo | |
| 25 | +echo "\$(ksymdeps_$1):" | |