kbuild: Bump the build system to 5.1

Our last sync with the kernel was 5.1. Even that was a partial one
as some patches from 4.x kernels were already missing making the
transition to a modern kbuild infeasible.

We are so out of sync now, that tracking the patches and backporting
them one by one makes little sense and it's going to take ages.

This is an attempt to sync up Makefile[.lib/.kbuild].
Unfortunately due to sheer amount of patches this is not easy to review,
but that's what we decided during a community call.

One of the biggest changes is get rid of partial linking entirely and
build .a archives isntead of .o.
We diaviate from the kernel on that. Instead of calling a custom script
to create the archive symbol table, we call ar with rcTP (isntead of
rcSTP) since we want a resulting archive that's sauble with the linker.

The only affected platforms are PPC ones. Unfortunately I don't have any
of them around to test, but the objdump of the resulting files --
arch/powerpc/lib/built-in.[oa] looks identical.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
This commit is contained in:
Ilias Apalodimas
2025-06-27 21:57:16 +03:00
committed by Tom Rini
parent 22595e7430
commit 5f520875bd
18 changed files with 917 additions and 471 deletions

862
Makefile

File diff suppressed because it is too large Load Diff

View File

@@ -16,8 +16,8 @@ endif
endif endif
ifdef MINIMAL ifdef MINIMAL
# necessary to create built-in.o # necessary to create built-in.a
obj- := __dummy__.o obj- := __dummy__.a
else else
obj-y += mmc.o obj-y += mmc.o

View File

