commit:     ebaac45475e2dbf861838769c38459dd6275d1b6
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri May  3 05:00:53 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May  3 05:05:43 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ebaac454

sys-boot/gnu-efi: fix Clang build, backport refind fixes

Closes: https://bugs.gentoo.org/930538
Signed-off-by: Sam James <sam <AT> gentoo.org>

 sys-boot/gnu-efi/files/gnu-efi-3.0.18-clang.patch  |  26 +++++
 sys-boot/gnu-efi/files/gnu-efi-3.0.18-refind.patch | 126 +++++++++++++++++++++
 sys-boot/gnu-efi/gnu-efi-3.0.18-r1.ebuild          |  90 +++++++++++++++
 3 files changed, 242 insertions(+)

diff --git a/sys-boot/gnu-efi/files/gnu-efi-3.0.18-clang.patch 
b/sys-boot/gnu-efi/files/gnu-efi-3.0.18-clang.patch
new file mode 100644
index 000000000000..7819351928c5
--- /dev/null
+++ b/sys-boot/gnu-efi/files/gnu-efi-3.0.18-clang.patch
@@ -0,0 +1,26 @@
+https://bugs.gentoo.org/930538
+https://github.com/ncroxon/gnu-efi/issues/4
+https://github.com/ncroxon/gnu-efi/pull/5
+https://github.com/ncroxon/gnu-efi/commit/a0111e0df165d49cf34fc4f5fae46fc0921a756d
+
+From a0111e0df165d49cf34fc4f5fae46fc0921a756d Mon Sep 17 00:00:00 2001
+From: Callum Farmer <[email protected]>
+Date: Wed, 24 Apr 2024 12:04:48 +0100
+Subject: [PATCH] Disable RELRO
+
+No point having PT_GNU_RELRO as ELF data won't exist when merging into PE32+ 
file
+
+Unbreaks lld usage which complains about linker script
+Fixes ncroxon/gnu-efi#4
+--- a/Make.defaults
++++ b/Make.defaults
+@@ -199,7 +199,7 @@ endif
+ ARFLAGS := rDv
+ ASFLAGS += $(ARCH3264)
+ LDFLAGS       += -nostdlib --warn-common --no-undefined --fatal-warnings \
+-         --build-id=sha1 -z nocombreloc
++         --build-id=sha1 -z nocombreloc -z norelro
+ 
+ ifneq ($(ARCH),arm)
+ export LIBGCC=$(shell $(CC) $(CFLAGS) $(ARCH3264) -print-libgcc-file-name)
+

