From fb99f173c564bb454b6f49994933b8b1756ba28b Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Wed, 1 Jun 2022 20:37:10 +0530 Subject: [PATCH 01/21] util: add a missing header Add sysmacros.h to make gcc happy. Signed-off-by: Ani Sinha --- util/getroot.c | 1 + util/raid.c | 1 + 2 files changed, 2 insertions(+) diff --git a/util/getroot.c b/util/getroot.c index e103fb6c..fc358df4 100644 --- a/util/getroot.c +++ b/util/getroot.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include diff --git a/util/raid.c b/util/raid.c index f73ae76c..880ae2c5 100644 --- a/util/raid.c +++ b/util/raid.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include From dee9f23d513bba941c8f21e00d73ce459bd73331 Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Wed, 1 Jun 2022 20:38:58 +0530 Subject: [PATCH 02/21] build: Fix GRUB i386-pc build with Ubuntu gcc See upstream commit: 6643507ce30f77500 ("build: Fix GRUB i386-pc build with Ubuntu gcc") This change is a port of the upstream commit to this version of grub. With recent versions of gcc on Ubuntu a very large lzma_decompress.img file is output. (e.g. 134479600 bytes instead of 2864.) This causes grub-mkimage to fail with: "error: Decompressor is too big." This seems to be caused by a section .note.gnu.property that is placed at an offset such that objcopy needs to pad the img file with zeros. This issue is present on: Ubuntu 19.10 with gcc (Ubuntu 8.3.0-26ubuntu1~19.10) 8.3.0 Ubuntu 19.10 with gcc (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008 This issue is not present on: Ubuntu 19.10 with gcc (Ubuntu 7.5.0-3ubuntu1~19.10) 7.5.0 RHEL 8.0 with gcc 8.3.1 20190507 (Red Hat 8.3.1-4) The issue can be fixed by removing the section using objcopy as shown in this patch. Signed-off-by: Ani Sinha Signed-off-by: Simon Hardy Reviewed-by: Daniel Kiper --- gentpl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gentpl.py b/gentpl.py index 13a60816..1a7bcd2c 100644 --- a/gentpl.py +++ b/gentpl.py @@ -453,7 +453,7 @@ def image(platform): if test x$(USE_APPLE_CC_FIXES) = xyes; then \ $(MACHO2IMG) $< $@; \ else \ - $(OBJCOPY) $(""" + cname() + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .note.gnu.gold-version $< $@; \ + $(OBJCOPY) $(""" + cname() + """_OBJCOPYFLAGS) --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .reginfo -R .rel.dyn -R .note.gnu.gold-version -R .note.gnu.property $< $@; \ fi """) return r From 36cde12912acec445d506eaad1905ca35c4cdb37 Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Wed, 1 Jun 2022 20:44:29 +0530 Subject: [PATCH 03/21] x86-64: Treat R_X86_64_PLT32 as R_X86_64_PC32 This is a port of the upstram commit: 842c390469e2c2e10b5 ("x86-64: Treat R_X86_64_PLT32 as R_X86_64_PC32") Starting from binutils commit bd7ab16b4537788ad53521c45469a1bdae84ad4a: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=bd7ab16b4537788ad53521c45469a1bdae84ad4a x86-64 assembler generates R_X86_64_PLT32, instead of R_X86_64_PC32, for 32-bit PC-relative branches. Grub2 should treat R_X86_64_PLT32 as R_X86_64_PC32. Signed-off-by: Ani Sinha Signed-off-by: H.J. Lu Reviewed-by: Daniel Kiper --- util/grub-mkimagexx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index 476d05ee..13e61a75 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -427,6 +427,7 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections, break; case R_X86_64_PC32: + case R_X86_64_PLT32: { grub_uint32_t *t32 = (grub_uint32_t *) target; *t32 = grub_host_to_target64 (grub_target_to_host32 (*t32) From f3770082df8f9abcbd13d9755499432bc2fa8271 Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Wed, 1 Jun 2022 21:49:57 +0530 Subject: [PATCH 04/21] abort: fix gcc complaint with applying 'noreturn' attribute This change fixes this gcc warning: error: 'abort' specifies less restrictive attribute than its target 'grub_abort': 'noreturn' [-Werror=missing-attributes] It applies 'noreturn' attribute to abort() declaration as well, which has already been declared as an alias to grub_abort(). Signed-off-by: Ani Sinha --- grub-core/kern/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c index 0c80cc83..3ce9d373 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c @@ -1189,7 +1189,7 @@ grub_abort (void) #if ! defined (__APPLE__) && !defined (GRUB_UTIL) /* GCC emits references to abort(). */ -void abort (void) __attribute__ ((alias ("grub_abort"))); +void __attribute__ ((noreturn)) abort (void) __attribute__ ((alias ("grub_abort"))); #endif #if NEED_ENABLE_EXECUTE_STACK && !defined(GRUB_UTIL) && !defined(GRUB_MACHINE_EMU) From fe23c1ad7b14db92ab08dfb047211584bdca026e Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Thu, 2 Jun 2022 08:53:41 +0530 Subject: [PATCH 05/21] lex: ignore unused value Ignore gcc warning -Wunused-value that causes build failure on newer compiler. Signed-off-by: Ani Sinha --- grub-core/script/yylex.l | 1 + 1 file changed, 1 insertion(+) diff --git a/grub-core/script/yylex.l b/grub-core/script/yylex.l index 8fdcfef6..5ad5c41c 100644 --- a/grub-core/script/yylex.l +++ b/grub-core/script/yylex.l @@ -31,6 +31,7 @@ #pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations" #pragma GCC diagnostic ignored "-Wunused-function" #pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wunused-value" #define yyfree grub_lexer_yyfree #define yyalloc grub_lexer_yyalloc From a4ffa70a58f00261412325bed4db87cebe2836d3 Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Thu, 2 Jun 2022 09:23:52 +0530 Subject: [PATCH 06/21] disable address-of-packed-member warning/failure Disable gcc address-of-packed-member warnings in newer compilers. This warning results in build failure when enabled since many parts of the grub codebase access members of the packed structs directly. Signed-off-by: Ani Sinha --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 91b36d0a..6124ebea 100644 --- a/configure.ac +++ b/configure.ac @@ -393,7 +393,7 @@ LDFLAGS="$TARGET_LDFLAGS" LIBS="" # debug flags. -WARN_FLAGS="-Wall -W -Wshadow -Wold-style-definition -Wpointer-arith -Wundef -Wextra -Waddress -Wattributes -Wcast-align -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wempty-body -Wendif-labels -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmain -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-noreturn -Wmultichar -Wnonnull -Woverflow -Wparentheses -Wpointer-arith -Wpointer-to-int-cast -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wstrict-aliasing -Wswitch -Wtrigraphs -Wundef -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wnested-externs -Wstrict-prototypes -Wpointer-sign" +WARN_FLAGS="-Wall -Wno-address-of-packed-member -W -Wshadow -Wold-style-definition -Wpointer-arith -Wundef -Wextra -Waddress -Wattributes -Wcast-align -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wempty-body -Wendif-labels -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmain -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-noreturn -Wmultichar -Wnonnull -Woverflow -Wparentheses -Wpointer-arith -Wpointer-to-int-cast -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wstrict-aliasing -Wswitch -Wtrigraphs -Wundef -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wnested-externs -Wstrict-prototypes -Wpointer-sign" HOST_CFLAGS="$HOST_CFLAGS $WARN_FLAGS" TARGET_CFLAGS="$TARGET_CFLAGS $WARN_FLAGS -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations" TARGET_CCASFLAGS="$TARGET_CCASFLAGS -g" From d7adac3a6824a4e6e40e8510c8308554219aaac0 Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Thu, 2 Jun 2022 10:43:14 +0530 Subject: [PATCH 07/21] fix build failure due to undefined _GLOBAL_OFFSET_TABLE_ symbol The newer gcc compiler (tried with gcc 9.4) enables PIE/PIC by default. When compiling 32 bit code, this results in build failure like this: cat syminfo.lst | sort | awk -f /home/anisinha/workspace/bits/build/grub/grub-core/genmoddep.awk > moddep.lst || (rm -f moddep.lst; exit 1) _GLOBAL_OFFSET_TABLE_ in python is not defined The undefined symbol exists in the object file libffi/src/x86/python_module-sysv.o which is built from the assembly source libffi/src/x86/sysv.S. In this assembly code, symbol _GLOBAL_OFFSET_TABLE_ is referenced only wnen __PIC__ is defined, which is the default case for the newer compiler. Fix this by passing -fno-PIC to the CFLAGS for 32 bit compilation case. Signed-off-by: Ani Sinha --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 6124ebea..e5d3d8de 100644 --- a/configure.ac +++ b/configure.ac @@ -542,7 +542,7 @@ if test "x$target_m32" = x1; then # Force 32-bit mode. TARGET_CFLAGS="$TARGET_CFLAGS -m32" TARGET_CCASFLAGS="$TARGET_CCASFLAGS -m32" - TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32" + TARGET_CPPFLAGS="$TARGET_CPPFLAGS -m32 -fno-pic" TARGET_LDFLAGS="$TARGET_LDFLAGS -m32" TARGET_MODULE_FORMAT="elf32" fi From f20a2dcb3397e6f653840df6da62b519a2080f15 Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Thu, 2 Jun 2022 11:19:58 +0530 Subject: [PATCH 08/21] Introduce grub_efi_packed_guid and use it where alignment is not guranteed ported from upstream commit: 316dda716c046 ("Introduce grub_efi_packed_guid and use it where alignment is not guranteed") Signed-off-by: Ani Sinha --- grub-core/commands/efi/acpi.c | 8 ++++---- grub-core/commands/efi/loadbios.c | 2 +- grub-core/loader/i386/xnu.c | 2 +- include/grub/efi/api.h | 21 +++++++++++++++------ include/grub/efiemu/efiemu.h | 4 ++-- include/grub/efiemu/runtime.h | 2 +- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/grub-core/commands/efi/acpi.c b/grub-core/commands/efi/acpi.c index 93a560d9..c6976bc4 100644 --- a/grub-core/commands/efi/acpi.c +++ b/grub-core/commands/efi/acpi.c @@ -26,11 +26,11 @@ struct grub_acpi_rsdp_v10 * grub_machine_acpi_get_rsdpv1 (void) { unsigned i; - static grub_efi_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID; + static grub_efi_packed_guid_t acpi_guid = GRUB_EFI_ACPI_TABLE_GUID; for (i = 0; i < grub_efi_system_table->num_table_entries; i++) { - grub_efi_guid_t *guid = + grub_efi_packed_guid_t *guid = &grub_efi_system_table->configuration_table[i].vendor_guid; if (! grub_memcmp (guid, &acpi_guid, sizeof (grub_efi_guid_t))) @@ -44,11 +44,11 @@ struct grub_acpi_rsdp_v20 * grub_machine_acpi_get_rsdpv2 (void) { unsigned i; - static grub_efi_guid_t acpi20_guid = GRUB_EFI_ACPI_20_TABLE_GUID; + static grub_efi_packed_guid_t acpi20_guid = GRUB_EFI_ACPI_20_TABLE_GUID; for (i = 0; i < grub_efi_system_table->num_table_entries; i++) { - grub_efi_guid_t *guid = + grub_efi_packed_guid_t *guid = &grub_efi_system_table->configuration_table[i].vendor_guid; if (! grub_memcmp (guid, &acpi20_guid, sizeof (grub_efi_guid_t))) diff --git a/grub-core/commands/efi/loadbios.c b/grub-core/commands/efi/loadbios.c index 214adc3d..132cadbc 100644 --- a/grub-core/commands/efi/loadbios.c +++ b/grub-core/commands/efi/loadbios.c @@ -105,7 +105,7 @@ fake_bios_data (int use_rom) smbios = 0; for (i = 0; i < grub_efi_system_table->num_table_entries; i++) { - grub_efi_guid_t *guid = + grub_efi_packed_guid_t *guid = &grub_efi_system_table->configuration_table[i].vendor_guid; if (! grub_memcmp (guid, &acpi2_guid, sizeof (grub_efi_guid_t))) diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c index 4e5ce097..04429b5f 100644 --- a/grub-core/loader/i386/xnu.c +++ b/grub-core/loader/i386/xnu.c @@ -724,7 +724,7 @@ grub_cpu_xnu_fill_devicetree (grub_uint64_t *fsbfreq_out) { void *ptr; struct grub_xnu_devtree_key *curkey; - grub_efi_guid_t guid; + grub_efi_packed_guid_t guid; char guidbuf[64]; /* Retrieve current key. */ diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h index 26127ded..47a9cb10 100644 --- a/include/grub/efi/api.h +++ b/include/grub/efi/api.h @@ -384,6 +384,15 @@ struct grub_efi_guid } __attribute__ ((aligned(8))); typedef struct grub_efi_guid grub_efi_guid_t; +struct grub_efi_packed_guid +{ + grub_uint32_t data1; + grub_uint16_t data2; + grub_uint16_t data3; + grub_uint8_t data4[8]; +} GRUB_PACKED; +typedef struct grub_efi_packed_guid grub_efi_packed_guid_t; + /* XXX although the spec does not specify the padding, this actually must have the padding! */ struct grub_efi_memory_descriptor @@ -467,7 +476,7 @@ typedef struct grub_efi_memory_mapped_device_path grub_efi_memory_mapped_device_ struct grub_efi_vendor_device_path { grub_efi_device_path_t header; - grub_efi_guid_t vendor_guid; + grub_efi_packed_guid_t vendor_guid; grub_efi_uint8_t vendor_defined_data[0]; } __attribute__ ((packed)); typedef struct grub_efi_vendor_device_path grub_efi_vendor_device_path_t; @@ -661,7 +670,7 @@ typedef struct grub_efi_uart_device_path grub_efi_uart_device_path_t; struct grub_efi_vendor_messaging_device_path { grub_efi_device_path_t header; - grub_efi_guid_t vendor_guid; + grub_efi_packed_guid_t vendor_guid; grub_efi_uint8_t vendor_defined_data[0]; } __attribute__ ((packed)); typedef struct grub_efi_vendor_messaging_device_path grub_efi_vendor_messaging_device_path_t; @@ -699,7 +708,7 @@ typedef struct grub_efi_cdrom_device_path grub_efi_cdrom_device_path_t; struct grub_efi_vendor_media_device_path { grub_efi_device_path_t header; - grub_efi_guid_t vendor_guid; + grub_efi_packed_guid_t vendor_guid; grub_efi_uint8_t vendor_defined_data[0]; } __attribute__ ((packed)); typedef struct grub_efi_vendor_media_device_path grub_efi_vendor_media_device_path_t; @@ -718,7 +727,7 @@ typedef struct grub_efi_file_path_device_path grub_efi_file_path_device_path_t; struct grub_efi_protocol_device_path { grub_efi_device_path_t header; - grub_efi_guid_t guid; + grub_efi_packed_guid_t guid; } __attribute__ ((packed)); typedef struct grub_efi_protocol_device_path grub_efi_protocol_device_path_t; @@ -727,7 +736,7 @@ typedef struct grub_efi_protocol_device_path grub_efi_protocol_device_path_t; struct grub_efi_piwg_device_path { grub_efi_device_path_t header; - grub_efi_guid_t guid __attribute__ ((packed)); + grub_efi_packed_guid_t guid; } __attribute__ ((packed)); typedef struct grub_efi_piwg_device_path grub_efi_piwg_device_path_t; @@ -1084,7 +1093,7 @@ typedef struct grub_efi_runtime_services grub_efi_runtime_services_t; struct grub_efi_configuration_table { - grub_efi_guid_t vendor_guid; + grub_efi_packed_guid_t vendor_guid; void *vendor_table; } __attribute__ ((packed)); typedef struct grub_efi_configuration_table grub_efi_configuration_table_t; diff --git a/include/grub/efiemu/efiemu.h b/include/grub/efiemu/efiemu.h index 4ce3fc92..a592e8a6 100644 --- a/include/grub/efiemu/efiemu.h +++ b/include/grub/efiemu/efiemu.h @@ -183,13 +183,13 @@ struct grub_efiemu_configuration_table }; struct grub_efiemu_configuration_table32 { - grub_efi_guid_t vendor_guid; + grub_efi_packed_guid_t vendor_guid; grub_efi_uint32_t vendor_table; } __attribute__ ((packed)); typedef struct grub_efiemu_configuration_table32 grub_efiemu_configuration_table32_t; struct grub_efiemu_configuration_table64 { - grub_efi_guid_t vendor_guid; + grub_efi_packed_guid_t vendor_guid; grub_efi_uint64_t vendor_table; } __attribute__ ((packed)); typedef struct grub_efiemu_configuration_table64 grub_efiemu_configuration_table64_t; diff --git a/include/grub/efiemu/runtime.h b/include/grub/efiemu/runtime.h index 1eb474a5..18c866ca 100644 --- a/include/grub/efiemu/runtime.h +++ b/include/grub/efiemu/runtime.h @@ -29,7 +29,7 @@ struct grub_efiemu_ptv_rel struct efi_variable { - grub_efi_guid_t guid; + grub_efi_packed_guid_t guid; grub_uint32_t namelen; grub_uint32_t size; grub_efi_uint32_t attributes; From 7fb057b51cab3516531ce5cbe1da7e667b242f2e Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Thu, 2 Jun 2022 12:34:17 +0530 Subject: [PATCH 09/21] Fix couple of linker complaints when built with the 2.34 version of linker a) Fix the linker warning "-r and -pie may not be used together" The fix has been ported from the Qemu commmit: c96f0ee6a67ca ("rules.mak: Use -r instead of -Wl, -r to fix building when PIE is default") With PIE enabled by deafault, we should use "-r" instead of "Wl,-r". The gcc "-r" option avoids gcc from sending "-pie" to the linker when a relocatable object is sent as its input. b) Fix linker warning "PHDR segment not covered by LOAD segment". To fix this, we send "-static" as the linker argument so that PHDR segment is not generated. See also the following note in ld: Changes in 2.34: * The ld check for "PHDR segment not covered by LOAD segment" is more effective, catching cases that were wrongly allowed by previous versions of ld. If you see this error it is likely you are linking with a bad linker script or the binary you are building is not intended to be loaded by a dynamic loader. In the latter case --no-dynamic-linker is appropriate. Signed-off-by: Ani Sinha --- acinclude.m4 | 2 +- conf/Makefile.common | 2 +- grub-core/Makefile.core.def | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 0eb2e2a1..38df4f50 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -91,7 +91,7 @@ else fi grub_cv_prog_objcopy_absolute=yes for link_addr in 0x2000 0x8000 0x7C00; do - if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},$link_addr conftest.o -o conftest.exec]); then : + if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib -static ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},$link_addr conftest.o -o conftest.exec]); then : else AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr]) fi diff --git a/conf/Makefile.common b/conf/Makefile.common index b5615a14..07e16579 100644 --- a/conf/Makefile.common +++ b/conf/Makefile.common @@ -78,7 +78,7 @@ STRIPFLAGS_KERNEL = -R .rel.dyn -R .reginfo -R .note -R .comment -R .note.gnu.go endif CFLAGS_MODULE = $(CFLAGS_CPU) $(CFLAGS_PLATFORM) -ffreestanding -LDFLAGS_MODULE = $(LDFLAGS_CPU) $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d +LDFLAGS_MODULE = $(LDFLAGS_CPU) $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -r -Wl,-d CPPFLAGS_MODULE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) CCASFLAGS_MODULE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 9a9840b3..f57f4c9b 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -36,9 +36,9 @@ kernel = { nostrip = emu; emu_ldflags = '-Wl,-r,-d'; - i386_efi_ldflags = '-Wl,-r,-d'; + i386_efi_ldflags = '-r -Wl,-d'; i386_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; - x86_64_efi_ldflags = '-Wl,-r,-d'; + x86_64_efi_ldflags = '-r -Wl,-d'; x86_64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; ia64_efi_cflags = '-fno-builtin -fpic -minline-int-divide-max-throughput'; @@ -46,7 +46,7 @@ kernel = { ia64_efi_stripflags = '--strip-unneeded -K start -R .note -R .comment -R .note.gnu.gold-version'; i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; - i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x9000'; + i386_pc_ldflags = '-static $(TARGET_IMG_BASE_LDOPT),0x9000'; i386_qemu_ldflags = '$(TARGET_IMG_LDFLAGS)'; i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x8200'; @@ -271,7 +271,7 @@ image = { sparc64_ieee1275 = boot/sparc64/ieee1275/boot.S; i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; - i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00'; + i386_pc_ldflags = '-static $(TARGET_IMG_BASE_LDOPT),0x7C00'; i386_qemu_ldflags = '$(TARGET_IMG_LDFLAGS)'; i386_qemu_ldflags = '$(TARGET_IMG_BASE_LDOPT),$(GRUB_BOOT_MACHINE_LINK_ADDR)'; @@ -293,7 +293,7 @@ image = { cppflags = '-DHYBRID_BOOT=1'; i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; - i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00'; + i386_pc_ldflags = '-static $(TARGET_IMG_BASE_LDOPT),0x7C00'; objcopyflags = '-O binary'; enable = i386_pc; @@ -304,7 +304,7 @@ image = { i386_pc = boot/i386/pc/cdboot.S; i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; - i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00'; + i386_pc_ldflags = '-static $(TARGET_IMG_BASE_LDOPT),0x7C00'; objcopyflags = '-O binary'; enable = i386_pc; }; @@ -314,7 +314,7 @@ image = { i386_pc = boot/i386/pc/pxeboot.S; i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; - i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x7C00'; + i386_pc_ldflags = '-static $(TARGET_IMG_BASE_LDOPT),0x7C00'; objcopyflags = '-O binary'; enable = i386_pc; @@ -325,7 +325,7 @@ image = { i386_pc = boot/i386/pc/diskboot.S; i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; - i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x8000'; + i386_pc_ldflags = '-static $(TARGET_IMG_BASE_LDOPT),0x8000'; sparc64_ieee1275 = boot/sparc64/ieee1275/diskboot.S; sparc64_ieee1275_ldflags = '-Wl,-Ttext=0x4200'; @@ -341,7 +341,7 @@ image = { i386_pc = boot/i386/pc/lnxboot.S; i386_pc_ldflags = '$(TARGET_IMG_LDFLAGS)'; - i386_pc_ldflags = '$(TARGET_IMG_BASE_LDOPT),0x6000'; + i386_pc_ldflags = '-static $(TARGET_IMG_BASE_LDOPT),0x6000'; objcopyflags = '-O binary'; enable = i386_pc; @@ -388,7 +388,7 @@ image = { i386_pc = boot/i386/pc/startup_raw.S; objcopyflags = '-O binary'; - ldflags = '$(TARGET_IMG_LDFLAGS) $(TARGET_IMG_BASE_LDOPT),0x8200'; + ldflags = '-static $(TARGET_IMG_LDFLAGS) $(TARGET_IMG_BASE_LDOPT),0x8200'; enable = i386_pc; }; From 977cb1e8e7823cb7639d7f1e933f55571efb0565 Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Thu, 2 Jun 2022 19:26:44 +0530 Subject: [PATCH 10/21] btrfs: fix glibc complaint about uninitialzied data structure Mem-setting the struct to zero first so that it is properly initialized. It is to be noted that even without the proper initialization, the code was not actually accessing uninitialized memory. This change thus does not fix a bug but only silences a compiler warning. Signed-off-by: Ani Sinha --- grub-core/fs/btrfs.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index a993f074..f7b3ba26 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -28,6 +28,7 @@ #include #include #include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -252,10 +253,16 @@ static grub_err_t read_sblock (grub_disk_t disk, struct grub_btrfs_superblock *sb) { unsigned i; + struct grub_btrfs_superblock sblock; grub_err_t err = GRUB_ERR_NONE; + /* without this, the comiler will get confused. It will complain that + * on the first iteration of the loop below, we are accessing + * uninitialized sblock + */ + memset(&sblock, 0, sizeof(struct grub_btrfs_superblock)); + for (i = 0; i < ARRAY_SIZE (superblock_sectors); i++) { - struct grub_btrfs_superblock sblock; /* Don't try additional superblocks beyond device size. */ if (i && (grub_le_to_cpu64 (sblock.this_device.size) >> GRUB_DISK_SECTOR_BITS) <= superblock_sectors[i]) From 59ef15e130f145b14fa901568b523ec458bf84a3 Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Thu, 2 Jun 2022 22:06:00 +0530 Subject: [PATCH 11/21] Fix alignment of some data structures This fixes the alignment of some data strructures by making them aligned to eight byte boundaries. This resolves gcc complaints like the following: error: alignment 1 of 'struct grub_btrfs_inode' is less than 8 [-Werror=packed-not-aligned] Signed-off-by: Ani Sinha --- grub-core/fs/btrfs.c | 2 +- include/grub/acpi.h | 2 +- include/grub/gpt_partition.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index f7b3ba26..c6068329 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -200,7 +200,7 @@ struct grub_btrfs_time { grub_int64_t sec; grub_uint32_t nanosec; -} __attribute__ ((aligned (4))); +} __attribute__ ((packed)); struct grub_btrfs_inode { diff --git a/include/grub/acpi.h b/include/grub/acpi.h index ee0a108f..ec2a54d7 100644 --- a/include/grub/acpi.h +++ b/include/grub/acpi.h @@ -84,7 +84,7 @@ struct grub_acpi_madt grub_uint32_t lapic_addr; grub_uint32_t flags; struct grub_acpi_madt_entry_header entries[0]; -}; +} __attribute__ ((packed)); enum { diff --git a/include/grub/gpt_partition.h b/include/grub/gpt_partition.h index 83e3b319..7824708c 100644 --- a/include/grub/gpt_partition.h +++ b/include/grub/gpt_partition.h @@ -28,7 +28,7 @@ struct grub_gpt_part_type grub_uint16_t data2; grub_uint16_t data3; grub_uint8_t data4[8]; -} __attribute__ ((aligned(8))); +} __attribute__ ((packed)); typedef struct grub_gpt_part_type grub_gpt_part_type_t; #define GRUB_GPT_PARTITION_TYPE_EMPTY \ From 4602bad7c76e3a0c5d6d784cbad16ff34ebc752c Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Wed, 1 Jun 2022 11:50:04 +0530 Subject: [PATCH 12/21] fix implicit fallthrough gcc warnings This patch addresses implicit fallthrough warnings on the newer gcc compiler. Proper comment to silence the warning or appropriate comments have been added in the case statements. Signed-off-by: Ani Sinha --- grub-core/commands/hdparm.c | 1 + grub-core/disk/cryptodisk.c | 1 + grub-core/disk/diskfilter.c | 2 ++ grub-core/disk/efi/efidisk.c | 3 +++ grub-core/efiemu/mm.c | 1 + grub-core/font/font.c | 2 ++ grub-core/fs/udf.c | 1 + grub-core/gdb/cstub.c | 1 + grub-core/gnulib/regexec.c | 2 +- grub-core/lib/legacy_parse.c | 1 + grub-core/lib/xzembed/xz_dec_lzma2.c | 2 ++ grub-core/lib/xzembed/xz_dec_stream.c | 8 ++++++++ grub-core/loader/i386/linux.c | 3 +++ grub-core/loader/i386/pc/linux.c | 3 +++ grub-core/mmap/efi/mmap.c | 3 +++ grub-core/normal/charset.c | 1 + grub-core/video/bochs.c | 1 + grub-core/video/cirrus.c | 1 + grub-core/video/i386/pc/vbe.c | 2 ++ grub-core/video/readers/jpeg.c | 1 + util/grub-mkimagexx.c | 1 + 21 files changed, 40 insertions(+), 1 deletion(-) diff --git a/grub-core/commands/hdparm.c b/grub-core/commands/hdparm.c index 3fb08912..208a8320 100644 --- a/grub-core/commands/hdparm.c +++ b/grub-core/commands/hdparm.c @@ -328,6 +328,7 @@ grub_cmd_hdparm (grub_extcmd_context_t ctxt, int argc, char **args) ata = ((struct grub_scsi *) disk->data)->data; break; } + // fall through default: return grub_error (GRUB_ERR_IO, "not an ATA device"); } diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 1ac906d9..e96c5a76 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -268,6 +268,7 @@ grub_cryptodisk_endecrypt (struct grub_cryptodisk *dev, break; case GRUB_CRYPTODISK_MODE_IV_PLAIN64: iv[1] = grub_cpu_to_le32 (sector >> 32); + // fall through case GRUB_CRYPTODISK_MODE_IV_PLAIN: iv[0] = grub_cpu_to_le32 (sector & 0xFFFFFFFF); break; diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c index 6e9745e3..97cdb19b 100644 --- a/grub-core/disk/diskfilter.c +++ b/grub-core/disk/diskfilter.c @@ -71,6 +71,7 @@ is_lv_readable (struct grub_diskfilter_lv *lv, int easily) case GRUB_DISKFILTER_RAID6: if (!easily) need--; + // fall through case GRUB_DISKFILTER_RAID4: case GRUB_DISKFILTER_RAID5: if (!easily) @@ -507,6 +508,7 @@ read_segment (struct grub_diskfilter_segment *seg, grub_disk_addr_t sector, if (seg->node_count == 1) return grub_diskfilter_read_node (&seg->nodes[0], sector, size, buf); + // fall through case GRUB_DISKFILTER_MIRROR: case GRUB_DISKFILTER_RAID10: { diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c index d9d788c4..5e8be72f 100644 --- a/grub-core/disk/efi/efidisk.c +++ b/grub-core/disk/efi/efidisk.c @@ -262,6 +262,9 @@ name_devices (struct grub_efidisk_data *devices) { case GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE: is_hard_drive = 1; +#if defined(__GNUC__) && __GNUC__ >= 7 + __attribute__ ((fallthrough)); +#endif /* Fall through by intention. */ case GRUB_EFI_CDROM_DEVICE_PATH_SUBTYPE: { diff --git a/grub-core/efiemu/mm.c b/grub-core/efiemu/mm.c index 10cbc68c..ebd2f9d0 100644 --- a/grub-core/efiemu/mm.c +++ b/grub-core/efiemu/mm.c @@ -410,6 +410,7 @@ grub_efiemu_mmap_fill (void) default: grub_dprintf ("efiemu", "Unknown memory type %d. Assuming unusable\n", type); + // fall through case GRUB_MEMORY_RESERVED: return grub_efiemu_add_to_mmap (addr, size, GRUB_EFI_UNUSABLE_MEMORY); diff --git a/grub-core/font/font.c b/grub-core/font/font.c index fca8c8d0..4c51f433 100644 --- a/grub-core/font/font.c +++ b/grub-core/font/font.c @@ -1297,6 +1297,7 @@ blit_comb (const struct grub_unicode_glyph *glyph_id, - grub_font_get_xheight (combining_glyphs[i]->font) - 1; if (space <= 0) space = 1 + (grub_font_get_xheight (main_glyph->font)) / 8; + // fall through case GRUB_UNICODE_STACK_ATTACHED_ABOVE: do_blit (combining_glyphs[i], targetx, @@ -1338,6 +1339,7 @@ blit_comb (const struct grub_unicode_glyph *glyph_id, + combining_glyphs[i]->height); if (space <= 0) space = 1 + (grub_font_get_xheight (main_glyph->font)) / 8; + // fall through case GRUB_UNICODE_STACK_ATTACHED_BELOW: do_blit (combining_glyphs[i], targetx, -(bounds.y - space)); diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c index 8e28d41e..04b79728 100644 --- a/grub-core/fs/udf.c +++ b/grub-core/fs/udf.c @@ -970,6 +970,7 @@ grub_udf_read_symlink (grub_fshelp_node_t node) case 1: if (ptr[1]) goto fail; + // fall through case 2: /* in 4 bytes. out: 1 byte. */ optr = out; diff --git a/grub-core/gdb/cstub.c b/grub-core/gdb/cstub.c index a5c0c431..9cc4c9b7 100644 --- a/grub-core/gdb/cstub.c +++ b/grub-core/gdb/cstub.c @@ -336,6 +336,7 @@ grub_gdb_trap (int trap_no) /* sAA..AA: Step one instruction from AA..AA(optional). */ case 's': stepping = 1; + // fall through /* cAA..AA: Continue at address AA..AA(optional). */ case 'c': diff --git a/grub-core/gnulib/regexec.c b/grub-core/gnulib/regexec.c index dc449ce5..4b56021d 100644 --- a/grub-core/gnulib/regexec.c +++ b/grub-core/gnulib/regexec.c @@ -4104,8 +4104,8 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node, case OP_UTF8_PERIOD: if (ch >= ASCII_CHARS) return false; - /* FALLTHROUGH */ #endif + // fall through case OP_PERIOD: if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE)) || (ch == '\0' && (mctx->dfa->syntax & RE_DOT_NOT_NULL))) diff --git a/grub-core/lib/legacy_parse.c b/grub-core/lib/legacy_parse.c index 775eaad1..67c8aafa 100644 --- a/grub-core/lib/legacy_parse.c +++ b/grub-core/lib/legacy_parse.c @@ -626,6 +626,7 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix) { case TYPE_FILE_NO_CONSUME: hold_arg = 1; + // fall through case TYPE_PARTITION: case TYPE_FILE: args[i] = adjust_file (curarg, curarglen); diff --git a/grub-core/lib/xzembed/xz_dec_lzma2.c b/grub-core/lib/xzembed/xz_dec_lzma2.c index 7899e9e8..a8ed1c4e 100644 --- a/grub-core/lib/xzembed/xz_dec_lzma2.c +++ b/grub-core/lib/xzembed/xz_dec_lzma2.c @@ -1041,6 +1041,7 @@ enum xz_ret xz_dec_lzma2_run( return XZ_DATA_ERROR; s->lzma2.sequence = SEQ_LZMA_PREPARE; + //fall through case SEQ_LZMA_PREPARE: if (s->lzma2.compressed < RC_INIT_BYTES) @@ -1051,6 +1052,7 @@ enum xz_ret xz_dec_lzma2_run( s->lzma2.compressed -= RC_INIT_BYTES; s->lzma2.sequence = SEQ_LZMA_RUN; + // fall through case SEQ_LZMA_RUN: /* diff --git a/grub-core/lib/xzembed/xz_dec_stream.c b/grub-core/lib/xzembed/xz_dec_stream.c index 0d79b1f0..3eac7bc4 100644 --- a/grub-core/lib/xzembed/xz_dec_stream.c +++ b/grub-core/lib/xzembed/xz_dec_stream.c @@ -748,6 +748,7 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) return ret; s->sequence = SEQ_BLOCK_START; + // fall through case SEQ_BLOCK_START: /* We need one byte of input to continue. */ @@ -771,6 +772,7 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) s->temp.size = s->block_header.size; s->temp.pos = 0; s->sequence = SEQ_BLOCK_HEADER; + // fall through case SEQ_BLOCK_HEADER: if (!fill_temp(s, b)) @@ -781,6 +783,7 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) return ret; s->sequence = SEQ_BLOCK_UNCOMPRESS; + // fall through case SEQ_BLOCK_UNCOMPRESS: ret = dec_block(s, b); @@ -788,6 +791,7 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) return ret; s->sequence = SEQ_BLOCK_PADDING; + // fall through case SEQ_BLOCK_PADDING: /* @@ -808,6 +812,7 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) } s->sequence = SEQ_BLOCK_CHECK; + // fall through case SEQ_BLOCK_CHECK: ret = hash_validate(s, b, 0); @@ -823,6 +828,7 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) return ret; s->sequence = SEQ_INDEX_PADDING; + // fall through case SEQ_INDEX_PADDING: while ((s->index.size + (b->in_pos - s->in_start)) @@ -862,6 +868,7 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) #endif s->sequence = SEQ_INDEX_CRC32; + // fall through case SEQ_INDEX_CRC32: ret = hash_validate(s, b, 1); @@ -870,6 +877,7 @@ static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) s->temp.size = STREAM_HEADER_SIZE; s->sequence = SEQ_STREAM_FOOTER; + // fall through case SEQ_STREAM_FOOTER: if (!fill_temp(s, b)) diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 62087cfa..5e82a21b 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -977,10 +977,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), { case 'g': shift += 10; + // fall through case 'm': shift += 10; + // fall through case 'k': shift += 10; + // fall through default: break; } diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c index 4eeb1b6c..48162e9a 100644 --- a/grub-core/loader/i386/pc/linux.c +++ b/grub-core/loader/i386/pc/linux.c @@ -252,10 +252,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), { case 'g': shift += 10; + // fall through case 'm': shift += 10; + // fall through case 'k': shift += 10; + // fall through default: break; } diff --git a/grub-core/mmap/efi/mmap.c b/grub-core/mmap/efi/mmap.c index 75f82eda..0c734a4d 100644 --- a/grub-core/mmap/efi/mmap.c +++ b/grub-core/mmap/efi/mmap.c @@ -72,6 +72,7 @@ grub_efi_mmap_iterate (grub_memory_hook_t hook, int avoid_efi_boot_services) GRUB_MEMORY_AVAILABLE); break; } + break; case GRUB_EFI_RUNTIME_SERVICES_CODE: hook (desc->physical_start, desc->num_pages * 4096, GRUB_MEMORY_CODE); @@ -85,6 +86,7 @@ grub_efi_mmap_iterate (grub_memory_hook_t hook, int avoid_efi_boot_services) default: grub_printf ("Unknown memory type %d, considering reserved\n", desc->type); + break; case GRUB_EFI_BOOT_SERVICES_DATA: if (!avoid_efi_boot_services) @@ -93,6 +95,7 @@ grub_efi_mmap_iterate (grub_memory_hook_t hook, int avoid_efi_boot_services) GRUB_MEMORY_AVAILABLE); break; } + break; case GRUB_EFI_RESERVED_MEMORY_TYPE: case GRUB_EFI_RUNTIME_SERVICES_DATA: case GRUB_EFI_MEMORY_MAPPED_IO: diff --git a/grub-core/normal/charset.c b/grub-core/normal/charset.c index 25593ce8..2dda288d 100644 --- a/grub-core/normal/charset.c +++ b/grub-core/normal/charset.c @@ -858,6 +858,7 @@ grub_bidi_line_logical_to_visual (const grub_uint32_t *logical, case GRUB_BIDI_TYPE_R: case GRUB_BIDI_TYPE_AL: bidi_needed = 1; + // fall through default: { if (join_state == JOIN_FORCE) diff --git a/grub-core/video/bochs.c b/grub-core/video/bochs.c index 79cae654..e279256a 100644 --- a/grub-core/video/bochs.c +++ b/grub-core/video/bochs.c @@ -351,6 +351,7 @@ grub_video_bochs_setup (unsigned int width, unsigned int height, case 32: framebuffer.mode_info.reserved_mask_size = 8; framebuffer.mode_info.reserved_field_pos = 24; + // fall through case 24: framebuffer.mode_info.red_mask_size = 8; diff --git a/grub-core/video/cirrus.c b/grub-core/video/cirrus.c index 7fad50e5..f28c52d8 100644 --- a/grub-core/video/cirrus.c +++ b/grub-core/video/cirrus.c @@ -431,6 +431,7 @@ grub_video_cirrus_setup (unsigned int width, unsigned int height, case 32: framebuffer.mode_info.reserved_mask_size = 8; framebuffer.mode_info.reserved_field_pos = 24; + // fall through case 24: framebuffer.mode_info.red_mask_size = 8; diff --git a/grub-core/video/i386/pc/vbe.c b/grub-core/video/i386/pc/vbe.c index 81e5a8e9..e70ae7df 100644 --- a/grub-core/video/i386/pc/vbe.c +++ b/grub-core/video/i386/pc/vbe.c @@ -880,6 +880,7 @@ vbe2videoinfo (grub_uint32_t mode, /* CGA is basically 4-bit packed pixel. */ case GRUB_VBE_MEMORY_MODEL_CGA: mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_CGA; + // fall through case GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL: mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_INDEX_COLOR; break; @@ -892,6 +893,7 @@ vbe2videoinfo (grub_uint32_t mode, /* Non chain 4 is a special case of planar. */ case GRUB_VBE_MEMORY_MODEL_NONCHAIN4_256: mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_NONCHAIN4; + // fall through case GRUB_VBE_MEMORY_MODEL_PLANAR: mode_info->mode_type |= GRUB_VIDEO_MODE_TYPE_PLANAR | GRUB_VIDEO_MODE_TYPE_INDEX_COLOR; diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c index f5e63aee..10ef4c8b 100644 --- a/grub-core/video/readers/jpeg.c +++ b/grub-core/video/readers/jpeg.c @@ -701,6 +701,7 @@ grub_jpeg_decode_jpeg (struct grub_jpeg_data *data) case JPEG_MARKER_SOS: /* Start Of Scan. */ if (grub_jpeg_decode_sos (data)) break; + // fall through case JPEG_MARKER_RST0: /* Restart. */ case JPEG_MARKER_RST1: case JPEG_MARKER_RST2: diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index 13e61a75..a4a7f9cf 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -486,6 +486,7 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections, + sym->st_value - image_target->vaddr_offset)); } + // fall through case R_IA64_LTOFF_FPTR22: *gpptr = grub_host_to_target64 (addend + sym_addr); add_value_to_slot_21 ((grub_addr_t) target, From 5d2f8bc8b7103fbd334f7f0ef8dbe56425156793 Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Thu, 26 Mar 2020 14:35:34 +0800 Subject: [PATCH 13/21] mdraid1x_linux: Fix gcc10 error -Werror=array-bounds We bumped into the build error while testing gcc-10 pre-release. ../../grub-core/disk/mdraid1x_linux.c: In function 'grub_mdraid_detect': ../../grub-core/disk/mdraid1x_linux.c:181:15: error: array subscript is outside array bounds of 'grub_uint16_t[0]' {aka 'short unsigned int[0]'} [-Werror=array-bounds] 181 | (char *) &sb.dev_roles[grub_le_to_cpu32 (sb.dev_number)] | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../grub-core/disk/mdraid1x_linux.c:98:17: note: while referencing 'dev_roles' 98 | grub_uint16_t dev_roles[0]; /* Role in array, or 0xffff for a spare, or 0xfffe for faulty. */ | ^~~~~~~~~ ../../grub-core/disk/mdraid1x_linux.c:127:33: note: defined here 'sb' 127 | struct grub_raid_super_1x sb; | ^~ cc1: all warnings being treated as errors Apparently gcc issues the warning when trying to access sb.dev_roles array's member, since it is a zero length array as the last element of struct grub_raid_super_1x that is allocated sparsely without extra chunks for the trailing bits, so the warning looks legitimate in this regard. As the whole thing here is doing offset computation, it is undue to use syntax that would imply array member access then take address from it later. Instead we could accomplish the same thing through basic array pointer arithmetic to pacify the warning. Signed-off-by: Michael Chang Reviewed-by: Daniel Kiper --- grub-core/disk/mdraid1x_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/disk/mdraid1x_linux.c b/grub-core/disk/mdraid1x_linux.c index a0e65a8c..4898ad03 100644 --- a/grub-core/disk/mdraid1x_linux.c +++ b/grub-core/disk/mdraid1x_linux.c @@ -178,7 +178,7 @@ grub_mdraid_detect (grub_disk_t disk, return NULL; if (grub_disk_read (disk, sector, - (char *) &sb.dev_roles[grub_le_to_cpu32 (sb.dev_number)] + (char *) (sb.dev_roles + grub_le_to_cpu32 (sb.dev_number)) - (char *) &sb, sizeof (role), &role)) return NULL; From 05926767f9b19d7cc4c86cc647893c17c971b222 Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Sat, 2 Jul 2022 00:55:01 -0700 Subject: [PATCH 14/21] Add GRUB_PACKED definition Definition of GRUB_PACKED was missing. Added it. Signed-off-by: Ani Sinha --- include/grub/types.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/grub/types.h b/include/grub/types.h index 3e677c69..eb7ea9b3 100644 --- a/include/grub/types.h +++ b/include/grub/types.h @@ -24,6 +24,12 @@ #include #endif +#ifdef __MINGW32__ +#define GRUB_PACKED __attribute__ ((packed,gcc_struct)) +#else +#define GRUB_PACKED __attribute__ ((packed)) +#endif + #ifdef GRUB_UTIL # define GRUB_CPU_SIZEOF_VOID_P SIZEOF_VOID_P # define GRUB_CPU_SIZEOF_LONG SIZEOF_LONG From e96575ad143ab047ed9ce8c0eb3ed3d193d0fe7c Mon Sep 17 00:00:00 2001 From: Michael Chang Date: Thu, 26 Mar 2020 14:35:35 +0800 Subject: [PATCH 15/21] zfs: Fix gcc10 error -Werror=zero-length-bounds We bumped into the build error while testing gcc-10 pre-release. In file included from ../../include/grub/file.h:22, from ../../grub-core/fs/zfs/zfs.c:34: ../../grub-core/fs/zfs/zfs.c: In function 'zap_leaf_lookup': ../../grub-core/fs/zfs/zfs.c:2263:44: error: array subscript '' is outside the bounds of an interior zero-length array 'grub_uint16_t[0]' {aka 'short unsigned int[0]'} [-Werror=zero-length-bounds] 2263 | for (chunk = grub_zfs_to_cpu16 (l->l_hash[LEAF_HASH (blksft, h, l)], endian); ../../include/grub/types.h:241:48: note: in definition of macro 'grub_le_to_cpu16' 241 | # define grub_le_to_cpu16(x) ((grub_uint16_t) (x)) | ^ ../../grub-core/fs/zfs/zfs.c:2263:16: note: in expansion of macro 'grub_zfs_to_cpu16' 2263 | for (chunk = grub_zfs_to_cpu16 (l->l_hash[LEAF_HASH (blksft, h, l)], endian); | ^~~~~~~~~~~~~~~~~ In file included from ../../grub-core/fs/zfs/zfs.c:48: ../../include/grub/zfs/zap_leaf.h:72:16: note: while referencing 'l_hash' 72 | grub_uint16_t l_hash[0]; | ^~~~~~ Here I'd like to quote from the gcc document [1] which seems best to explain what is going on here. "Although the size of a zero-length array is zero, an array member of this kind may increase the size of the enclosing type as a result of tail padding. The offset of a zero-length array member from the beginning of the enclosing structure is the same as the offset of an array with one or more elements of the same type. The alignment of a zero-length array is the same as the alignment of its elements. Declaring zero-length arrays in other contexts, including as interior members of structure objects or as non-member objects, is discouraged. Accessing elements of zero-length arrays declared in such contexts is undefined and may be diagnosed." The l_hash[0] is apparnetly an interior member to the enclosed structure while l_entries[0] is the trailing member. And the offending code tries to access members in l_hash[0] array that triggers the diagnose. Given that the l_entries[0] is used to get proper alignment to access leaf chunks, we can accomplish the same thing through the ALIGN_UP macro thus eliminating l_entries[0] from the structure. In this way we can pacify the warning as l_hash[0] now becomes the last member to the enclosed structure. [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html Signed-off-by: Michael Chang Reviewed-by: Daniel Kiper --- grub-core/fs/zfs/zfs.c | 5 ++++- include/grub/zfs/zap_leaf.h | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c index ba0554ab..21adb3fb 100644 --- a/grub-core/fs/zfs/zfs.c +++ b/grub-core/fs/zfs/zfs.c @@ -140,7 +140,10 @@ ZAP_LEAF_NUMCHUNKS (int bs) static inline zap_leaf_chunk_t * ZAP_LEAF_CHUNK (zap_leaf_phys_t *l, int bs, int idx) { - return &((zap_leaf_chunk_t *) (l->l_entries + grub_properly_aligned_t *l_entries; + + l_entries = (grub_properly_aligned_t *) ALIGN_UP((grub_addr_t)l->l_hash, sizeof (grub_properly_aligned_t)); + return &((zap_leaf_chunk_t *) (l_entries + (ZAP_LEAF_HASH_NUMENTRIES(bs) * 2) / sizeof (grub_properly_aligned_t)))[idx]; } diff --git a/include/grub/zfs/zap_leaf.h b/include/grub/zfs/zap_leaf.h index f2b7cb1d..3a77ff47 100644 --- a/include/grub/zfs/zap_leaf.h +++ b/include/grub/zfs/zap_leaf.h @@ -70,7 +70,6 @@ typedef struct zap_leaf_phys { */ grub_uint16_t l_hash[0]; - grub_properly_aligned_t l_entries[0]; } zap_leaf_phys_t; typedef union zap_leaf_chunk { From 53d189d6a6ddb91b62cbdc2df6448ae5ce2eb066 Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Thu, 7 Nov 2013 00:48:04 +0100 Subject: [PATCH 16/21] * grub-core/fs/reiserfs.c (grub_reiserfs_iterate_dir): Fix type of entry_type. --- grub-core/fs/reiserfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/fs/reiserfs.c b/grub-core/fs/reiserfs.c index 26adf23c..321b6b35 100644 --- a/grub-core/fs/reiserfs.c +++ b/grub-core/fs/reiserfs.c @@ -784,7 +784,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, = grub_le_to_cpu16 (directory_header->state); grub_fshelp_node_t entry_item; struct grub_reiserfs_key entry_key; - enum grub_reiserfs_item_type entry_type; + enum grub_fshelp_filetype entry_type; char *entry_name; if (!(entry_state & GRUB_REISERFS_VISIBLE_MASK)) From 91650b545b2170f1eba5c18be59cbba2d171a04e Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Thu, 7 Nov 2013 00:57:21 +0100 Subject: [PATCH 17/21] * grub-core/disk/geli.c (geli_rekey): Fix error return type. --- grub-core/disk/geli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/disk/geli.c b/grub-core/disk/geli.c index f9315df0..328b8c67 100644 --- a/grub-core/disk/geli.c +++ b/grub-core/disk/geli.c @@ -153,7 +153,7 @@ geli_rekey (struct grub_cryptodisk *dev, grub_uint64_t zoneno) gcry_err = grub_crypto_hmac_buffer (dev->hash, dev->rekey_key, 64, &tohash, sizeof (tohash), key); if (gcry_err) - return grub_crypto_gcry_error (gcry_err); + return gcry_err; return grub_cryptodisk_setkey (dev, (grub_uint8_t *) key, dev->rekey_derived_size); From ca6da85ca77d9457f05972fe964b8677dd486645 Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Sun, 3 Jul 2022 14:54:24 +0000 Subject: [PATCH 18/21] * grub-core/fs/zfs/zfscrypt.c (grub_ccm_decrypt): Return right error type Cherry-picked from upstream commit 8b66bb5d8d347a537738 ("* grub-core/fs/zfs/zfscrypt.c (grub_ccm_decrypt): Return right error type") Signed-off-by: Ani Sinha --- grub-core/fs/zfs/zfscrypt.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/grub-core/fs/zfs/zfscrypt.c b/grub-core/fs/zfs/zfscrypt.c index 4ea53b86..1b368087 100644 --- a/grub-core/fs/zfs/zfscrypt.c +++ b/grub-core/fs/zfs/zfscrypt.c @@ -143,7 +143,7 @@ grub_ccm_decrypt (grub_crypto_cipher_handle_t cipher, return err; if (mac_out) grub_crypto_xor (mac_out, mac, mul, m); - return GRUB_ERR_NONE; + return GPG_ERR_NO_ERROR; } static void @@ -244,7 +244,7 @@ grub_gcm_decrypt (grub_crypto_cipher_handle_t cipher, if (mac_out) grub_crypto_xor (mac_out, mac, mac_xor, m); - return GRUB_ERR_NONE; + return GPG_ERR_NO_ERROR; } @@ -263,8 +263,7 @@ algo_decrypt (grub_crypto_cipher_handle_t cipher, grub_uint64_t algo, return grub_gcm_decrypt (cipher, out, in, psize, mac_out, nonce, 15 - l, m); default: - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "algorithm %" - PRIuGRUB_UINT64_T " is not supported yet", algo); + return GPG_ERR_CIPHER_ALGO; } } @@ -279,7 +278,7 @@ grub_zfs_decrypt_real (grub_crypto_cipher_handle_t cipher, grub_uint32_t mac[4]; unsigned i; grub_uint32_t sw[4]; - grub_err_t err; + gcry_err_code_t err; grub_memcpy (sw, nonce, 16); if (endian != GRUB_ZFS_BIG_ENDIAN) @@ -295,7 +294,7 @@ grub_zfs_decrypt_real (grub_crypto_cipher_handle_t cipher, size, mac, sw + 1, 3, 12); if (err) - return err; + return grub_crypto_gcry_error (err); for (i = 0; i < 3; i++) if (grub_zfs_to_cpu32 (expected_mac[i], endian) From 58488d1ad038f894be983d5b15a4fc9b0967571e Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Thu, 7 Nov 2013 00:45:15 +0100 Subject: [PATCH 19/21] * grub-core/bus/usb/ehci.c (grub_ehci_restore_hw): Return right enum type. (grub_ehci_fini_hw): Likewise. * grub-core/bus/usb/usbhub.c (grub_usb_add_hub): Likewise. --- grub-core/bus/usb/ehci.c | 9 +++++---- grub-core/bus/usb/usbhub.c | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/grub-core/bus/usb/ehci.c b/grub-core/bus/usb/ehci.c index b7005192..19732fa0 100644 --- a/grub-core/bus/usb/ehci.c +++ b/grub-core/bus/usb/ehci.c @@ -28,6 +28,7 @@ #include #include #include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -1259,7 +1260,7 @@ grub_ehci_setup_transfer (grub_usb_controller_t dev, if ((transfer->dev->speed != GRUB_USB_SPEED_HIGH) && !transfer->dev->hubaddr) { - grub_error (GRUB_USB_ERR_BADDEVICE, + grub_error (GRUB_ERR_BAD_DEVICE, "FULL/LOW speed device on EHCI port!?!"); return GRUB_USB_ERR_BADDEVICE; } @@ -1719,7 +1720,7 @@ grub_ehci_portstatus (grub_usb_controller_t dev, /* FULL speed device connected - change port ownership. * It results in disconnected state of this EHCI port. */ grub_ehci_port_setbits (e, port, GRUB_EHCI_PORT_OWNER); - return GRUB_USB_ERR_BADDEVICE; + return GRUB_ERR_BAD_DEVICE; } /* XXX: Fix it! There is possible problem - we can say to calling @@ -1866,7 +1867,7 @@ grub_ehci_restore_hw (void) } } - return GRUB_USB_ERR_NONE; + return GRUB_ERR_NONE; } static grub_err_t @@ -1886,7 +1887,7 @@ grub_ehci_fini_hw (int noreturn __attribute__ ((unused))) grub_error (GRUB_ERR_TIMEOUT, "restore_hw: EHCI reset timeout"); } - return GRUB_USB_ERR_NONE; + return GRUB_ERR_NONE; } static struct grub_usb_controller_dev usb_controller = { diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c index 5fc5eba3..e4829bfc 100644 --- a/grub-core/bus/usb/usbhub.c +++ b/grub-core/bus/usb/usbhub.c @@ -181,7 +181,7 @@ grub_usb_add_hub (grub_usb_device_t dev) rescan = 1; - return GRUB_ERR_NONE; + return GRUB_USB_ERR_NONE; } static void From 2d6c16479fccf88a8b98224c958bbc61fc3dbc99 Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Thu, 7 Nov 2013 00:55:17 +0100 Subject: [PATCH 20/21] * grub-core/disk/usbms.c (grub_usbms_cbi_cmd): Fix error type. (grub_usbms_cbi_reset): Likewise. (grub_usbms_bo_reset): Likewise. (grub_usbms_reset): Likewise. (grub_usbms_attach): Likewise. (grub_usbms_transfer_cbi): Likewise. --- grub-core/disk/usbms.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/grub-core/disk/usbms.c b/grub-core/disk/usbms.c index 52cc33e9..68f30f28 100644 --- a/grub-core/disk/usbms.c +++ b/grub-core/disk/usbms.c @@ -76,7 +76,7 @@ typedef struct grub_usbms_dev *grub_usbms_dev_t; static grub_usbms_dev_t grub_usbms_devices[MAX_USBMS_DEVICES]; static int first_available_slot = 0; -static grub_err_t +static grub_usb_err_t grub_usbms_cbi_cmd (grub_usb_device_t dev, int interface, grub_uint8_t *cbicb) { @@ -86,7 +86,7 @@ grub_usbms_cbi_cmd (grub_usb_device_t dev, int interface, GRUB_USBMS_CBI_CMD_SIZE, (char*)cbicb); } -static grub_err_t +static grub_usb_err_t grub_usbms_cbi_reset (grub_usb_device_t dev, int interface) { /* Prepare array with Command Block Reset (=CBR) */ @@ -108,17 +108,17 @@ grub_usbms_cbi_reset (grub_usb_device_t dev, int interface) return grub_usbms_cbi_cmd (dev, interface, (grub_uint8_t *)&cbicb); } -static grub_err_t +static grub_usb_err_t grub_usbms_bo_reset (grub_usb_device_t dev, int interface) { grub_usb_err_t u; u = grub_usb_control_msg (dev, 0x21, 255, 0, interface, 0, 0); if (u) - return grub_error (GRUB_ERR_IO, "USB error %d", u); - return GRUB_ERR_NONE; + return u; + return GRUB_USB_ERR_NONE; } -static grub_err_t +static grub_usb_err_t grub_usbms_reset (grub_usbms_dev_t dev) { if (dev->protocol == GRUB_USBMS_PROTOCOL_BULK) @@ -149,7 +149,7 @@ grub_usbms_attach (grub_usb_device_t usbdev, int configno, int interfno) int j; grub_uint8_t luns = 0; unsigned curnum; - grub_usb_err_t err = GRUB_ERR_NONE; + grub_usb_err_t err = GRUB_USB_ERR_NONE; if (first_available_slot == ARRAY_SIZE (grub_usbms_devices)) return 0; @@ -567,7 +567,11 @@ grub_usbms_transfer_cbi (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd, } } - return err; + + if (err) + return grub_error (GRUB_ERR_IO, "USB error %d", err); + + return GRUB_ERR_NONE; } From 7f69537ee21e60750f308113a25197aec5a505bc Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Thu, 7 Jul 2022 13:32:12 +0530 Subject: [PATCH 21/21] grub-mkimage: make it link statically so that it can be used on any host grub-mkimage is used by grub-mkrescue which in turn is used to generate the bios bits iso file. We need to ensure that grub-mkimage can run on any host, even on those that have an earlier version of glibc installed. Hence, we make it statically linked executable so that the exact version of libraries that are available on the host where its run does not matter. Thus issues such as the following can be avoided when executed: grub-mkimage: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found Signed-off-by: Ani Sinha --- Makefile.util.def | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.util.def b/Makefile.util.def index b80187c8..a9974724 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -157,6 +157,7 @@ program = { ldadd = '$(LIBLZMA)'; ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)'; cppflags = '-DGRUB_PKGLIBDIR=\"$(pkglibdir)\"'; + cflags = '-static'; }; program = {