@@ -18,8 +18,8 @@ SECTIONS
{ {
arch/powerpc/cpu/mpc8xx/start.o (.text) arch/powerpc/cpu/mpc8xx/start.o (.text)
arch/powerpc/cpu/mpc8xx/traps.o (.text*) arch/powerpc/cpu/mpc8xx/traps.o (.text*)
arch/powerpc/lib/built-in.o (.text*) arch/powerpc/lib/built-in.a (.text*)
drivers/net/built-in.o (.text*) drivers/net/built-in.a (.text*)
. = DEFINED(env_offset) ? env_offset : .; . = DEFINED(env_offset) ? env_offset : .;
env/embedded.o (.text.environment) env/embedded.o (.text.environment)

View File

@@ -18,8 +18,8 @@ SECTIONS
{ {
arch/powerpc/cpu/mpc8xx/start.o (.text) arch/powerpc/cpu/mpc8xx/start.o (.text)
arch/powerpc/cpu/mpc8xx/traps.o (.text*) arch/powerpc/cpu/mpc8xx/traps.o (.text*)
arch/powerpc/lib/built-in.o (.text*) arch/powerpc/lib/built-in.a (.text*)
drivers/net/built-in.o (.text*) drivers/net/built-in.a (.text*)
. = DEFINED(env_offset) ? env_offset : .; . = DEFINED(env_offset) ? env_offset : .;
env/embedded.o (.text.environment) env/embedded.o (.text.environment)

View File

@@ -14,8 +14,8 @@ endif
endif endif
ifdef MINIMAL ifdef MINIMAL
# necessary to create built-in.o # necessary to create built-in.a
obj- := __dummy__.o obj- := __dummy__.a
else else
# include i2c_common.o once if either VID or FSL_USE_PCA9547_MUX # include i2c_common.o once if either VID or FSL_USE_PCA9547_MUX
I2C_COMMON= I2C_COMMON=

View File

@@ -16,8 +16,8 @@ endif
# Common for all Toradex modules # Common for all Toradex modules
ifeq ($(CONFIG_XPL_BUILD),y) ifeq ($(CONFIG_XPL_BUILD),y)
# Necessary to create built-in.o # Necessary to create built-in.a
obj- := __dummy__.o obj- := __dummy__.a
else else
obj-$(CONFIG_TDX_CFG_BLOCK) += ../../toradex/common/tdx-cfg-block.o obj-$(CONFIG_TDX_CFG_BLOCK) += ../../toradex/common/tdx-cfg-block.o
obj-y += ../../toradex/common/tdx-common.o obj-y += ../../toradex/common/tdx-common.o

View File

@@ -3,8 +3,8 @@
# Author: Teresa Remmet <t.remmet@phytec.de> # Author: Teresa Remmet <t.remmet@phytec.de>
ifdef CONFIG_XPL_BUILD ifdef CONFIG_XPL_BUILD
# necessary to create built-in.o # necessary to create built-in.a
obj- := __dummy__.o obj- := __dummy__.a
endif endif
obj-y += phytec_som_detection.o phytec_som_detection_blocks.o obj-y += phytec_som_detection.o phytec_som_detection_blocks.o

View File

@@ -3,8 +3,8 @@
# Copyright (C) 2011 Samsung Electronics # Copyright (C) 2011 Samsung Electronics
ifdef CONFIG_XPL_BUILD ifdef CONFIG_XPL_BUILD
# necessary to create built-in.o # necessary to create built-in.a
obj- := __dummy__.o obj- := __dummy__.a
hostprogs-y := tools/mkorigenspl hostprogs-y := tools/mkorigenspl
always := $(hostprogs-y) always := $(hostprogs-y)

View File

@@ -3,8 +3,8 @@
# Copyright (C) 2011 Samsung Electronics # Copyright (C) 2011 Samsung Electronics
ifdef CONFIG_XPL_BUILD ifdef CONFIG_XPL_BUILD
# necessary to create built-in.o # necessary to create built-in.a
obj- := __dummy__.o obj- := __dummy__.a
hostprogs-y := tools/mksmdkv310spl hostprogs-y := tools/mksmdkv310spl
always := $(hostprogs-y) always := $(hostprogs-y)

View File

@@ -3,8 +3,8 @@
# Common for all Toradex modules # Common for all Toradex modules
ifeq ($(CONFIG_XPL_BUILD),y) ifeq ($(CONFIG_XPL_BUILD),y)
# Necessary to create built-in.o # Necessary to create built-in.a
obj- := __dummy__.o obj- := __dummy__.a
else else
obj-$(CONFIG_TDX_CFG_BLOCK) += tdx-cfg-block.o obj-$(CONFIG_TDX_CFG_BLOCK) += tdx-cfg-block.o
obj-y += tdx-common.o obj-y += tdx-common.o

View File

@@ -130,17 +130,17 @@ the compiler cannot update the alignment of the linker_list item.
In the first case, an 8-byte 'fill' region is added:: In the first case, an 8-byte 'fill' region is added::
__u_boot_list_2_driver_2_testbus_drv __u_boot_list_2_driver_2_testbus_drv
0x0000000000270018 0x80 test/built-in.o 0x0000000000270018 0x80 test/built-in.a
0x0000000000270018 _u_boot_list_2_driver_2_testbus_drv 0x0000000000270018 _u_boot_list_2_driver_2_testbus_drv
__u_boot_list_2_driver_2_testfdt1_drv __u_boot_list_2_driver_2_testfdt1_drv
0x0000000000270098 0x80 test/built-in.o 0x0000000000270098 0x80 test/built-in.a
0x0000000000270098 _u_boot_list_2_driver_2_testfdt1_drv 0x0000000000270098 _u_boot_list_2_driver_2_testfdt1_drv
*fill* 0x0000000000270118 0x8 *fill* 0x0000000000270118 0x8
__u_boot_list_2_driver_2_testfdt_drv __u_boot_list_2_driver_2_testfdt_drv
0x0000000000270120 0x80 test/built-in.o 0x0000000000270120 0x80 test/built-in.a
0x0000000000270120 _u_boot_list_2_driver_2_testfdt_drv 0x0000000000270120 _u_boot_list_2_driver_2_testfdt_drv
__u_boot_list_2_driver_2_testprobe_drv __u_boot_list_2_driver_2_testprobe_drv
0x00000000002701a0 0x80 test/built-in.o 0x00000000002701a0 0x80 test/built-in.a
0x00000000002701a0 _u_boot_list_2_driver_2_testprobe_drv 0x00000000002701a0 _u_boot_list_2_driver_2_testprobe_drv
With this, the linker_list no-longer works since items after testfdt1_drv With this, the linker_list no-longer works since items after testfdt1_drv

View File

@@ -89,15 +89,15 @@ File u-boot.map contains the memory layout of the U-Boot binary. Here we find
these lines:: these lines::
.text.do_undefined .text.do_undefined
0x00000000000101fc 0xc cmd/built-in.o 0x00000000000101fc 0xc cmd/built-in.a
.text.exception_complete .text.exception_complete
0x0000000000010208 0x90 cmd/built-in.o 0x0000000000010208 0x90 cmd/built-in.a
... ...
.text.cmd_process .text.cmd_process
0x00000000000213b8 0x164 common/built-in.o 0x00000000000213b8 0x164 common/built-in.a
0x00000000000213b8 cmd_process 0x00000000000213b8 cmd_process
.text.cmd_process_error .text.cmd_process_error
0x000000000002151c 0x40 common/built-in.o 0x000000000002151c 0x40 common/built-in.a
0x000000000002151c cmd_process_error 0x000000000002151c cmd_process_error
So the error occurred at the start of function do\_undefined() and this So the error occurred at the start of function do\_undefined() and this

View File

@@ -76,10 +76,12 @@ endif
ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),) ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),)
lib-target := $(obj)/lib.a lib-target := $(obj)/lib.a
# Modified for U-Boot
# real-obj-y += $(obj)/lib-ksyms.o
endif endif
ifneq ($(strip $(obj-y) $(obj-m) $(obj-) $(subdir-m) $(lib-target)),) ifneq ($(strip $(real-obj-y) $(need-builtin)),)
builtin-target := $(obj)/built-in.o builtin-target := $(obj)/built-in.a
endif endif
ifdef CONFIG_MODULES ifdef CONFIG_MODULES
@@ -102,7 +104,11 @@ else ifeq ($(KBUILD_CHECKSRC),2)
cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $<
endif endif
# Do section mismatch analysis for each module/built-in.o ifneq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),)
cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $<
endif
# Do section mismatch analysis for each module/built-in.a
ifdef CONFIG_DEBUG_SECTION_MISMATCH ifdef CONFIG_DEBUG_SECTION_MISMATCH
cmd_secanalysis = ; scripts/mod/modpost $@ cmd_secanalysis = ; scripts/mod/modpost $@
endif endif
@@ -111,101 +117,94 @@ endif
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Default is built-in, unless we know otherwise # Default is built-in, unless we know otherwise
$(foreach x, i ll lst o s symtypes, $(patsubst %.o,%.$(x),$(real-obj-m))): \
part-of-module := y
modkern_cflags = \ modkern_cflags = \
$(if $(part-of-module), \ $(if $(part-of-module), \
$(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \ $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
$(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL)) $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL))
quiet_modtag = $(if $(part-of-module),[M], ) quiet_modtag = $(if $(part-of-module),[M], )
$(real-objs-m) : part-of-module := y
$(real-objs-m:.o=.i) : part-of-module := y
$(real-objs-m:.o=.s) : part-of-module := y
$(real-objs-m:.o=.lst): part-of-module := y
# Default for not multi-part modules
modname = $(basetarget)
$(multi-objs-m) : modname = $(modname-multi)
$(multi-objs-m:.o=.i) : modname = $(modname-multi)
$(multi-objs-m:.o=.s) : modname = $(modname-multi)
$(multi-objs-m:.o=.lst) : modname = $(modname-multi)
$(multi-objs-y) : modname = $(modname-multi)
$(multi-objs-y:.o=.i) : modname = $(modname-multi)
$(multi-objs-y:.o=.s) : modname = $(modname-multi)
$(multi-objs-y:.o=.lst) : modname = $(modname-multi)
quiet_cmd_cc_s_c = CC $(quiet_modtag) $@ quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
cmd_cc_s_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $< cmd_cc_s_c = $(CC) $(filter-out $(DEBUG_CFLAGS), $(c_flags)) $(DISABLE_LTO) -fverbose-asm -S -o $@ $<
$(obj)/%.s: $(src)/%.c FORCE $(obj)/%.s: $(src)/%.c FORCE
$(call if_changed_dep,cc_s_c) $(call if_changed_dep,cc_s_c)
quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@ quiet_cmd_cpp_i_c = CPP $(quiet_modtag) $@
cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $< cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $<
$(obj)/%.i: $(src)/%.c FORCE $(obj)/%.i: $(src)/%.c FORCE
$(call if_changed_dep,cc_i_c) $(call if_changed_dep,cpp_i_c)
cmd_gensymtypes = \ # These mirror gensymtypes_S and co below, keep them in synch.
cmd_gensymtypes_c = \
$(CPP) -D__GENKSYMS__ $(c_flags) $< | \ $(CPP) -D__GENKSYMS__ $(c_flags) $< | \
scripts/genksyms/genksyms $(if $(1), -T $(2)) \ scripts/genksyms/genksyms $(if $(1), -T $(2)) \
$(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) \
$(if $(KBUILD_PRESERVE),-p) \ $(if $(KBUILD_PRESERVE),-p) \
-r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null)) -r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@ quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
cmd_cc_symtypes_c = \ cmd_cc_symtypes_c = \
$(call cmd_gensymtypes,true,$@) >/dev/null; \ $(call cmd_gensymtypes_c,true,$@) >/dev/null; \
test -s $@ || rm -f $@ test -s $@ || rm -f $@
$(obj)/%.symtypes : $(src)/%.c FORCE $(obj)/%.symtypes : $(src)/%.c FORCE
$(call cmd,cc_symtypes_c) $(call cmd,cc_symtypes_c)
# LLVM assembly
# Generate .ll files from .c
quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -o $@ $<
$(obj)/%.ll: $(src)/%.c FORCE
$(call if_changed_dep,cc_ll_c)
# C (.c) files # C (.c) files
# The C file is compiled and updated dependency information is generated. # The C file is compiled and updated dependency information is generated.
# (See cmd_cc_o_c + relevant part of rule_cc_o_c) # (See cmd_cc_o_c + relevant part of rule_cc_o_c)
quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
ifdef CONFIG_MODVERSIONS ifdef CONFIG_MODVERSIONS
# When module versioning is enabled the following steps are executed: # When module versioning is enabled the following steps are executed:
# o compile a <file>.o from <file>.c # o compile a <file>.o from <file>.c
# o if <file>.o doesn't contain a __ksymtab version, i.e. does # o if <file>.o doesn't contain a __ksymtab version, i.e. does
# not export symbols, it's done # not export symbols, it's done.
# o otherwise, we calculate symbol versions using the good old # o otherwise, we calculate symbol versions using the good old
# genksyms on the preprocessed source and postprocess them in a way # genksyms on the preprocessed source and postprocess them in a way
# that they are usable as a linker script # that they are usable as a linker script
# o generate .tmp_<file>.o from <file>.o using the linker to # o generate .tmp_<file>.o from <file>.o using the linker to
# replace the unresolved symbols __crc_exported_symbol with # replace the unresolved symbols __crc_exported_symbol with
# the actual value of the checksum generated by genksyms # the actual value of the checksum generated by genksyms
# o remove .tmp_<file>.o to <file>.o # o remove .tmp_<file>.o to <file>.o
cmd_modversions = \
cmd_modversions_c = \
if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \ if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \
$(call cmd_gensymtypes,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
> $(@D)/.tmp_$(@F:.o=.ver); \ > $(@D)/.tmp_$(@F:.o=.ver); \
\ \
$(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \ $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \
-T $(@D)/.tmp_$(@F:.o=.ver); \ -T $(@D)/.tmp_$(@F:.o=.ver); \
mv -f $(@D)/.tmp_$(@F) $@; \ mv -f $(@D)/.tmp_$(@F) $@; \
rm -f $(@D)/.tmp_$(@F:.o=.ver); \ rm -f $(@D)/.tmp_$(@F:.o=.ver); \
fi; fi
endif endif
ifdef CONFIG_FTRACE_MCOUNT_RECORD ifdef CONFIG_FTRACE_MCOUNT_RECORD
# gcc 5 supports generating the mcount tables directly ifndef CC_USING_RECORD_MCOUNT
ifneq ($(call cc-option,-mrecord-mcount,y),y) # compiler will not generate __mcount_loc use recordmcount or recordmcount.pl
KBUILD_CFLAGS += -mrecord-mcount
else
# else do it all manually
ifdef BUILD_C_RECORDMCOUNT ifdef BUILD_C_RECORDMCOUNT
ifeq ("$(origin RECORDMCOUNT_WARN)", "command line") ifeq ("$(origin RECORDMCOUNT_WARN)", "command line")
RECORDMCOUNT_FLAGS = -w RECORDMCOUNT_FLAGS = -w
endif endif
# Due to recursion, we must skip empty.o. # Due to recursion, we must skip empty.o.
# The empty.o file is created in the make process in order to determine # The empty.o file is created in the make process in order to determine
# the target endianness and word size. It is made before all other C # the target endianness and word size. It is made before all other C
# files, including recordmcount. # files, including recordmcount.
sub_cmd_record_mcount = \ sub_cmd_record_mcount = \
if [ $(@) != "scripts/mod/empty.o" ]; then \ if [ $(@) != "scripts/mod/empty.o" ]; then \
$(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)"; \ $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)"; \
@@ -213,17 +212,59 @@ sub_cmd_record_mcount = \
recordmcount_source := $(srctree)/scripts/recordmcount.c \ recordmcount_source := $(srctree)/scripts/recordmcount.c \
$(srctree)/scripts/recordmcount.h $(srctree)/scripts/recordmcount.h
else else
sub_cmd_record_mcount = perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \ sub_cmd_record_mcount = perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \
"$(if $(CONFIG_SYS_BIG_ENDIAN),big,little)" \ "$(if $(CONFIG_SYS_BIG_ENDIAN),big,little)" \
"$(if $(CONFIG_64BIT),64,32)" \ "$(if $(CONFIG_64BIT),64,32)" \
"$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \ "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \
"$(LD) $(KBUILD_LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \ "$(LD) $(KBUILD_LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \
"$(if $(part-of-module),1,0)" "$(@)"; "$(if $(part-of-module),1,0)" "$(@)";
recordmcount_source := $(srctree)/scripts/recordmcount.pl recordmcount_source := $(srctree)/scripts/recordmcount.pl
endif # BUILD_C_RECORDMCOUNT
cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)), \
$(sub_cmd_record_mcount))
endif # CC_USING_RECORD_MCOUNT
endif # CONFIG_FTRACE_MCOUNT_RECORD
ifdef CONFIG_STACK_VALIDATION
ifneq ($(SKIP_STACK_VALIDATION),1)
__objtool_obj := $(objtree)/tools/objtool/objtool
objtool_args = $(if $(CONFIG_UNWINDER_ORC),orc generate,check)
objtool_args += $(if $(part-of-module), --module,)
ifndef CONFIG_FRAME_POINTER
objtool_args += --no-fp
endif endif
cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)), \ ifdef CONFIG_GCOV_KERNEL
$(sub_cmd_record_mcount)) objtool_args += --no-unreachable
endif # -record-mcount endif
ifdef CONFIG_RETPOLINE
objtool_args += --retpoline
endif
# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
# 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
# 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
cmd_objtool = $(if $(patsubst y%,, \
$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
$(__objtool_obj) $(objtool_args) $@)
objtool_obj = $(if $(patsubst y%,, \
$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
$(__objtool_obj))
endif # SKIP_STACK_VALIDATION
endif # CONFIG_STACK_VALIDATION
# Rebuild all objects when objtool changes, or is enabled/disabled.
objtool_dep = $(objtool_obj) \
$(wildcard include/config/orc/unwinder.h \
include/config/stack/validation.h)
ifdef CONFIG_TRIM_UNUSED_KSYMS
cmd_gen_ksymdeps = \
$(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd
endif endif
define rule_cc_o_c define rule_cc_o_c
@@ -243,17 +284,25 @@ define rule_as_o_S
$(call cmd,modversions_S) $(call cmd,modversions_S)
endef endef
# List module undefined symbols (or empty line if not enabled)
ifdef CONFIG_TRIM_UNUSED_KSYMS
cmd_undef_syms = $(NM) $@ | sed -n 's/^ *U //p' | xargs echo
else
cmd_undef_syms = echo
endif
# Built-in and composite module parts # Built-in and composite module parts
$(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
$(call cmd,force_checksrc) $(call cmd,force_checksrc)
$(call if_changed_rule,cc_o_c) $(call if_changed_rule,cc_o_c)
# Single-part modules are special since we need to mark them in $(MODVERDIR) # Single-part modules are special since we need to mark them in $(MODVERDIR)
$(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE $(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
$(call cmd,force_checksrc) $(call cmd,force_checksrc)
$(call if_changed_rule,cc_o_c) $(call if_changed_rule,cc_o_c)
@{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod) @{ echo $(@:.o=.ko); echo $@; \
$(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod)
quiet_cmd_cc_lst_c = MKLST $@ quiet_cmd_cc_lst_c = MKLST $@
cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \ cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \
@@ -268,29 +317,83 @@ $(obj)/%.lst: $(src)/%.c FORCE
modkern_aflags := $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL) modkern_aflags := $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL)
$(real-objs-m) : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) $(real-obj-m) : modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
$(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE) $(real-obj-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
quiet_cmd_as_s_S = CPP $(quiet_modtag) $@ # .S file exports must have their C prototypes defined in asm/asm-prototypes.h
cmd_as_s_S = $(CPP) $(a_flags) -o $@ $< # or a file that it includes, in order to get versioned symbols. We build a
# dummy C file that includes asm-prototypes and the EXPORT_SYMBOL lines from
# the .S file (with trailing ';'), and run genksyms on that, to extract vers.
#
# This is convoluted. The .S file must first be preprocessed to run guards and
# expand names, then the resulting exports must be constructed into plain
# EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preprocessed
# to make the genksyms input.
#
# These mirror gensymtypes_c and co above, keep them in synch.
cmd_gensymtypes_S = \
{ echo "\#include <linux/kernel.h>" ; \
echo "\#include <asm/asm-prototypes.h>" ; \
$(CPP) $(a_flags) $< | \
grep "\<___EXPORT_SYMBOL\>" | \
sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.*/EXPORT_SYMBOL(\1);/' ; } | \
$(CPP) -D__GENKSYMS__ $(c_flags) -xc - | \
scripts/genksyms/genksyms $(if $(1), -T $(2)) \
$(patsubst y,-R,$(CONFIG_MODULE_REL_CRCS)) \
$(if $(KBUILD_PRESERVE),-p) \
-r $(firstword $(wildcard $(2:.symtypes=.symref) /dev/null))
quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
cmd_cc_symtypes_S = \
$(call cmd_gensymtypes_S,true,$@) >/dev/null; \
test -s $@ || rm -f $@
$(obj)/%.symtypes : $(src)/%.S FORCE
$(call cmd,cc_symtypes_S)
quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<
$(obj)/%.s: $(src)/%.S FORCE $(obj)/%.s: $(src)/%.S FORCE
$(call if_changed_dep,as_s_S) $(call if_changed_dep,cpp_s_S)
quiet_cmd_as_o_S = AS $(quiet_modtag) $@ quiet_cmd_as_o_S = AS $(quiet_modtag) $@
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
$(obj)/%.o: $(src)/%.S FORCE ifdef CONFIG_MODVERSIONS
$(call if_changed_dep,as_o_S)
targets += $(real-objs-y) $(real-objs-m) $(lib-y) ASM_PROTOTYPES := $(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/asm-prototypes.h)
ifneq ($(ASM_PROTOTYPES),)
# versioning matches the C process described above, with difference that
# we parse asm-prototypes.h C header to get function definitions.
cmd_modversions_S = \
if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \
$(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
> $(@D)/.tmp_$(@F:.o=.ver); \
\
$(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \
-T $(@D)/.tmp_$(@F:.o=.ver); \
mv -f $(@D)/.tmp_$(@F) $@; \
rm -f $(@D)/.tmp_$(@F:.o=.ver); \
fi
endif
endif
$(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE
$(call if_changed_rule,as_o_S)
targets += $(filter-out $(subdir-obj-y), $(real-obj-y)) $(real-obj-m) $(lib-y)
targets += $(extra-y) $(MAKECMDGOALS) $(always) targets += $(extra-y) $(MAKECMDGOALS) $(always)
targets += $(real-dtb-y) $(lib-y) $(always-y) targets += $(real-dtb-y) $(lib-y) $(always-y)
# Linker scripts preprocessor (.lds.S -> .lds) # Linker scripts preprocessor (.lds.S -> .lds)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
quiet_cmd_cpp_lds_S = LDS $@ quiet_cmd_cpp_lds_S = LDS $@
cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -C -U$(ARCH) \ cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -U$(ARCH) \
-D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $< -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
$(obj)/%.lds: $(src)/%.lds.S FORCE $(obj)/%.lds: $(src)/%.lds.S FORCE
@@ -312,17 +415,17 @@ $(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/tools/asn1_compiler
$(sort $(subdir-obj-y)): $(subdir-ym) ; $(sort $(subdir-obj-y)): $(subdir-ym) ;
# #
# Rule to compile a set of .o files into one .o file # Rule to compile a set of .o files into one .a file (without symbol table)
# #
ifdef builtin-target ifdef builtin-target
quiet_cmd_link_o_target = AR $@
# If the list of objects to link is empty, just create an empty built-in.o
cmd_link_o_target = $(if $(strip $(obj-y)),\
rm -f $@; $(AR) cDPrsT $@ $(filter $(obj-y), $^), \
rm -f $@; $(AR) cDPrsT$(KBUILD_ARFLAGS) $@)
$(builtin-target): $(obj-y) FORCE quiet_cmd_ar_builtin = AR $@
$(call if_changed,link_o_target) # Modified for U-Boot, we create thin archives directly, instead of using the kernel script
# Check f49821ee32b76 and 6358d6e8b98 in kernel
cmd_ar_builtin = rm -f $@; $(AR) rcTP$(KBUILD_ARFLAGS) $@ $(real-prereqs)
$(builtin-target): $(real-obj-y) FORCE
$(call if_changed,ar_builtin)
targets += $(builtin-target) targets += $(builtin-target)
endif # builtin-target endif # builtin-target
@@ -341,7 +444,7 @@ $(modorder-target): $(subdir-ym) FORCE
$(Q)(cat /dev/null; $(modorder-cmds)) > $@ $(Q)(cat /dev/null; $(modorder-cmds)) > $@
# #
# Rule to compile a set of .o files into one .a file # Rule to compile a set of .o files into one .a file (with symbol table)
# #
ifdef lib-target ifdef lib-target
@@ -349,25 +452,40 @@ $(lib-target): $(lib-y) FORCE
$(call if_changed,ar) $(call if_changed,ar)
targets += $(lib-target) 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 endif
quiet_cmd_link_multi-y = AR $@ # NOTE:
cmd_link_multi-y = rm -f $@; $(AR) cDPrsT$(KBUILD_ARFLAGS) $@ $(filter %.o,$^) # Do not replace $(filter %.o,^) with $(real-prereqs). When a single object
# module is turned into a multi object module, $^ will contain header file
quiet_cmd_link_multi-m = AR [M] $@ # dependencies recorded in the .*.cmd file.
cmd_link_multi-m = $(cmd_link_multi-y) quiet_cmd_link_multi-m = LD [M] $@
cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(filter %.o,$^) $(cmd_secanalysis)
$(multi-used-y): FORCE
$(call if_changed,link_multi-y)
$(call multi_depend, $(multi-used-y), .o, -objs -y)
$(multi-used-m): FORCE $(multi-used-m): FORCE
$(call if_changed,link_multi-m) $(call if_changed,link_multi-m)
@{ echo $(@:.o=.ko); echo $(filter %.o,$^); } > $(MODVERDIR)/$(@F:.o=.mod) @{ echo $(@:.o=.ko); echo $(filter %.o,$^); \
$(call multi_depend, $(multi-used-m), .o, -objs -y) $(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod)
$(call multi_depend, $(multi-used-m), .o, -objs -y -m)
targets += $(multi-used-y) $(multi-used-m)
targets += $(multi-used-m)
targets := $(filter-out $(PHONY), $(targets))
# Add intermediate targets: # Add intermediate targets:
# When building objects with specific suffix patterns, add intermediate # When building objects with specific suffix patterns, add intermediate
@@ -375,9 +493,13 @@ targets += $(multi-used-y) $(multi-used-m)
intermediate_targets = $(foreach sfx, $(2), \ intermediate_targets = $(foreach sfx, $(2), \
$(patsubst %$(strip $(1)),%$(sfx), \ $(patsubst %$(strip $(1)),%$(sfx), \
$(filter %$(strip $(1)), $(targets)))) $(filter %$(strip $(1)), $(targets))))
# %.asn1.o <- %.asn1.[ch] <- %.asn1
# %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
# %.lex.o <- %.lex.c <- %.l # %.lex.o <- %.lex.c <- %.l
# %.tab.o <- %.tab.[ch] <- %.y # %.tab.o <- %.tab.[ch] <- %.y
targets += $(call intermediate_targets, .lex.o, .lex.c) \ targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \
$(call intermediate_targets, .dtb.o, .dtb.S .dtb) \
$(call intermediate_targets, .lex.o, .lex.c) \
$(call intermediate_targets, .tab.o, .tab.c .tab.h) $(call intermediate_targets, .tab.o, .tab.c .tab.h)
# Descending # Descending
@@ -385,7 +507,7 @@ targets += $(call intermediate_targets, .lex.o, .lex.c) \
PHONY += $(subdir-ym) PHONY += $(subdir-ym)
$(subdir-ym): $(subdir-ym):
$(Q)$(MAKE) $(build)=$@ $(Q)$(MAKE) $(build)=$@ need-builtin=$(if $(findstring $@,$(subdir-obj-y)),1)
# Add FORCE to the prequisites of a target to force it to be always rebuilt. # Add FORCE to the prequisites of a target to force it to be always rebuilt.
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------

View File

@@ -0,0 +1,59 @@
# SPDX-License-Identifier: GPL-2.0
gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) += cyc_complexity_plugin.so
gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += latent_entropy_plugin.so
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) \
+= -DLATENT_ENTROPY_PLUGIN
ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY
DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable
endif
export DISABLE_LATENT_ENTROPY_PLUGIN
gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV) += sancov_plugin.so
gcc-plugin-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) += structleak_plugin.so
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_VERBOSE) \
+= -fplugin-arg-structleak_plugin-verbose
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF) \
+= -fplugin-arg-structleak_plugin-byref
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL) \
+= -fplugin-arg-structleak_plugin-byref-all
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) \
+= -DSTRUCTLEAK_PLUGIN
gcc-plugin-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += randomize_layout_plugin.so
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) \
+= -DRANDSTRUCT_PLUGIN
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT_PERFORMANCE) \
+= -fplugin-arg-randomize_layout_plugin-performance-mode
gcc-plugin-$(CONFIG_GCC_PLUGIN_STACKLEAK) += stackleak_plugin.so
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \
+= -DSTACKLEAK_PLUGIN
gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STACKLEAK) \
+= -fplugin-arg-stackleak_plugin-track-min-size=$(CONFIG_STACKLEAK_TRACK_MIN_SIZE)
ifdef CONFIG_GCC_PLUGIN_STACKLEAK
DISABLE_STACKLEAK_PLUGIN += -fplugin-arg-stackleak_plugin-disable
endif
export DISABLE_STACKLEAK_PLUGIN
gcc-plugin-$(CONFIG_GCC_PLUGIN_ARM_SSP_PER_TASK) += arm_ssp_per_task_plugin.so
ifdef CONFIG_GCC_PLUGIN_ARM_SSP_PER_TASK
DISABLE_ARM_SSP_PER_TASK_PLUGIN += -fplugin-arg-arm_ssp_per_task_plugin-disable
endif
export DISABLE_ARM_SSP_PER_TASK_PLUGIN
# All the plugin CFLAGS are collected here in case a build target needs to
# filter them out of the KBUILD_CFLAGS.
GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y))
# The sancov_plugin.so is included via CFLAGS_KCOV, so it is removed here.
GCC_PLUGINS_CFLAGS := $(filter-out %/sancov_plugin.so, $(GCC_PLUGINS_CFLAGS))
export GCC_PLUGINS_CFLAGS
# Add the flags to the build!
KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
# All enabled GCC plugins are collected here for building below.
GCC_PLUGIN := $(gcc-plugin-y)
export GCC_PLUGIN

