Kbuild updates for v4.20

- optimize kallsyms slightly
 
 - remove check for old CFLAGS usage
 
 - add some compiler flags unconditionally instead of evaluating
   $(call cc-option,...)
 
 - fix variable shadowing in host tools
 
 - refactor scripts/mkmakefile
 
 - refactor various makefiles
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABAgAGBQJb1eyEAAoJED2LAQed4NsGUjwP/0/W0nLP+nKCJ0NpsSD151Ea
 Vrbm+RMxl8uPuQ0+Bh59rdO2yWR8v7jOX8CPbX1DqW0XwW4vTNRZm9j6A83rJzHv
 dPpinUObq6vXGJCYvMLoumhOkM1lRZie1AeBeLgKF0G0jprxUspGvakSyM/5SOo6
 3gIhpPcczijC980KHIJbmwiGqRFVs3/zwqcKjQaRD3C6f4HdJL3i9Zr7kuZF0g1x
 dxCdN4Shv5x0igggp58z8646bbKlN7hItYaPq2csDop55/jWKzUkBkFkeaDjiUdB
 B6ysQfwkuTb6sbKXE6euYLUTyc6epx9v9pey0FpOx5tjXT+QmgK1ddLQEwdFH2+/
 Fd5VR70h8uKTNvmqFJ+iebpR/aC71sUqYAzsoiTVZibR/F6+QAuhHJPZJDlSSwLC
 QH7j0fwJ3X5p9PYe3JBWyWzOd9BDvtV+HGE67Kx17iRNW0FDyKSvn7tezRVtqvHr
 KENrMT4n+lNQzB+c4lfjOE9ANpOf+PP4+ODhbrtvKItyb5QfF4F+5CDVif3wv3Kt
 6dvh13hvR06gQCpbuxcFgD17mT1T/lVieuzOnWjtEh4HiMI1H0abYfkRWbQshrti
 u7TfYxwAyWKtisiPiT/1THYsW3ux7QmTSIo2iOznQxDlbmzENpQx+f22HsLaC0XU
 AUgvKGBaN0WOar2f2gyq
 =jM4E
 -----END PGP SIGNATURE-----

Merge tag 'kbuild-v4.20' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild

Pull Kbuild updates from Masahiro Yamada:

 - optimize kallsyms slightly

 - remove check for old CFLAGS usage

 - add some compiler flags unconditionally instead of evaluating
   $(call cc-option,...)

 - fix variable shadowing in host tools

 - refactor scripts/mkmakefile

 - refactor various makefiles

* tag 'kbuild-v4.20' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild:
  modpost: Create macro to avoid variable shadowing
  ASN.1: Remove unnecessary shadowed local variable
  kbuild: use 'else ifeq' for checksrc to improve readability
  kbuild: remove unneeded link_multi_deps
  kbuild: add -Wno-unused-but-set-variable flag unconditionally
  kbuild: add -Wdeclaration-after-statement flag unconditionally
  kbuild: add -Wno-pointer-sign flag unconditionally
  modpost: remove leftover symbol prefix handling for module device table
  kbuild: simplify command line creation in scripts/mkmakefile
  kbuild: do not pass $(objtree) to scripts/mkmakefile
  kbuild: remove user ID check in scripts/mkmakefile
  kbuild: remove VERSION and PATCHLEVEL from $(objtree)/Makefile
  kbuild: add --include-dir flag only for out-of-tree build
  kbuild: remove dead code in cmd_files calculation in top Makefile
  kbuild: hide most of targets when running config or mixed targets
  kbuild: remove old check for CFLAGS use
  kbuild: prefix Makefile.dtbinst path with $(srctree) unconditionally
  kallsyms: remove left-over Blackfin code
  kallsyms: reduce size a little on 64-bit
This commit is contained in:
Linus Torvalds 2018-10-28 13:22:35 -07:00
commit ac747c0715
8 changed files with 53 additions and 84 deletions

