summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Trofimovich <slyfox@gentoo.org>2018-02-17 19:41:37 +0000
committerSergei Trofimovich <slyfox@gentoo.org>2018-02-17 19:41:54 +0000
commit4e5016fe999d1e38f3ba606c977bcea43451ac05 (patch)
tree19a2cea51cae7099c8fdc5b1c5348bc8184b381f /dev-libs
parentapp-emulation/qemu: bug #647570 (diff)
downloadgentoo-4e5016fe999d1e38f3ba606c977bcea43451ac05.tar.gz
gentoo-4e5016fe999d1e38f3ba606c977bcea43451ac05.tar.bz2
gentoo-4e5016fe999d1e38f3ba606c977bcea43451ac05.zip
dev-libs/libffi: fix small struct handling on ia64, bug #634190
Bug: https://github.com/libffi/libffi/pull/407 Closes: https://bugs.gentoo.org/634190 Package-Manager: Portage-2.3.24, Repoman-2.3.6
Diffstat (limited to 'dev-libs')
-rw-r--r--dev-libs/libffi/files/libffi-3.2.1-ia64-small-struct.patch74
-rw-r--r--dev-libs/libffi/libffi-3.2.1-r2.ebuild70
2 files changed, 144 insertions, 0 deletions
diff --git a/dev-libs/libffi/files/libffi-3.2.1-ia64-small-struct.patch b/dev-libs/libffi/files/libffi-3.2.1-ia64-small-struct.patch
new file mode 100644
index 000000000000..6e21f3566bc9
--- /dev/null
+++ b/dev-libs/libffi/files/libffi-3.2.1-ia64-small-struct.patch
@@ -0,0 +1,74 @@
+From b58caef7fd620408be9239ac24ea89d5bc84f30b Mon Sep 17 00:00:00 2001
+From: Sergei Trofimovich <slyfox@gentoo.org>
+Date: Sat, 17 Feb 2018 19:00:40 +0000
+Subject: [PATCH 2/2] ia64: fix small struct return
+
+This change fixes libffi.call/struct10.c failure on ia64:
+FAIL: libffi.call/struct10.c -W -Wall -Wno-psabi -O0 execution test
+
+.Lst_small_struct handles returns for structs less than 32 bytes
+(following ia64 return value ABI [1]). Subroutine does roughly the
+following:
+
+```
+ mov [sp+0] = r8
+ mov [sp+8] = r9
+ mov [sp+16] = r10
+ mov [sp+24] = r11
+ memcpy(destination, source=sp, 12);
+```
+
+The problem: ia64 ABI guarantees that top 16 bytes of stack are
+scratch space for callee function. Thus it can clobber it. [1]
+says (7.1 Procedure Frames):
+"""
+* Scratch area. This 16-byte region is provided as scratch storage
+ for procedures that are called by the current procedure. Leaf
+ procedures do not need to allocate this region. A procedure may
+ use the 16 bytes at the top of its own frame as scratch memory,
+ but the contents of this area are not preserved by a procedure call.
+"""
+
+In our case 16 top bytes are clobbered by a PLT resolver when memcpy()
+is called for the first time. As a result memcpy implementation reads
+already clobbered data frop top of stack.
+
+The fix is simple: allocate 16 bytes of scrats space prior to memcpy()
+call.
+
+[1]: https://www.intel.com/content/dam/www/public/us/en/documents/guides/itanium-software-runtime-architecture-guide.pdf
+
+Bug: https://bugs.gentoo.org/634190
+Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
+---
+ src/ia64/unix.S | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/src/ia64/unix.S b/src/ia64/unix.S
+index 4733377..e2547e0 100644
+--- a/src/ia64/unix.S
++++ b/src/ia64/unix.S
+@@ -175,7 +175,6 @@ ffi_call_unix:
+ ;;
+
+ .Lst_small_struct:
+- add sp = -16, sp
+ cmp.lt p6, p0 = 8, in3
+ cmp.lt p7, p0 = 16, in3
+ cmp.lt p8, p0 = 24, in3
+@@ -191,6 +190,12 @@ ffi_call_unix:
+ (p8) st8 [r18] = r11
+ mov out1 = sp
+ mov out2 = in3
++ ;;
++ // ia64 software calling convention requires
++ // top 16 bytes of stack to be scratch space
++ // PLT resolver uses that scratch space at
++ // 'memcpy' symbol reolution time
++ add sp = -16, sp
+ br.call.sptk.many b0 = memcpy#
+ ;;
+ mov ar.pfs = loc0
+--
+2.16.1
+
diff --git a/dev-libs/libffi/libffi-3.2.1-r2.ebuild b/dev-libs/libffi/libffi-3.2.1-r2.ebuild
new file mode 100644
index 000000000000..533e9afa08e2
--- /dev/null
+++ b/dev-libs/libffi/libffi-3.2.1-r2.ebuild
@@ -0,0 +1,70 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+inherit eutils libtool multilib multilib-minimal toolchain-funcs
+
+DESCRIPTION="a portable, high level programming interface to various calling conventions"
+HOMEPAGE="https://sourceware.org/libffi/"
+SRC_URI="ftp://sourceware.org/pub/${PN}/${P}.tar.gz"
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~ppc-aix ~x64-cygwin ~amd64-fbsd ~x86-fbsd ~amd64-linux ~arm-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
+IUSE="debug pax_kernel static-libs test"
+
+RDEPEND="abi_x86_32? ( !<=app-emulation/emul-linux-x86-baselibs-20130224-r1
+ !app-emulation/emul-linux-x86-baselibs[-abi_x86_32(-)] )"
+DEPEND="test? ( dev-util/dejagnu )"
+
+DOCS="ChangeLog* README"
+
+PATCHES=(
+ "${FILESDIR}"/${PN}-3.2.1-o-tmpfile-eacces.patch #529044
+ "${FILESDIR}"/${PN}-3.2.1-complex_alpha.patch
+ "${FILESDIR}"/${PN}-3.1-darwin-x32.patch
+ "${FILESDIR}"/${PN}-3.2.1-complex-ia64.patch
+ "${FILESDIR}"/${PN}-3.2.1-include-path.patch
+ "${FILESDIR}"/${PN}-3.2.1-include-path-autogen.patch
+ "${FILESDIR}"/${PN}-3.2.1-ia64-small-struct.patch #634190
+)
+
+ECONF_SOURCE=${S}
+
+pkg_setup() {
+ # Check for orphaned libffi, see https://bugs.gentoo.org/354903 for example
+ if [[ ${ROOT} == "/" && ${EPREFIX} == "" ]] && ! has_version ${CATEGORY}/${PN}; then
+ local base="${T}"/conftest
+ echo 'int main() { }' > "${base}".c
+ $(tc-getCC) -o "${base}" "${base}".c -lffi >&/dev/null
+ if [ $? -eq 0 ]; then
+ eerror "The linker reported linking against -lffi to be working while it shouldn't have."
+ eerror "This is wrong and you should find and delete the old copy of libffi before continuing."
+ die "The system is in inconsistent state with unknown libffi installed."
+ fi
+ fi
+}
+
+src_prepare() {
+ default
+
+ sed -i -e 's:@toolexeclibdir@:$(libdir):g' Makefile.in || die #462814
+ elibtoolize
+}
+
+multilib_src_configure() {
+ use userland_BSD && export HOST="${CHOST}"
+ # python does not like miltilib-wrapped headers: bug #643582
+ # thus we install includes into ABI-specific paths
+ local includes="${EPREFIX}"/usr/$(get_libdir)/${P}/include/
+ econf \
+ $(use_enable static-libs static) \
+ $(use_enable pax_kernel pax_emutramp) \
+ $(use_enable debug) \
+ --includedir="${includes}"
+}
+
+multilib_src_install_all() {
+ prune_libtool_files
+ einstalldocs
+}