grub/util
Peter Jones ebc825b549 mkimage: avoid copying relocations for sections that won't be copied.
Some versions of gcc include a plugin called "annobin", and in some
build systems this is enabled by default.  This plugin creates special
ELF note sections to track which ABI-breaking features are used by a
binary, as well as a series of relocations to annotate where.

If grub is compiled with this feature, then when grub-mkimage translates
the binary to another file format which does not strongly associate
relocation data with sections (i.e. when platform is *-efi), these
relocations appear to be against the .text section rather than the
original note section.  When the binary is loaded by the PE runtime
loader, hilarity ensues.

This issue is not necessarily limited to the annobin, but could arise
any time there are relocations in sections that are not represented in
grub-mkimage's output.

This patch seeks to avoid this issue by only including relocations that
refer to sections which will be included in the final binary.

As an aside, this should also obviate the need to avoid -funwind-tables,
-fasynchronous-unwind-tables, and any sections similar to .eh_frame in
the future.  I've tested it on x86-64-efi with the following gcc command
line options (as recorded by -grecord-gcc-flags), but I still need to
test the result on some other platforms that have been problematic in
the past (especially ARM Aarch64) before I feel comfortable making
changes to the configure.ac bits:

GNU C11 7.2.1 20180116 (Red Hat 7.2.1-7) -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow -msoft-float -mno-stack-arg-probe -mcmodel=large -mno-red-zone -m64 -mtune=generic -march=x86-64 -g3 -Os -freg-struct-return -fno-stack-protector -ffreestanding -funwind-tables -fasynchronous-unwind-tables -fno-strict-aliasing -fstack-clash-protection -fno-ident -fplugin=annobin

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2018-03-05 14:08:09 +01:00
..
bash-completion.d
grub.d Keep the native terminal active when enabling gfxterm 2018-01-29 12:51:03 +01:00
i386/efi
ieee1275 ieee1275: Fix segfault in grub-ofpathname 2017-12-06 12:55:55 +01:00
bin2h.c
config.c
editenv.c
garbage-gen.c
getroot.c
glue-efi.c Build fixes for argp.h with older gcc. 2013-12-21 18:08:25 +01:00
grub-editenv.c
grub-file.c
grub-fstest.c
grub-gen-asciih.c
grub-gen-widthspec.c
grub-glue-efi.c
grub-install-common.c
grub-install.c Make grub-install check for errors from efibootmgr 2018-02-14 18:02:01 +01:00
grub-kbdcomp.in
grub-macbless.c
grub-macho2img.c * util/grub-macho2img.c: Use plain fopen rather than grub_util_fopen. 2013-11-11 22:48:43 +01:00
grub-menulst2cfg.c
grub-mkconfig.in
grub-mkconfig_lib.in grub-mkconfig: Fix detecting .sig files as system images 2017-12-06 12:58:54 +01:00
grub-mkfont.c
grub-mkimage.c
grub-mkimage32.c mkimage: make it easier to run syntax checkers on grub-mkimagexx.c 2018-03-05 13:44:55 +01:00
grub-mkimage64.c mkimage: make it easier to run syntax checkers on grub-mkimagexx.c 2018-03-05 13:44:55 +01:00
grub-mkimagexx.c mkimage: avoid copying relocations for sections that won't be copied. 2018-03-05 14:08:09 +01:00
grub-mklayout.c
grub-mknetdir.c
grub-mkpasswd-pbkdf2.c
grub-mkrelpath.c
grub-mkrescue.c
grub-mkstandalone.c
grub-module-verifier.c x86-64: Treat R_X86_64_PLT32 as R_X86_64_PC32 2018-02-23 22:25:30 +01:00
grub-module-verifier32.c
grub-module-verifier64.c
grub-module-verifierXX.c
grub-mount.c
grub-pe2elf.c
grub-probe.c
grub-reboot.in
grub-render-label.c
grub-script-check.c
grub-set-default.in
grub-setup.c
grub-syslinux2cfg.c
import_gcry.py
import_gcrypth.sed
import_unicode.py
misc.c
mkimage.c
probe.c
render-label.c
resolve.c
setup.c sparc64: Add blocklist GPT support for SPARC 2018-02-14 17:42:56 +01:00
setup_bios.c
setup_sparc.c
spkmodem-recv.c