Bug 2123772 - Bundle libffi to unblock enablement of "static trampolines"
Summary: Bundle libffi to unblock enablement of "static trampolines"
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: ghc8.10
Version: 38
Hardware: Unspecified
OS: Unspecified
medium
unspecified
Target Milestone: ---
Assignee: Jens Petersen
QA Contact:
URL:
Whiteboard:
Depends On: 2174157
Blocks: 2040380
TreeView+ depends on / blocked
 
Reported: 2022-09-02 15:04 UTC by Vít Ondruch
Modified: 2023-07-04 09:06 UTC (History)
2 users (show)

Fixed In Version: ghc8.10-8.10.7-10.fc38
Clone Of:
Environment:
Last Closed: 2023-07-04 09:06:20 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker FC-648 0 None None None 2022-11-05 10:48:52 UTC

Description Vít Ondruch 2022-09-02 15:04:23 UTC
Description of problem:
In Ruby, we are fighting with "random" test crashes since libffi 3.4.2 was introduced into Fedora. We was told that the issue could be fixed by enabling "static trampolines" in libffi, but this is blocked by GHC. One of the possibilities to move forward with this could be temporary bundling libffi in GHC as was suggested in bug 2040380 comment 24. Is that something acceptable for GHC?



Version-Release number of selected component (if applicable):
ghc-8.10.7-121.fc37


How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:
GHC block enablement of static trampolines in libffi

Expected results:
GHC does not block enablement static trampolines in libffi


Additional info:
I have tried this patch to enable bundled libffi:

~~~
$ git diff
diff --git a/ghc.spec b/ghc.spec
index 6fe2e2f..7a4f90f 100644
--- a/ghc.spec
+++ b/ghc.spec
@@ -40,6 +40,13 @@
 # no longer build testsuite (takes time and not really being used)
 %bcond_with testsuite
 
+# Currently, there are issues with libffi and cloures. Static tramplines could
+# help with this, but they are disabled due to GHC. Therefore, temporary use
+# bundled libffi for GHC and let enable static tramplines for libffi.
+# https://bugzilla.redhat.com/show_bug.cgi?id=2040380
+# https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6155
+%bcond_without system_libffi
+
 # 8.10 can use llvm 9-12
 %global llvm_major 11
 %global ghc_llvm_archs armv7hl aarch64
@@ -117,7 +124,7 @@ BuildRequires: ghc-transformers-devel
 BuildRequires: alex
 BuildRequires: gmp-devel
 BuildRequires: hscolour
-BuildRequires: libffi-devel
+%{?with_system_ffi:BuildRequires: libffi-devel}
 BuildRequires: make
 # for terminfo
 BuildRequires: ncurses-devel
@@ -255,7 +262,7 @@ This package provides the User Guide and Haddock manual.
 %if %{defined ghclibdir}
 %ghc_lib_subpackage -d -l BSD Cabal-3.2.1.0
 %ghc_lib_subpackage -d -l %BSDHaskellReport array-0.5.4.0
-%ghc_lib_subpackage -d -l %BSDHaskellReport -c gmp-devel%{?_isa},libffi-devel%{?_isa} base-%{base_ver}
+%ghc_lib_subpackage -d -l %BSDHaskellReport -c gmp-devel%{?_isa}%{?with_system_ffi:,libffi-devel%{?_isa}} base-%{base_ver}
 %ghc_lib_subpackage -d -l BSD binary-0.8.8.0
 %ghc_lib_subpackage -d -l BSD bytestring-0.10.12.0
 %ghc_lib_subpackage -d -l %BSDHaskellReport containers-0.6.5.1
@@ -330,7 +337,7 @@ Installing this package causes %{name}-*-prof packages corresponding to
 %patch2 -p1 -b .orig
 %patch6 -p1 -b .orig
 
-rm -r libffi-tarballs
+%{?with_system_ffi:rm -r libffi-tarballs}
 
 %ifarch armv7hl
 %patch12 -p1 -b .orig12
@@ -410,7 +417,7 @@ export CC=%{_bindir}/gcc
   --libexecdir=%{_libexecdir} --localstatedir=%{_localstatedir} \
   --sharedstatedir=%{_sharedstatedir} --mandir=%{_mandir} \
   --docdir=%{_docdir}/%{name} \
-  --with-system-libffi \
+  %{?with_system_ffi:--with-system-libffi} \
 %ifarch %{ghc_unregisterized_arches}
   --enable-unregisterised \
 %endif
~~~

Unfortunately the build failed:

