From e68d63dda97b76cd32f4f079597a7aa7084671de Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 9 Nov 2022 19:14:39 -0700 Subject: [PATCH 1/5] image: Correct strncpy() warning with image_set_name() gcc 12 seems to warn on strncpy() as a matter of course. Rewrite the code a different way to do the same thing, to avoid the warning. Signed-off-by: Simon Glass Signed-off-by: Joel Stanley --- include/image.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/image.h b/include/image.h index 937c7eee8ffb..0e58ffb139fe 100644 --- a/include/image.h +++ b/include/image.h @@ -821,7 +821,13 @@ image_set_hdr_b(comp) /* image_set_comp */ static inline void image_set_name(image_header_t *hdr, const char *name) { - strncpy(image_get_name(hdr), name, IH_NMLEN); + /* + * This is equivalent to: strncpy(image_get_name(hdr), name, IH_NMLEN); + * + * Use the tortured code below to avoid a warning with gcc 12. We do not + * want to include a nul terminator if the name is of length IH_NMLEN + */ + memcpy(image_get_name(hdr), name, strnlen(name, IH_NMLEN)); } int image_check_hcrc(const image_header_t *hdr); From 3ac6214e82560bee0ab31e9556e16fbbc6382ffd Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Wed, 7 Dec 2022 15:49:43 -0500 Subject: [PATCH 2/5] Makefile: Silence binutils 2.39 linker warnings This is the upstream equivalent of these two fixes: 57450d8661b3 ("Makefile: Link with -z noexectack") 1e1c51f8ace8 ("Makefile: link with --no-warn-rwx-segments") Signed-off-by: Joel Stanley --- Makefile | 6 ++++++ scripts/Makefile.build | 2 +- scripts/Makefile.lib | 6 ++++-- scripts/Makefile.spl | 6 ++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index e1fa881b2aa4..0e06827b1ca6 100644 --- a/Makefile +++ b/Makefile @@ -878,6 +878,12 @@ LDFLAGS_u-boot += $(LDFLAGS_FINAL) # Avoid 'Not enough room for program headers' error on binutils 2.28 onwards. LDFLAGS_u-boot += $(call ld-option, --no-dynamic-linker) +# Avoid 'warning: u-boot-spl has a LOAD segment with RWX permissions' +LDFLAGS_u-boot += $(call ld-option,--no-warn-rwx-segments) + +# Avoid 'missing .note.GNU-stack section implies executable stack' +LDFLAGS_u-boot += -z noexecstack + ifeq ($(CONFIG_ARC)$(CONFIG_NIOS2)$(CONFIG_X86)$(CONFIG_XTENSA),) LDFLAGS_u-boot += -Ttext $(CONFIG_SYS_TEXT_BASE) endif diff --git a/scripts/Makefile.build b/scripts/Makefile.build index f7a041296d3d..71d66aca25c0 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -347,7 +347,7 @@ ifdef builtin-target quiet_cmd_link_o_target = LD $@ # If the list of objects to link is empty, just create an empty built-in.o cmd_link_o_target = $(if $(strip $(obj-y)),\ - $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^) \ + $(LD) $(ld_flags) -z noexecstack -r -o $@ $(filter $(obj-y), $^) \ $(cmd_secanalysis),\ rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 70de9bb13a66..60c3706ea2cb 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -377,9 +377,11 @@ cmd_efi_objcopy = $(OBJCOPY) -j .header -j .text -j .sdata -j .data -j \ $(obj)/%.efi: $(obj)/%_efi.so $(call cmd,efi_objcopy) +KBUILD_EFILDFLAGS = -nostdlib -zexecstack -znocombreloc -znorelro +KBUILD_EFILDFLAGS += $(call ld-option,--no-warn-rwx-segments) quiet_cmd_efi_ld = LD $@ -cmd_efi_ld = $(LD) -nostdlib -znocombreloc -T $(EFI_LDS_PATH) -shared \ - -Bsymbolic -s $^ -o $@ +cmd_efi_ld = $(LD) $(KBUILD_EFILDFLAGS) -T $(EFI_LDS_PATH) \ + -shared -Bsymbolic -s $^ -o $@ EFI_LDS_PATH = $(srctree)/arch/$(ARCH)/lib/$(EFI_LDS) diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl index dfa17f52552c..5f091c8082c0 100644 --- a/scripts/Makefile.spl +++ b/scripts/Makefile.spl @@ -330,6 +330,12 @@ LDFLAGS_$(SPL_BIN) += -T u-boot-spl.lds $(LDFLAGS_FINAL) # Avoid 'Not enough room for program headers' error on binutils 2.28 onwards. LDFLAGS_$(SPL_BIN) += $(call ld-option, --no-dynamic-linker) +# Avoid 'warning: u-boot-spl has a LOAD segment with RWX permissions' +LDFLAGS_$(SPL_BIN) += $(call ld-option,--no-warn-rwx-segments) + +# Avoid 'missing .note.GNU-stack section implies executable stack' +LDFLAGS_$(SPL_BIN) += -z noexecstack + # Pick the best-match (i.e. SPL_TEXT_BASE for SPL, TPL_TEXT_BASE for TPL) ifneq ($(CONFIG_$(SPL_TPL_)TEXT_BASE),) LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_$(SPL_TPL_)TEXT_BASE) From 321b1e653951425b6155298be74243e98ec14ffe Mon Sep 17 00:00:00 2001 From: Joel Stanley Date: Thu, 2 Mar 2023 11:13:21 +1030 Subject: [PATCH 3/5] configs: ast2600: Use stringify This avoids the warning about mutliple STR defines: ../env/mmc.c:22: warning: "STR" redefined 22 | #define STR(X) __STR(X) Signed-off-by: Joel Stanley --- include/configs/evb_ast2600_spl.h | 5 +---- include/configs/evb_ast2600_spl_emmc.h | 5 +---- include/configs/evb_ast2600a1_spl.h | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/include/configs/evb_ast2600_spl.h b/include/configs/evb_ast2600_spl.h index 23dd7ecd7fa1..ae3e628d55c3 100644 --- a/include/configs/evb_ast2600_spl.h +++ b/include/configs/evb_ast2600_spl.h @@ -26,12 +26,9 @@ #define CONFIG_SPL_LOAD_FIT_ADDRESS 0x00010000 /* Extra ENV for Boot Command */ -#define STR_HELPER(n) #n -#define STR(n) STR_HELPER(n) - #undef CONFIG_EXTRA_ENV_SETTINGS #define CONFIG_EXTRA_ENV_SETTINGS \ - "loadaddr=" STR(CONFIG_SYS_LOAD_ADDR) "\0" \ + "loadaddr=" __stringify(CONFIG_SYS_LOAD_ADDR) "\0" \ "bootspi=fdt addr 20100000 && fdt header get fitsize totalsize && cp.b 20100000 ${loadaddr} ${fitsize} && bootm; echo Error loading kernel FIT image\0" \ "verify=yes\0" \ "" diff --git a/include/configs/evb_ast2600_spl_emmc.h b/include/configs/evb_ast2600_spl_emmc.h index f627c37a16c2..c5f79c3da443 100644 --- a/include/configs/evb_ast2600_spl_emmc.h +++ b/include/configs/evb_ast2600_spl_emmc.h @@ -25,12 +25,9 @@ #define CONFIG_SPL_BSS_MAX_SIZE 0x00100000 /* Extra ENV for Boot Command */ -#define STR_HELPER(n) #n -#define STR(n) STR_HELPER(n) - #undef CONFIG_EXTRA_ENV_SETTINGS #define CONFIG_EXTRA_ENV_SETTINGS \ - "loadaddr=" STR(CONFIG_SYS_LOAD_ADDR) "\0" \ + "loadaddr=" __stringify(CONFIG_SYS_LOAD_ADDR) "\0" \ "bootside=a\0" \ "rootfs=rofs-a\0" \ "setmmcargs=setenv bootargs ${bootargs} rootwait root=PARTLABEL=${rootfs}\0" \ diff --git a/include/configs/evb_ast2600a1_spl.h b/include/configs/evb_ast2600a1_spl.h index 006cc4345b6c..34d6f4f9339f 100644 --- a/include/configs/evb_ast2600a1_spl.h +++ b/include/configs/evb_ast2600a1_spl.h @@ -26,12 +26,9 @@ #define CONFIG_SPL_LOAD_FIT_ADDRESS 0x00010000 /* Extra ENV for Boot Command */ -#define STR_HELPER(n) #n -#define STR(n) STR_HELPER(n) - #undef CONFIG_EXTRA_ENV_SETTINGS #define CONFIG_EXTRA_ENV_SETTINGS \ - "loadaddr=" STR(CONFIG_SYS_LOAD_ADDR) "\0" \ + "loadaddr=" __stringify(CONFIG_SYS_LOAD_ADDR) "\0" \ "bootspi=fdt addr 20100000 && fdt header get fitsize totalsize && cp.b 20100000 ${loadaddr} ${fitsize} && bootm; echo Error loading kernel FIT image\0" \ "verify=yes\0" \ "" From 34ddab1373a61f12c5aeddb26a0e5becc7f323d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Mon, 2 Aug 2021 15:18:31 +0200 Subject: [PATCH 4/5] version: Move version_string[] from version.h to version_string.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More C files do not use compile time timestamp macros and do not have to be recompiled every time when SOURCE_DATE_EPOCH changes. This patch moves version_string[] from version.h to version_string.h and updates other C files which only needs version_string[] string to include version_string.h instead of version.h. After applying this patch these files are not recompiled every time when SOURCE_DATE_EPOCH changes. Signed-off-by: Pali Rohár Reviewed-by: Tom Rini Signed-off-by: Joel Stanley --- cmd/version.c | 1 + common/main.c | 2 +- drivers/video/cfb_console.c | 3 +-- include/version.h | 3 --- include/version_string.h | 8 ++++++++ lib/display_options.c | 2 +- test/print_ut.c | 2 +- 7 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 include/version_string.h diff --git a/cmd/version.c b/cmd/version.c index b2fffe997724..38902d8f1089 100644 --- a/cmd/version.c +++ b/cmd/version.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #ifdef CONFIG_SYS_COREBOOT #include diff --git a/common/main.c b/common/main.c index 07b34bf2b05d..ea41b8d28151 100644 --- a/common/main.c +++ b/common/main.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include /* * Board-specific Platform code can reimplement show_boot_progress () if needed diff --git a/drivers/video/cfb_console.c b/drivers/video/cfb_console.c index 636c3e8c184d..275d3de5e9ee 100644 --- a/drivers/video/cfb_console.c +++ b/drivers/video/cfb_console.c @@ -66,7 +66,7 @@ #include #include -#include +#include #include #include #include @@ -116,7 +116,6 @@ * Console device */ -#include #include #include #include diff --git a/include/version.h b/include/version.h index 2d24451569d5..0a3b29adb89a 100644 --- a/include/version.h +++ b/include/version.h @@ -16,7 +16,4 @@ #define U_BOOT_VERSION_STRING U_BOOT_VERSION " (" U_BOOT_DATE " - " \ U_BOOT_TIME " " U_BOOT_TZ ")" CONFIG_IDENT_STRING -#ifndef __ASSEMBLY__ -extern const char version_string[]; -#endif /* __ASSEMBLY__ */ #endif /* __VERSION_H__ */ diff --git a/include/version_string.h b/include/version_string.h new file mode 100644 index 000000000000..a89a6e43705e --- /dev/null +++ b/include/version_string.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef __VERSION_STRING_H__ +#define __VERSION_STRING_H__ + +extern const char version_string[]; + +#endif /* __VERSION_STRING_H__ */ diff --git a/lib/display_options.c b/lib/display_options.c index af1802ef992f..0be9377a10d1 100644 --- a/lib/display_options.c +++ b/lib/display_options.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include diff --git a/test/print_ut.c b/test/print_ut.c index f0f1d6010a16..cebd8b85e1a7 100644 --- a/test/print_ut.c +++ b/test/print_ut.c @@ -10,7 +10,7 @@ #include #endif #include -#include +#include #define FAKE_BUILD_TAG "jenkins-u-boot-denx_uboot_dm-master-build-aarch64" \ "and a lot more text to come" From 4462a9adeca824abefa4df8e5963796eedca2073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Mon, 2 Aug 2021 15:18:38 +0200 Subject: [PATCH 5/5] Remove including timestamp.h in version.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Header file version.h does not use anything from timestamp.h. Including of timestamp.h has side effect which cause recompiling object file at every make run because timestamp.h changes at every run. So remove timestamp.h from version.h and include timestamp.h in files which needs it. This change reduce recompilation time of final U-Boot binary when U-Boot source files were not changed as less source files needs to be recompiled. Signed-off-by: Pali Rohár Reviewed-by: Simon Glass Reviewed-by: Tom Rini [trini: Add in lib/acpi/acpi_table.c and test/dm/acpi.c, rework a few others] Signed-off-by: Tom Rini Signed-off-by: Joel Stanley --- board/work-microwave/work_92105/work_92105_display.c | 1 + cmd/version.c | 1 + common/spl/spl.c | 3 +++ include/version.h | 2 -- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/board/work-microwave/work_92105/work_92105_display.c b/board/work-microwave/work_92105/work_92105_display.c index ffa0fcfa874d..9605ee1877f9 100644 --- a/board/work-microwave/work_92105/work_92105_display.c +++ b/board/work-microwave/work_92105/work_92105_display.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include diff --git a/cmd/version.c b/cmd/version.c index 38902d8f1089..ec37c3da3194 100644 --- a/cmd/version.c +++ b/cmd/version.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include diff --git a/common/spl/spl.c b/common/spl/spl.c index 927e07277846..9fb7d3e2cae4 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -17,6 +17,9 @@ #include #include #include +#if CONFIG_IS_ENABLED(BANNER_PRINT) +#include +#endif #include #include #include diff --git a/include/version.h b/include/version.h index 0a3b29adb89a..66845ef0c239 100644 --- a/include/version.h +++ b/include/version.h @@ -7,8 +7,6 @@ #ifndef __VERSION_H__ #define __VERSION_H__ -#include - #ifndef DO_DEPS_ONLY #include "generated/version_autogenerated.h" #endif