View File

@ -15,10 +15,9 @@ NAME = "People's Front"
PHONY := _all PHONY := _all
_all: _all:
# o Do not use make's built-in rules and variables # Do not use make's built-in rules and variables
# (this increases performance and avoids hard-to-debug behaviour); # (this increases performance and avoids hard-to-debug behaviour)
# o Look for make include files relative to root of kernel src MAKEFLAGS += -rR
MAKEFLAGS += -rR --include-dir=$(CURDIR)
# Avoid funny character set dependencies # Avoid funny character set dependencies
unexport LC_ALL unexport LC_ALL
@ -136,6 +135,13 @@ KBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
$(if $(KBUILD_OUTPUT),, \ $(if $(KBUILD_OUTPUT),, \
$(error failed to create output directory "$(saved-output)")) $(error failed to create output directory "$(saved-output)"))
# Look for make include files relative to root of kernel src
#
# This does not become effective immediately because MAKEFLAGS is re-parsed
# once after the Makefile is read. It is OK since we are going to invoke
# 'sub-make' below.
MAKEFLAGS += --include-dir=$(CURDIR)
PHONY += $(MAKECMDGOALS) sub-make PHONY += $(MAKECMDGOALS) sub-make
$(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make $(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
@ -476,8 +482,7 @@ PHONY += outputmakefile
outputmakefile: outputmakefile:
ifneq ($(KBUILD_SRC),) ifneq ($(KBUILD_SRC),)
$(Q)ln -fsn $(srctree) source $(Q)ln -fsn $(srctree) source
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \ $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
$(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
endif endif
ifeq ($(cc-name),clang) ifeq ($(cc-name),clang)
@ -713,7 +718,7 @@ else
# These warnings generated too much noise in a regular build. # These warnings generated too much noise in a regular build.
# Use make W=1 to enable them (see scripts/Makefile.extrawarn) # Use make W=1 to enable them (see scripts/Makefile.extrawarn)
KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable) KBUILD_CFLAGS += -Wno-unused-but-set-variable
endif endif
KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable) KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
@ -794,10 +799,10 @@ endif
NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
# warn about C99 declaration after statement # warn about C99 declaration after statement
KBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement,) KBUILD_CFLAGS += -Wdeclaration-after-statement
# disable pointer signed / unsigned warnings in gcc 4.0 # disable pointer signed / unsigned warnings in gcc 4.0
KBUILD_CFLAGS += $(call cc-disable-warning, pointer-sign) KBUILD_CFLAGS += -Wno-pointer-sign
# disable stringop warnings in gcc 8+ # disable stringop warnings in gcc 8+
KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
@ -1647,9 +1652,6 @@ namespacecheck:
export_report: export_report:
$(PERL) $(srctree)/scripts/export_report.pl $(PERL) $(srctree)/scripts/export_report.pl
endif #ifeq ($(config-targets),1)
endif #ifeq ($(mixed-targets),1)
PHONY += checkstack kernelrelease kernelversion image_name PHONY += checkstack kernelrelease kernelversion image_name
# UML needs a little special treatment here. It wants to use the host # UML needs a little special treatment here. It wants to use the host
@ -1756,14 +1758,15 @@ cmd_crmodverdir = $(Q)mkdir -p $(MODVERDIR) \
$(if $(KBUILD_MODULES),; rm -f $(MODVERDIR)/*) $(if $(KBUILD_MODULES),; rm -f $(MODVERDIR)/*)
# read all saved command lines # read all saved command lines
cmd_files := $(wildcard .*.cmd)
cmd_files := $(wildcard .*.cmd $(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd))
ifneq ($(cmd_files),) ifneq ($(cmd_files),)
$(cmd_files): ; # Do not try to update included dependency files $(cmd_files): ; # Do not try to update included dependency files
include $(cmd_files) include $(cmd_files)
endif endif
endif # ifeq ($(config-targets),1)
endif # ifeq ($(mixed-targets),1)
endif # skip-makefile endif # skip-makefile
PHONY += FORCE PHONY += FORCE

View File

@ -37,7 +37,7 @@ extern const u8 kallsyms_names[] __weak;
* Tell the compiler that the count isn't in the small data section if the arch * Tell the compiler that the count isn't in the small data section if the arch
* has one (eg: FRV). * has one (eg: FRV).
*/ */
extern const unsigned long kallsyms_num_syms extern const unsigned int kallsyms_num_syms
__attribute__((weak, section(".rodata"))); __attribute__((weak, section(".rodata")));
extern const unsigned long kallsyms_relative_base extern const unsigned long kallsyms_relative_base
@ -46,7 +46,7 @@ __attribute__((weak, section(".rodata")));
extern const u8 kallsyms_token_table[] __weak; extern const u8 kallsyms_token_table[] __weak;
extern const u16 kallsyms_token_index[] __weak; extern const u16 kallsyms_token_index[] __weak;
extern const unsigned long kallsyms_markers[] __weak; extern const unsigned int kallsyms_markers[] __weak;
/* /*
* Expand a compressed symbol data into the resulting uncompressed string, * Expand a compressed symbol data into the resulting uncompressed string,

View File

@ -195,7 +195,7 @@ modbuiltin := -f $(srctree)/scripts/Makefile.modbuiltin obj
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj= # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj=
# Usage: # Usage:
# $(Q)$(MAKE) $(dtbinst)=dir # $(Q)$(MAKE) $(dtbinst)=dir
dtbinst := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.dtbinst obj dtbinst := -f $(srctree)/scripts/Makefile.dtbinst obj
### ###
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj= # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=

View File

@ -36,21 +36,11 @@ subdir-ccflags-y :=
include scripts/Kbuild.include include scripts/Kbuild.include
# For backward compatibility check that these variables do not change
save-cflags := $(CFLAGS)
# The filename Kbuild has precedence over Makefile # The filename Kbuild has precedence over Makefile
kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile) kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
include $(kbuild-file) include $(kbuild-file)
# If the save-* variables changed error out
ifeq ($(KBUILD_NOPEDANTIC),)
ifneq ("$(save-cflags)","$(CFLAGS)")
$(error CFLAGS was changed in "$(kbuild-file)". Fix it to use ccflags-y)
endif
endif
include scripts/Makefile.lib include scripts/Makefile.lib
# Do not include host rules unless needed # Do not include host rules unless needed
@ -83,14 +73,12 @@ __build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
@: @:
# Linus' kernel sanity checking tool # Linus' kernel sanity checking tool
ifneq ($(KBUILD_CHECKSRC),0) ifeq ($(KBUILD_CHECKSRC),1)
ifeq ($(KBUILD_CHECKSRC),2)
quiet_cmd_force_checksrc = CHECK $<
cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ;
else
quiet_cmd_checksrc = CHECK $< quiet_cmd_checksrc = CHECK $<
cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ; cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ;
endif else ifeq ($(KBUILD_CHECKSRC),2)
quiet_cmd_force_checksrc = CHECK $<
cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< ;
endif endif
ifneq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),) ifneq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),)
@ -495,28 +483,12 @@ targets += $(obj)/lib-ksyms.o
endif endif
#
# Rule to link composite objects
#
# Composite objects are specified in kbuild makefile as follows:
# <composite-object>-objs := <list of .o files>
# or
# <composite-object>-y := <list of .o files>
# or
# <composite-object>-m := <list of .o files>
# The -m syntax only works if <composite object> is a module
link_multi_deps = \
$(filter $(addprefix $(obj)/, \
$($(subst $(obj)/,,$(@:.o=-objs))) \
$($(subst $(obj)/,,$(@:.o=-y))) \
$($(subst $(obj)/,,$(@:.o=-m)))), $^)
quiet_cmd_link_multi-m = LD [M] $@ quiet_cmd_link_multi-m = LD [M] $@
cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis) cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(filter %.o,$^) $(cmd_secanalysis)
$(multi-used-m): FORCE $(multi-used-m): FORCE
$(call if_changed,link_multi-m) $(call if_changed,link_multi-m)
@{ echo $(@:.o=.ko); echo $(link_multi_deps); \ @{ echo $(@:.o=.ko); echo $(filter %.o,$^); \
$(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod) $(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod)
$(call multi_depend, $(multi-used-m), .o, -objs -y -m) $(call multi_depend, $(multi-used-m), .o, -objs -y -m)

View File

@ -413,7 +413,7 @@ static void tokenise(char *buffer, char *end)
/* Handle string tokens */ /* Handle string tokens */
if (isalpha(*p)) { if (isalpha(*p)) {
const char **dir, *start = p; const char **dir;
/* Can be a directive, type name or element /* Can be a directive, type name or element
* name. Find the end of the name. * name. Find the end of the name.

View File

@ -48,8 +48,6 @@ static unsigned long long relative_base;
static struct addr_range text_ranges[] = { static struct addr_range text_ranges[] = {
{ "_stext", "_etext" }, { "_stext", "_etext" },
{ "_sinittext", "_einittext" }, { "_sinittext", "_einittext" },
{ "_stext_l1", "_etext_l1" }, /* Blackfin on-chip L1 inst SRAM */
{ "_stext_l2", "_etext_l2" }, /* Blackfin on-chip L2 SRAM */
}; };
#define text_range_text (&text_ranges[0]) #define text_range_text (&text_ranges[0])
#define text_range_inittext (&text_ranges[1]) #define text_range_inittext (&text_ranges[1])
@ -405,7 +403,7 @@ static void write_src(void)
} }
output_label("kallsyms_num_syms"); output_label("kallsyms_num_syms");
printf("\tPTR\t%u\n", table_cnt); printf("\t.long\t%u\n", table_cnt);
printf("\n"); printf("\n");
/* table of offset markers, that give the offset in the compressed stream /* table of offset markers, that give the offset in the compressed stream
@ -434,7 +432,7 @@ static void write_src(void)
output_label("kallsyms_markers"); output_label("kallsyms_markers");
for (i = 0; i < ((table_cnt + 255) >> 8); i++) for (i = 0; i < ((table_cnt + 255) >> 8); i++)
printf("\tPTR\t%d\n", markers[i]); printf("\t.long\t%u\n", markers[i]);
printf("\n"); printf("\n");
free(markers); free(markers);

View File

@ -6,31 +6,20 @@
# Usage # Usage
# $1 - Kernel src directory # $1 - Kernel src directory
# $2 - Output directory
# $3 - version
# $4 - patchlevel
test ! -r $2/Makefile -o -O $2/Makefile || exit 0
# Only overwrite automatically generated Makefiles # Only overwrite automatically generated Makefiles
# (so we do not overwrite kernel Makefile) # (so we do not overwrite kernel Makefile)
if test -e $2/Makefile && ! grep -q Automatically $2/Makefile if test -e Makefile && ! grep -q Automatically Makefile
then then
exit 0 exit 0
fi fi
if [ "${quiet}" != "silent_" ]; then if [ "${quiet}" != "silent_" ]; then
echo " GEN $2/Makefile" echo " GEN Makefile"
fi fi
cat << EOF > $2/Makefile cat << EOF > Makefile
# Automatically generated by $0: don't edit # Automatically generated by $0: don't edit
VERSION = $3
PATCHLEVEL = $4
lastword = \$(word \$(words \$(1)),\$(1))
makedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST)))
ifeq ("\$(origin V)", "command line") ifeq ("\$(origin V)", "command line")
VERBOSE := \$(V) VERBOSE := \$(V)
endif endif
@ -38,15 +27,12 @@ ifneq (\$(VERBOSE),1)
Q := @ Q := @
endif endif
MAKEARGS := -C $1
MAKEARGS += O=\$(if \$(patsubst /%,,\$(makedir)),\$(CURDIR)/)\$(patsubst %/,%,\$(makedir))
MAKEFLAGS += --no-print-directory MAKEFLAGS += --no-print-directory
.PHONY: __sub-make \$(MAKECMDGOALS) .PHONY: __sub-make \$(MAKECMDGOALS)
__sub-make: __sub-make:
\$(Q)\$(MAKE) \$(MAKEARGS) \$(MAKECMDGOALS) \$(Q)\$(MAKE) -C $1 O=\$(CURDIR) \$(MAKECMDGOALS)
\$(filter-out __sub-make, \$(MAKECMDGOALS)): __sub-make \$(filter-out __sub-make, \$(MAKECMDGOALS)): __sub-make
@: @:

View File

@ -95,12 +95,20 @@ extern struct devtable *__start___devtable[], *__stop___devtable[];
*/ */
#define DEF_FIELD(m, devid, f) \ #define DEF_FIELD(m, devid, f) \
typeof(((struct devid *)0)->f) f = TO_NATIVE(*(typeof(f) *)((m) + OFF_##devid##_##f)) typeof(((struct devid *)0)->f) f = TO_NATIVE(*(typeof(f) *)((m) + OFF_##devid##_##f))
/* Define a variable v that holds the address of field f of struct devid
* based at address m. Due to the way typeof works, for a field of type
* T[N] the variable has type T(*)[N], _not_ T*.
*/
#define DEF_FIELD_ADDR_VAR(m, devid, f, v) \
typeof(((struct devid *)0)->f) *v = ((m) + OFF_##devid##_##f)
/* Define a variable f that holds the address of field f of struct devid /* Define a variable f that holds the address of field f of struct devid
* based at address m. Due to the way typeof works, for a field of type * based at address m. Due to the way typeof works, for a field of type
* T[N] the variable has type T(*)[N], _not_ T*. * T[N] the variable has type T(*)[N], _not_ T*.
*/ */
#define DEF_FIELD_ADDR(m, devid, f) \ #define DEF_FIELD_ADDR(m, devid, f) \
typeof(((struct devid *)0)->f) *f = ((m) + OFF_##devid##_##f) DEF_FIELD_ADDR_VAR(m, devid, f, f)
/* Add a table entry. We test function type matches while we're here. */ /* Add a table entry. We test function type matches while we're here. */
#define ADD_TO_DEVTABLE(device_id, type, function) \ #define ADD_TO_DEVTABLE(device_id, type, function) \
@ -656,10 +664,13 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
/* find duplicate, already added value */ /* find duplicate, already added value */
for (i2 = 0; i2 < i && !dup; i2++) { for (i2 = 0; i2 < i && !dup; i2++) {
DEF_FIELD_ADDR(symval + i2*id_size, pnp_card_device_id, devs); DEF_FIELD_ADDR_VAR(symval + i2 * id_size,
pnp_card_device_id,
devs, devs_dup);
for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) { for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) {
const char *id2 = (char *)(*devs)[j2].id; const char *id2 =
(char *)(*devs_dup)[j2].id;
if (!id2[0]) if (!id2[0])
break; break;
@ -1415,11 +1426,10 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT) if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT)
return; return;
/* All our symbols are of form <prefix>__mod_<name>__<identifier>_device_table. */ /* All our symbols are of form __mod_<name>__<identifier>_device_table. */
name = strstr(symname, "__mod_"); if (strncmp(symname, "__mod_", strlen("__mod_")))
if (!name)
return; return;
name += strlen("__mod_"); name = symname + strlen("__mod_");
namelen = strlen(name); namelen = strlen(name);
if (namelen < strlen("_device_table")) if (namelen < strlen("_device_table"))
return; return;