diff --git a/sys-boot/gnu-efi/files/gnu-efi-3.0.18-refind.patch 
b/sys-boot/gnu-efi/files/gnu-efi-3.0.18-refind.patch
new file mode 100644
index 000000000000..d198426c4635
--- /dev/null
+++ b/sys-boot/gnu-efi/files/gnu-efi-3.0.18-refind.patch
@@ -0,0 +1,126 @@
+https://github.com/ncroxon/gnu-efi/commit/f5bb548df572c992fe3389a586bec3a19b092c18
+https://github.com/ncroxon/gnu-efi/commit/6b9dae0bef0fab82230a6672eaadd38d739e3e1e
+
+From f5bb548df572c992fe3389a586bec3a19b092c18 Mon Sep 17 00:00:00 2001
+From: Callum Farmer <[email protected]>
+Date: Thu, 25 Apr 2024 15:27:26 +0100
+Subject: [PATCH] Align RTLIB CopyMem/SetMem with normal versions
+
+Looks like 699e452654df6de53890ae994756b0d47237e3ac broke rEFInd
+(https://sourceforge.net/p/refind/code/ci/189e405630293445df8565e36b831bba56e87093/)
+--- a/inc/efirtlib.h
++++ b/inc/efirtlib.h
+@@ -45,6 +45,7 @@ RtZeroMem (
+     );
+ 
+ VOID
++EFIAPI
+ RUNTIMEFUNCTION
+ RtSetMem (
+     IN VOID     *Buffer,
+@@ -53,10 +54,11 @@ RtSetMem (
+     );
+ 
+ VOID
++EFIAPI
+ RUNTIMEFUNCTION
+ RtCopyMem (
+     IN VOID     *Dest,
+-    IN CONST VOID     *Src,
++    IN VOID     *Src,
+     IN UINTN    len
+     );
+ 
+--- a/lib/runtime/efirtlib.c
++++ b/lib/runtime/efirtlib.c
+@@ -42,6 +42,7 @@ RtZeroMem (
+ #pragma RUNTIME_CODE(RtSetMem)
+ #endif
+ VOID
++EFIAPI
+ RUNTIMEFUNCTION
+ RtSetMem (
+     IN VOID     *Buffer,
+@@ -61,10 +62,11 @@ RtSetMem (
+ #pragma RUNTIME_CODE(RtCopyMem)
+ #endif
+ VOID
++EFIAPI
+ RUNTIMEFUNCTION
+ RtCopyMem (
+     IN VOID        *Dest,
+-    IN CONST VOID  *Src,
++    IN VOID  *Src,
+     IN UINTN       len
+     )
+ {
+
+From 6b9dae0bef0fab82230a6672eaadd38d739e3e1e Mon Sep 17 00:00:00 2001
+From: Callum Farmer <[email protected]>
+Date: Sat, 27 Apr 2024 13:14:28 +0100
+Subject: [PATCH] Fixup string functions for new CopyMem
+
+Signed-off-by: Callum Farmer <[email protected]>
+--- a/lib/runtime/rtstr.c
++++ b/lib/runtime/rtstr.c
+@@ -69,10 +69,13 @@ RtStrnCpy (
+     )
+ // copy strings
+ {
++    CHAR16 CopySrc = *Src;
++    CHAR16 *PCopySrc = &CopySrc;
++    
+     UINTN Size = RtStrnLen(Src, Len);
+     if (Size != Len)
+         RtSetMem(Dest + Size, (Len - Size) * sizeof(CHAR16), '\0');
+-    RtCopyMem(Dest, Src, Size * sizeof(CHAR16));
++    RtCopyMem(Dest, PCopySrc, Size * sizeof(CHAR16));
+ }
+ 
+ #ifndef __GNUC__
+@@ -105,10 +108,13 @@ RtStpnCpy (
+     )
+ // copy strings
+ {
++    CHAR16 CopySrc = *Src;
++    CHAR16 *PCopySrc = &CopySrc;
++    
+     UINTN Size = RtStrnLen(Src, Len);
+     if (Size != Len)
+         RtSetMem(Dest + Size, (Len - Size) * sizeof(CHAR16), '\0');
+-    RtCopyMem(Dest, Src, Size * sizeof(CHAR16));
++    RtCopyMem(Dest, PCopySrc, Size * sizeof(CHAR16));
+     return Dest + Size;
+ }
+ 
+@@ -137,10 +143,12 @@ RtStrnCat (
+     )
+ {
+     UINTN DestSize, Size;
++    CHAR16 CopySrc = *Src;
++    CHAR16 *PCopySrc = &CopySrc;
+ 
+     DestSize = RtStrLen(Dest);
+     Size = RtStrnLen(Src, Len);
+-    RtCopyMem(Dest + DestSize, Src, Size * sizeof(CHAR16));
++    RtCopyMem(Dest + DestSize, PCopySrc, Size * sizeof(CHAR16));
+     Dest[DestSize + Size] = '\0';
+ }
+ 
+--- a/lib/str.c
++++ b/lib/str.c
+@@ -201,11 +201,13 @@ StrDuplicate (
+ {
+     CHAR16      *Dest;
+     UINTN       Size;
++    CHAR16      CopySrc = *Src;
++    CHAR16      *PCopySrc = &CopySrc;
+ 
+     Size = StrSize(Src);
+     Dest = AllocatePool (Size);
+     if (Dest) {
+-        CopyMem (Dest, (void *)Src, Size);
++        CopyMem (Dest, PCopySrc, Size);
+     }
+     return Dest;
+ }

diff --git a/sys-boot/gnu-efi/gnu-efi-3.0.18-r1.ebuild 
b/sys-boot/gnu-efi/gnu-efi-3.0.18-r1.ebuild
new file mode 100644
index 000000000000..e54e5b583eef
--- /dev/null
+++ b/sys-boot/gnu-efi/gnu-efi-3.0.18-r1.ebuild
@@ -0,0 +1,90 @@
+# Copyright 2004-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+inherit toolchain-funcs
+
+DESCRIPTION="Library for build EFI Applications"
+HOMEPAGE="https://sourceforge.net/projects/gnu-efi/";
+SRC_URI="https://downloads.sourceforge.net/gnu-efi/${P}.tar.bz2";
+
+# inc/, lib/ dirs (README.efilib)
+# - BSD-2
+# gnuefi dir:
+# - BSD (3-cluase): crt0-efi-ia32.S
+# - GPL-2+ : setjmp_ia32.S
+LICENSE="GPL-2+ BSD BSD-2"
+SLOT="0"
+KEYWORDS="-* ~amd64 ~arm ~arm64 ~ia64 ~riscv ~x86"
+IUSE="abi_x86_32 abi_x86_64 custom-cflags"
+REQUIRED_USE="
+       amd64? ( || ( abi_x86_32 abi_x86_64 ) )
+       x86? ( || ( abi_x86_32 abi_x86_64 ) )
+"
+
+# These objects get run early boot (i.e. not inside of Linux),
+# so doing these QA checks on them doesn't make sense.
+QA_EXECSTACK="usr/*/lib*efi.a:* usr/*/crt*.o"
+RESTRICT="strip"
+
+PATCHES=(
+       "${FILESDIR}"/${P}-clang.patch
+       "${FILESDIR}"/${P}-refind.patch
+)
+
+src_prepare() {
+       default
+       sed -i -e "s/-Werror//" Make.defaults || die
+}
+
+efimake() {
+       local arch=
+       case ${CHOST} in
+               arm*) arch=arm ;;
+               aarch64*) arch=aarch64 ;;
+               ia64*) arch=ia64 ;;
+               i?86*) arch=ia32 ;;
+               riscv64*) arch=riscv64;;
+               x86_64*) arch=x86_64 ;;
+               *) die "Unknown CHOST" ;;
+       esac
+
+       local args=(
+               ARCH="${arch}"
+               HOSTCC="${BUILD_CC}"
+               CC="${CC}"
+               AS="${AS}"
+               LD="${LD}"
+               AR="${AR}"
+               OBJCOPY="${OBJCOPY}"
+               PREFIX="${EPREFIX}/usr"
+               LIBDIR='$(PREFIX)'/$(get_libdir)
+       )
+       emake -j1 "${args[@]}" "$@"
+}
+
+src_compile() {
+       tc-export BUILD_CC AR AS CC LD OBJCOPY
+
+       if ! use custom-cflags; then
+               unset CFLAGS CPPFLAGS LDFLAGS
+       fi
+
+       if use amd64 || use x86; then
+               use abi_x86_32 && CHOST=i686 ABI=x86 efimake
+               use abi_x86_64 && CHOST=x86_64 ABI=amd64 efimake
+       else
+               efimake
+       fi
+}
+
+src_install() {
+       if use amd64 || use x86; then
+               use abi_x86_32 && CHOST=i686 ABI=x86 efimake INSTALLROOT="${D}" 
install
+               use abi_x86_64 && CHOST=x86_64 ABI=amd64 efimake 
INSTALLROOT="${D}" install
+       else
+               efimake INSTALLROOT="${D}" install
+       fi
+       einstalldocs
+}

Reply via email to