~~~
checking dynamic linker characteristics... sed -e 's|\\|/|g' -e 's| /$| \\|' -e "1s|\.o|\.dyn_o|" -e "1s|^|utils/hp2ps/|" -e "1s|utils/hp2ps/|utils/hp2ps/dist-install/build/|" -e "1s|dist-install/build/dist-install/build|dist-install/build|g" -e "s|^/builddir/build/BUILD/ghc-8.10.7/||g" utils/hp2ps/dist-install/build/.depend.c_asm.bit >> utils/hp2ps/dist-install/build/.depend.c_asm.tmp && true
echo "libraries/ghc-prim_dist-install_depfile_haskell_EXISTS = YES" >> libraries/ghc-prim/dist-install/build/.depend-v-dyn-p.haskell.tmp
for dir in libraries/ghc-prim/dist-install/build/GHC/ libraries/ghc-prim/dist-install/build/GHC/Prim/; do if test ! -d $dir; then mkdir -p $dir; fi done
"rm" -f utils/hp2ps/dist-install/build/.depend.c_asm.bit  
echo "utils/hp2ps_dist-install_depfile_c_asm_EXISTS = YES" >> utils/hp2ps/dist-install/build/.depend.c_asm.tmp
grep -v ' : [a-zA-Z]:/' libraries/ghc-prim/dist-install/build/.depend-v-dyn-p.haskell.tmp > libraries/ghc-prim/dist-install/build/.depend-v-dyn-p.haskell.tmp2
mv utils/hp2ps/dist-install/build/.depend.c_asm.tmp utils/hp2ps/dist-install/build/.depend.c_asm
sed -e '/hs$/ p' -e '/hs$/ s/o /hi /g' -e '/hs$/ s/:/ : %hi: %o /' -e '/hs$/ s/^/$(eval $(call hi-rule,/' -e '/hs$/ s/$/))/' -e '/hs-boot$/ p' -e '/hs-boot$/ s/o-boot /hi-boot /g' -e '/hs-boot$/ s/:/ : %hi-boot: %o-boot /' -e '/hs-boot$/ s/^/$(eval $(call hi-rule,/' -e '/hs-boot$/ s/$/))/' libraries/ghc-prim/dist-install/build/.depend-v-dyn-p.haskell.tmp2 > libraries/ghc-prim/dist-install/build/.depend-v-dyn-p.haskell
echo "libraries/unix_dist-install_depfile_haskell_EXISTS = YES" >> libraries/unix/dist-install/build/.depend-v-dyn-p.haskell.tmp
for dir in libraries/unix/dist-install/build/System/ libraries/unix/dist-install/build/System/Posix/ libraries/unix/dist-install/build/System/Posix/ByteString/ libraries/unix/dist-install/build/System/Posix/Directory/ libraries/unix/dist-install/build/System/Posix/DynamicLinker/ libraries/unix/dist-install/build/System/Posix/DynamicLinker/Module/ libraries/unix/dist-install/build/System/Posix/Env/ libraries/unix/dist-install/build/System/Posix/Files/ libraries/unix/dist-install/build/System/Posix/IO/ libraries/unix/dist-install/build/System/Posix/Process/ libraries/unix/dist-install/build/System/Posix/Signals/ libraries/unix/dist-install/build/System/Posix/Temp/ libraries/unix/dist-install/build/System/Posix/Terminal/; do if test ! -d $dir; then mkdir -p $dir; fi done
grep -v ' : [a-zA-Z]:/' libraries/unix/dist-install/build/.depend-v-dyn-p.haskell.tmp > libraries/unix/dist-install/build/.depend-v-dyn-p.haskell.tmp2
sed -e '/hs$/ p' -e '/hs$/ s/o /hi /g' -e '/hs$/ s/:/ : %hi: %o /' -e '/hs$/ s/^/$(eval $(call hi-rule,/' -e '/hs$/ s/$/))/' -e '/hs-boot$/ p' -e '/hs-boot$/ s/o-boot /hi-boot /g' -e '/hs-boot$/ s/:/ : %hi-boot: %o-boot /' -e '/hs-boot$/ s/^/$(eval $(call hi-rule,/' -e '/hs-boot$/ s/$/))/' libraries/unix/dist-install/build/.depend-v-dyn-p.haskell.tmp2 > libraries/unix/dist-install/build/.depend-v-dyn-p.haskell
GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking how to run the C++ preprocessor... /lib/cpp
configure: error: in `/builddir/build/BUILD/ghc-8.10.7/libffi/build/x86_64-unknown-linux-gnu':
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details
echo "libraries/haskeline_dist-install_depfile_haskell_EXISTS = YES" >> libraries/haskeline/dist-install/build/.depend-v-dyn-p.haskell.tmp
for dir in libraries/haskeline/dist-install/build/System/Console/ libraries/haskeline/dist-install/build/System/Console/Haskeline/ libraries/haskeline/dist-install/build/System/Console/Haskeline/Backend/ libraries/haskeline/dist-install/build/System/Console/Haskeline/Backend/Posix/ libraries/haskeline/dist-install/build/System/Console/Haskeline/Command/; do if test ! -d $dir; then mkdir -p $dir; fi done
grep -v ' : [a-zA-Z]:/' libraries/haskeline/dist-install/build/.depend-v-dyn-p.haskell.tmp > libraries/haskeline/dist-install/build/.depend-v-dyn-p.haskell.tmp2
sed -e '/hs$/ p' -e '/hs$/ s/o /hi /g' -e '/hs$/ s/:/ : %hi: %o /' -e '/hs$/ s/^/$(eval $(call hi-rule,/' -e '/hs$/ s/$/))/' -e '/hs-boot$/ p' -e '/hs-boot$/ s/o-boot /hi-boot /g' -e '/hs-boot$/ s/:/ : %hi-boot: %o-boot /' -e '/hs-boot$/ s/^/$(eval $(call hi-rule,/' -e '/hs-boot$/ s/$/))/' libraries/haskeline/dist-install/build/.depend-v-dyn-p.haskell.tmp2 > libraries/haskeline/dist-install/build/.depend-v-dyn-p.haskell
rts/ghc.mk:588: rts/dist/build/.depend-v-dyn-p-l-debug-thr-thr_debug-thr_l-thr_p-debug_dyn-thr_dyn-thr_debug_dyn-l_dyn-thr_l_dyn-thr_debug_p-debug_p.c_asm: No such file or directory
make[1]: *** [libffi/ghc.mk:74: libffi/stamp.ffi.static-shared.configure] Error 1
~~~

Comment 1 Jens Petersen 2022-11-05 10:28:21 UTC
Sorry, only just saw this ;-(

Okay I will start to move forward with switching ghc 8.10 to bundle libffi in Rawhide.
I think I need to request a bundling exception to avoid getting into trouble..

Comment 2 Jens Petersen 2022-11-05 10:30:49 UTC
See also bug 2080355, where this was planned (for F38).

Comment 3 Jens Petersen 2022-11-05 10:39:00 UTC
Thanks too for sketching the changes.

(In fact I already tried this once before in May for ghc9.4,
but that time I hadn't filtered out the libffi.so provides
and broke the buildroot - anyway I think this can be done properly this time.)

Comment 4 Vít Ondruch 2022-11-07 13:45:32 UTC
(In reply to Jens Petersen from comment #1)
> I think I need to request a bundling exception to avoid getting into
> trouble..

I don't think there is needed anything like this these days [1]. But of course this should not be taken lightly (which is not I guess 😉) and the `bundled()` provide is still must.

And thank you for looking into this.


[1]: https://docs.fedoraproject.org/en-US/packaging-guidelines/#bundling

Comment 5 Vít Ondruch 2022-11-07 13:47:07 UTC
BTW mentioning bug 2080355, should this ticket block it?

Comment 6 Jens Petersen 2022-12-11 04:59:37 UTC
(In reply to Vít Ondruch from comment #5)
> BTW mentioning bug 2080355, should this ticket block it?

I am not sure - actually ghc9 supports static trampolines, 
so libffi bundling should only be necessary for ghc8

Comment 7 Jens Petersen 2023-01-10 16:03:36 UTC
Bundling libffi in the current ghc8.10 has turned out to be a bit harder than I foresaw.
I think so further packaging changes are needed to accomplish that.

Comment 8 Jens Petersen 2023-01-13 12:47:01 UTC
Okay I have managed to do this locally for ghc8.10.
I am not quite ready to push it yet, but I expect it to get into F38.

Comment 9 Jens Petersen 2023-01-30 11:54:52 UTC
They should be done in ghc8.10-8.10.7-10.fc38 now in f38-build-side-62436

Comment 10 Ben Cotton 2023-02-07 15:13:57 UTC
This bug appears to have been reported against 'rawhide' during the Fedora Linux 38 development cycle.
Changing version to 38.

Comment 11 Carlos O'Donell 2023-02-28 18:26:11 UTC
(In reply to Jens Petersen from comment #9)
> They should be done in ghc8.10-8.10.7-10.fc38 now in f38-build-side-62436

Thank you very much for fixing this in ghc8.10!

I do note that ghc8.10 accidentally exported all the bundled libffi provides e.g.
https://koji.fedoraproject.org/koji/rpminfo?rpmID=33414148
~~~
libffi.so.7()(64bit)
libffi.so.7(LIBFFI_BASE_7.0)(64bit)
libffi.so.7(LIBFFI_BASE_7.1)(64bit)
libffi.so.7(LIBFFI_CLOSURE_7.0)(64bit)
libffi.so.7(LIBFFI_COMPLEX_7.0)(64bit)
libffi.so.7(LIBFFI_GO_CLOSURE_7.0)(64bit)
~~~
These should be filtered out.

I've filed this bug for the filtering:
https://bugzilla.redhat.com/show_bug.cgi?id=2174157

Comment 12 Jens Petersen 2023-03-28 11:49:10 UTC
Thanks

(Just noting for completeness that I noticed currently the old ghc:8.10 module only still exists in F38+
though it is okay to break that from my point of view - it could/should also be retired anyway probably)

Comment 13 Jens Petersen 2023-07-04 09:06:20 UTC
It is now possible to rebuild ghc8.10 in mock (probably for a while).
https://koji.fedoraproject.org/koji/taskinfo?taskID=102905839 (x86_64 perf build)

(I thought I had linked to the mock issue here but seems not,
but anyway the fixed mock that allows building ghc8.10 with systemd-nspawn
is already in the koji builder for some weeks/months now I think.)


Note You need to log in before you can comment on or make changes to this bug.