The linking phase fails for the version 0.10.3 with '-02' and '-O3': x86_64-pc-linux-gnu-ld -o refind_x64.dll -n -q --gc-sections -nostdlib --script=/usr/lib/GccBase.lds --defsym=PECOFF_HEADER_SIZE=0x228 --entry efi_main -u efi_main -m elf_x86_64 \ -L /usr/lib --start-group -lBaseDebugPrintErrorLevelLib -lBasePrintLib -lBasePcdLibNull -lUefiDebugLibStdErr -lBaseLib -lBaseMemoryLib -lUefiBootServicesTableLib -lUefiMemoryAllocationLib -lUefiRuntimeServicesTableLib -lUefiDevicePathLib -lUefiLib -lPeCoffExtraActionLibNull -lUefiApplicationEntryPoint -lDxeServicesLib -lDxeServicesTableLib -lDxeHobLib -lBasePeCoffLib apple.obj config.obj mystrings.obj line_edit.obj driver_support.obj icns.obj lib.obj main.obj menu.obj screen.obj gpt.obj crc32.obj legacy.obj AutoGen.obj ../libeg/libeg.lib \ ../EfiLib/EfiLib.lib ../mok/mok.lib --end-group ../libeg/libeg.lib(lodepng.obj): In function `lodepng_state_copy': lodepng.c:(.text+0x4f65): undefined reference to `memcpy' Make.tiano:48: recipe for target 'refind_x64.dll' failed make[1]: *** [refind_x64.dll] Error 1 make[1]: Leaving directory '/var/tmp/portage/sys-boot/refind-0.10.3/work/refind-0.10.3/refind' Makefile:54: recipe for target 'tiano' failed make: *** [tiano] Error 2 This is likely due to gcc inserting mem* functions as part of its optimizations and us linking with '-nostdlib'. Overriding with '-Os' as done by the upstream seems like a good workaround for the issue for now. This bug is filed prior to the commit that will introduce the version 0.10.3 to the tree so it can be referenced in the ebuild.
This problem should become not applicable with the PR: https://github.com/gentoo/gentoo/pull/2754
As an EFI application is not a Linux application, it is nonesence to use user defined CFLAGS and LDFLAGS. So the problem is fixed by using only upstream defined flags. Note that adventurers can use the custom-cflags flag when merging refind to force refind using user defined CFLAGS, but this is unsupported.