-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
grub: Changes towards building bits on a newer compiler #1
Open
ani-sinha
wants to merge
21
commits into
biosbits:bits
Choose a base branch
from
ani-sinha:bits
base: bits
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add sysmacros.h to make gcc happy. Signed-off-by: Ani Sinha <[email protected]>
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 <[email protected]> Signed-off-by: Simon Hardy <[email protected]> Reviewed-by: Daniel Kiper <[email protected]>
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 <[email protected]> Signed-off-by: H.J. Lu <[email protected]> Reviewed-by: Daniel Kiper <[email protected]>
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 <[email protected]>
Ignore gcc warning -Wunused-value that causes build failure on newer compiler. Signed-off-by: Ani Sinha <[email protected]>
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 <[email protected]>
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 <[email protected]>
ani-sinha
force-pushed
the
bits
branch
4 times, most recently
from
July 4, 2022 05:29
ebb4294
to
50c22e2
Compare
…nteed ported from upstream commit: 316dda716c046 ("Introduce grub_efi_packed_guid and use it where alignment is not guranteed") Signed-off-by: Ani Sinha <[email protected]>
…inker 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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <unknown> 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 <[email protected]> Reviewed-by: Daniel Kiper <[email protected]>
Definition of GRUB_PACKED was missing. Added it. Signed-off-by: Ani Sinha <[email protected]>
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 '<unknown>' 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 <[email protected]> Reviewed-by: Daniel Kiper <[email protected]>
…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 <[email protected]>
…type. (grub_ehci_fini_hw): Likewise. * grub-core/bus/usb/usbhub.c (grub_usb_add_hub): Likewise.
…usbms_cbi_reset): Likewise. (grub_usbms_bo_reset): Likewise. (grub_usbms_reset): Likewise. (grub_usbms_attach): Likewise. (grub_usbms_transfer_cbi): Likewise.
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 <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These are all the changes that were needed to build grub on a newer gcc compiler, version 9.4.0