9
scripts/Makefile.kcov Normal file
View File

@@ -0,0 +1,9 @@
ifdef CONFIG_KCOV
kcov-flags-$(CONFIG_CC_HAS_SANCOV_TRACE_PC) += -fsanitize-coverage=trace-pc
kcov-flags-$(CONFIG_KCOV_ENABLE_COMPARISONS) += -fsanitize-coverage=trace-cmp
kcov-flags-$(CONFIG_GCC_PLUGIN_SANCOV) += -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so
export CFLAGS_KCOV := $(kcov-flags-y)
endif

View File

@@ -5,46 +5,40 @@ ccflags-y += $(EXTRA_CFLAGS)
cppflags-y += $(EXTRA_CPPFLAGS) cppflags-y += $(EXTRA_CPPFLAGS)
ldflags-y += $(EXTRA_LDFLAGS) ldflags-y += $(EXTRA_LDFLAGS)
# # flags that take effect in current and sub directories
# flags that take effect in sub directories KBUILD_AFLAGS += $(subdir-asflags-y)
export KBUILD_SUBDIR_ASFLAGS := $(KBUILD_SUBDIR_ASFLAGS) $(subdir-asflags-y) KBUILD_CFLAGS += $(subdir-ccflags-y)
export KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y)
# Figure out what we need to build from the various variables # Figure out what we need to build from the various variables
# =========================================================================== # ===========================================================================
# When an object is listed to be built compiled-in and modular, # When an object is listed to be built compiled-in and modular,
# only build the compiled-in version # only build the compiled-in version
obj-m := $(filter-out $(obj-y),$(obj-m)) obj-m := $(filter-out $(obj-y),$(obj-m))
# Libraries are always collected in one lib file. # Libraries are always collected in one lib file.
# Filter out objects already built-in # Filter out objects already built-in
lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m))) lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
# Handle objects in subdirs
# ---------------------------------------------------------------------------
# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.o
# and add the directory to the list of dirs to descend into: $(subdir-y)
# o if we encounter foo/ in $(obj-m), remove it from $(obj-m)
# and add the directory to the list of dirs to descend into: $(subdir-m)
# Determine modorder. # Determine modorder.
# Unfortunately, we don't have information about ordering between -y # Unfortunately, we don't have information about ordering between -y
# and -m subdirs. Just put -y's first. # and -m subdirs. Just put -y's first.
modorder := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko)) modorder := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko))
# Handle objects in subdirs
# ---------------------------------------------------------------------------
# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.a
# and add the directory to the list of dirs to descend into: $(subdir-y)
# o if we encounter foo/ in $(obj-m), remove it from $(obj-m)
# and add the directory to the list of dirs to descend into: $(subdir-m)
__subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y))) __subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
subdir-y += $(__subdir-y) subdir-y += $(__subdir-y)
__subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m))) __subdir-m := $(patsubst %/,%,$(filter %/, $(obj-m)))
subdir-m += $(__subdir-m) subdir-m += $(__subdir-m)
obj-y := $(patsubst %/, %/built-in.o, $(obj-y)) obj-y := $(patsubst %/, %/built-in.a, $(obj-y))
obj-m := $(filter-out %/, $(obj-m)) obj-m := $(filter-out %/, $(obj-m))
# Subdirectories we need to descend into # Subdirectories we need to descend into
subdir-ym := $(sort $(subdir-y) $(subdir-m)) subdir-ym := $(sort $(subdir-y) $(subdir-m))
# Expand $(foo-objs) $(foo-y) etc. by replacing their individuals # Expand $(foo-objs) $(foo-y) etc. by replacing their individuals
@@ -54,9 +48,9 @@ multi-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -),
# List primitive targets that are compiled from source files # List primitive targets that are compiled from source files
real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m)) real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m))
# if $(foo-objs) exists, foo.o is a composite object # if $(foo-objs), $(foo-y), or $(foo-m) exists, foo.o is a composite object
multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m)))) multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m)))) multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))), $(m))))
multi-used := $(multi-used-y) $(multi-used-m) multi-used := $(multi-used-y) $(multi-used-m)
single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m))) single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m)))
@@ -74,11 +68,22 @@ base-dtb-y := $(foreach m, $(multi-dtb-y), $(firstword $(call suffix-search, $m,
# $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to
# tell kbuild to descend # tell kbuild to descend
subdir-obj-y := $(filter %/built-in.o, $(obj-y)) subdir-obj-y := $(filter %/built-in.a, $(obj-y))
# Replace multi-part objects by their individual parts, look at local dir only # Replace multi-part objects by their individual parts,
real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y) # including built-in.a from subdirectories
real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) real-obj-y := $(foreach m, $(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m)))
real-obj-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m)))
# DTB
# If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
extra-y += $(dtb-y)
extra-$(CONFIG_OF_ALL_DTBS) += $(dtb-)
ifneq ($(CHECK_DTBS),)
extra-y += $(patsubst %.dtb,%.dt.yaml, $(dtb-y))
extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-))
endif
# Add subdir path # Add subdir path
@@ -91,8 +96,8 @@ obj-y := $(addprefix $(obj)/,$(obj-y))
obj-m := $(addprefix $(obj)/,$(obj-m)) obj-m := $(addprefix $(obj)/,$(obj-m))
lib-y := $(addprefix $(obj)/,$(lib-y)) lib-y := $(addprefix $(obj)/,$(lib-y))
subdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y)) subdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y))
real-objs-y := $(addprefix $(obj)/,$(real-objs-y)) real-obj-y := $(addprefix $(obj)/,$(real-obj-y))
real-objs-m := $(addprefix $(obj)/,$(real-objs-m)) real-obj-m := $(addprefix $(obj)/,$(real-obj-m))
single-used-m := $(addprefix $(obj)/,$(single-used-m)) single-used-m := $(addprefix $(obj)/,$(single-used-m))
multi-used-y := $(addprefix $(obj)/,$(multi-used-y)) multi-used-y := $(addprefix $(obj)/,$(multi-used-y))
multi-used-m := $(addprefix $(obj)/,$(multi-used-m)) multi-used-m := $(addprefix $(obj)/,$(multi-used-m))
@@ -102,22 +107,25 @@ multi-dtb-y := $(addprefix $(obj)/,$(multi-dtb-y))
real-dtb-y := $(addprefix $(obj)/,$(real-dtb-y)) real-dtb-y := $(addprefix $(obj)/,$(real-dtb-y))
subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
# Finds the multi-part object the current object will be linked into.
# If the object belongs to two or more multi-part objects, all of them are
# concatenated with a colon separator.
modname-multi = $(subst $(space),:,$(sort $(foreach m,$(multi-used),\
$(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=)))))
modname = $(if $(modname-multi),$(modname-multi),$(basetarget))
# These flags are needed for modversions and compiling, so we define them here # These flags are needed for modversions and compiling, so we define them here
# already # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
# $(modname_flags) #defines KBUILD_MODNAME as the name of the module it will
# end up in (or would, if it gets compiled in) # end up in (or would, if it gets compiled in)
# Note: Files that end up in two or more modules are compiled without the
# KBUILD_MODNAME definition. The reason is that any made-up name would
# differ in different configs.
name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote) name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote)
basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget)) basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
modname_flags = $(if $(filter 1,$(words $(modname))),\ modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname))
-DKBUILD_MODNAME=$(call name-fix,$(modname)))
orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \ orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
$(ccflags-y) $(CFLAGS_$(basetarget).o) $(ccflags-y) $(CFLAGS_$(basetarget).o)
_c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags)) _c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
orig_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(KBUILD_SUBDIR_ASFLAGS) \ orig_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) \
$(asflags-y) $(AFLAGS_$(basetarget).o) $(asflags-y) $(AFLAGS_$(basetarget).o)
_a_flags = $(filter-out $(AFLAGS_REMOVE_$(basetarget).o), $(orig_a_flags)) _a_flags = $(filter-out $(AFLAGS_REMOVE_$(basetarget).o), $(orig_a_flags))
_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F)) _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
@@ -140,7 +148,19 @@ endif
ifeq ($(CONFIG_KASAN),y) ifeq ($(CONFIG_KASAN),y)
_c_flags += $(if $(patsubst n%,, \ _c_flags += $(if $(patsubst n%,, \
$(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \ $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
$(CFLAGS_KASAN)) $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
endif
ifeq ($(CONFIG_UBSAN),y)
_c_flags += $(if $(patsubst n%,, \
$(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \
$(CFLAGS_UBSAN))
endif
ifeq ($(CONFIG_KCOV),y)
_c_flags += $(if $(patsubst n%,, \
$(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
$(CFLAGS_KCOV))
endif endif
__c_flags = $(_c_flags) __c_flags = $(_c_flags)
@@ -161,7 +181,6 @@ __a_flags = $(call flags,_a_flags)
__cpp_flags = $(call flags,_cpp_flags) __cpp_flags = $(call flags,_cpp_flags)
endif endif
endif endif
# Modified for U-Boot: LINUXINCLUDE -> UBOOTINCLUDE # Modified for U-Boot: LINUXINCLUDE -> UBOOTINCLUDE
c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(UBOOTINCLUDE) \ c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(UBOOTINCLUDE) \
$(__c_flags) $(modkern_cflags) \ $(__c_flags) $(modkern_cflags) \
@@ -222,7 +241,6 @@ dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \
# Finds the multi-part object the current object will be linked into # Finds the multi-part object the current object will be linked into
modname-multi = $(sort $(foreach m,$(multi-used),\ modname-multi = $(sort $(foreach m,$(multi-used),\
$(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=)))) $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))
# Useful for describing the dependency of composite objects # Useful for describing the dependency of composite objects
# Usage: # Usage:
# $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add) # $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
@@ -278,12 +296,13 @@ $(obj)/%: $(src)/%_shipped
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
quiet_cmd_ld = LD $@ quiet_cmd_ld = LD $@
cmd_ld = $(LD) $(ld_flags) $(filter-out FORCE,$^) -o $@ cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@
# Archive # Archive
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
quiet_cmd_ar = AR $@ quiet_cmd_ar = AR $@
cmd_ar = rm -f $@; $(AR) rcsTP$(KBUILD_ARFLAGS) $@ $(real-prereqs) cmd_ar = rm -f $@; $(AR) rcsTP$(KBUILD_ARFLAGS) $@ $(real-prereqs)
# Objcopy # Objcopy
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@@ -295,10 +314,11 @@ cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
quiet_cmd_gzip = GZIP $@ quiet_cmd_gzip = GZIP $@
cmd_gzip = cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@ cmd_gzip = cat $(real-prereqs) | gzip -n -f -9 > $@
# DTC # DTC
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
DTC ?= $(objtree)/scripts/dtc/dtc
# Disable noisy checks by default # Disable noisy checks by default
ifeq ($(findstring 1,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),) ifeq ($(findstring 1,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),)
@@ -309,7 +329,6 @@ DTC_FLAGS += -Wno-unit_address_vs_reg \
-Wno-graph_child_address \ -Wno-graph_child_address \
-Wno-simple_bus_reg \ -Wno-simple_bus_reg \
-Wno-unique_unit_address \ -Wno-unique_unit_address \
-Wno-simple_bus_reg \
-Wno-pci_device_reg -Wno-pci_device_reg
# U-Boot specific disables # U-Boot specific disables
@@ -567,20 +586,20 @@ printf "%08x\n" $$dec_size | \
) )
quiet_cmd_bzip2 = BZIP2 $@ quiet_cmd_bzip2 = BZIP2 $@
cmd_bzip2 = { cat $(real-prereqs) | bzip2 -9 && $(size_append); } > $@ cmd_bzip2 = { cat $(real-prereqs) | bzip2 -9 && $(size_append); } > $@
# Lzma # Lzma
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
quiet_cmd_lzma = LZMA $@ quiet_cmd_lzma = LZMA $@
cmd_lzma = { cat $(real-prereqs) | lzma -9 && $(size_append); } > $@ cmd_lzma = { cat $(real-prereqs) | lzma -9 && $(size_append); } > $@
quiet_cmd_lzo = LZO $@ quiet_cmd_lzo = LZO $@
cmd_lzo = { cat $(real-prereqs) | lzop -9 && $(size_append); } > $@ cmd_lzo = { cat $(real-prereqs) | lzop -9 && $(size_append); } > $@
quiet_cmd_lz4 = LZ4 $@ quiet_cmd_lz4 = LZ4 $@
cmd_lz4 = { cat $(real-prereqs) | lz4c -l -c1 stdin stdout && \ cmd_lz4 = { cat $(real-prereqs) | lz4c -l -c1 stdin stdout && \
$(size_append); } > $@ $(size_append); } > $@
# U-Boot mkimage # U-Boot mkimage
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@@ -702,12 +721,15 @@ quiet_cmd_fdt_rm_props = FDTGREP $@
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Default sed regexp - multiline due to syntax constraints # Default sed regexp - multiline due to syntax constraints
#
# Use [:space:] because LLVM's integrated assembler inserts <tab> around
# the .ascii directive whereas GCC keeps the <space> as-is.
define sed-offsets define sed-offsets
"s:[[:space:]]*\.ascii[[:space:]]*\"\(.*\)\":\1:; \ 's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
/^->/{s:->#\(.*\):/* \1 */:; \ /^->/{s:->#\(.*\):/* \1 */:; \
s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \ s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \ s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
s:->::; p;}" s:->::; p;}'
endef endef
# Use filechk to avoid rebuilds when a header changes, but the resulting file # Use filechk to avoid rebuilds when a header changes, but the resulting file

View File

@@ -135,7 +135,7 @@ head-y := $(addprefix $(obj)/,$(head-y))
libs-y := $(addprefix $(obj)/,$(libs-y)) libs-y := $(addprefix $(obj)/,$(libs-y))
u-boot-spl-dirs := $(patsubst %/,%,$(filter %/, $(libs-y))) u-boot-spl-dirs := $(patsubst %/,%,$(filter %/, $(libs-y)))
libs-y := $(patsubst %/, %/built-in.o, $(libs-y)) libs-y := $(patsubst %/, %/built-in.a, $(libs-y))
# Add GCC lib # Add GCC lib
ifeq ($(CONFIG_USE_PRIVATE_LIBGCC),y) ifeq ($(CONFIG_USE_PRIVATE_LIBGCC),y)

View File

@@ -627,7 +627,7 @@ class BuilderThread(threading.Thread):
# Extract the environment from U-Boot and dump it out # Extract the environment from U-Boot and dump it out
cmd = [f'{self.toolchain.cross}objcopy', '-O', 'binary', cmd = [f'{self.toolchain.cross}objcopy', '-O', 'binary',
'-j', '.rodata.default_environment', '-j', '.rodata.default_environment',
'env/built-in.o', 'uboot.env'] 'env/built-in.a', 'uboot.env']
command.run_one(*cmd, capture=True, capture_stderr=True, command.run_one(*cmd, capture=True, capture_stderr=True,
cwd=result.out_dir, raise_on_error=False, env=env) cwd=result.out_dir, raise_on_error=False, env=env)
if not work_in_output: if not work_in_output: