Bug 2046865 - python-cffi: FTBFS in Fedora rawhide/f36 on ppc64le
Summary: python-cffi: FTBFS in Fedora rawhide/f36 on ppc64le
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: python-cffi
Version: 36
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: ---
Assignee: Miro Hrončok
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On: 2045797
Blocks: PPCTracker F36FTBFS PYTHON3.11 F37FTBFS 2050761
TreeView+ depends on / blocked
 
Reported: 2022-01-27 09:36 UTC by Fedora Release Engineering
Modified: 2022-04-05 14:27 UTC (History)
5 users (show)

Fixed In Version: python-cffi-1.15.0-5.fc37 python-cffi-1.15.0-5.fc36
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-04-05 14:27:43 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
build.log (32.00 KB, text/plain)
2022-01-27 09:36 UTC, Fedora Release Engineering
no flags Details
root.log (32.00 KB, text/plain)
2022-01-27 09:36 UTC, Fedora Release Engineering
no flags Details
state.log (996 bytes, text/plain)
2022-01-27 09:36 UTC, Fedora Release Engineering
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker FREEIPA-7746 0 None None None 2022-01-27 09:39:18 UTC

Description Fedora Release Engineering 2022-01-27 09:36:29 UTC
python-cffi failed to build from source in Fedora rawhide/f36

https://koji.fedoraproject.org/koji/taskinfo?taskID=81985388


For details on the mass rebuild see:

https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild
Please fix python-cffi at your earliest convenience and set the bug's status to
ASSIGNED when you start fixing it. If the bug remains in NEW state for 8 weeks,
python-cffi will be orphaned. Before branching of Fedora 37,
python-cffi will be retired, if it still fails to build.

For more details on the FTBFS policy, please visit:
https://docs.fedoraproject.org/en-US/fesco/Fails_to_build_from_source_Fails_to_install/

Comment 1 Fedora Release Engineering 2022-01-27 09:36:33 UTC
Created attachment 1856221 [details]
build.log

file build.log too big, will only attach last 32768 bytes

Comment 2 Fedora Release Engineering 2022-01-27 09:36:34 UTC
Created attachment 1856222 [details]
root.log

file root.log too big, will only attach last 32768 bytes

Comment 3 Fedora Release Engineering 2022-01-27 09:36:36 UTC
Created attachment 1856223 [details]
state.log

Comment 4 Miro Hrončok 2022-01-27 10:03:16 UTC
It seems the tests don't like https://fedoraproject.org/wiki/Changes/SetBuildFlagsBuildCheck

Will try to opt-out.

Comment 6 Miro Hrončok 2022-01-27 10:23:17 UTC
https://src.fedoraproject.org/rpms/python-cffi/pull-request/13 fixes the main issue, but the build still fails on ppc64le:

=================================== FAILURES ===================================
__________________________ test_longdouble_precision ___________________________
    def test_longdouble_precision():
        # Test that we don't loose any precision of 'long double' when
        # passing through Python and CFFI.
        ffi = FFI()
        ffi.cdef("long double step1(long double x);")
        SAME_SIZE = ffi.sizeof("long double") == ffi.sizeof("double")
        lib = ffi.verify("""
            long double step1(long double x)
            {
                return 4*x-x*x;
            }
        """)
        def do(cast_to_double):
            x = 0.9789
            for i in range(10000):
                x = lib.step1(x)
                if cast_to_double:
                    x = float(x)
            return float(x)
    
        more_precise = do(False)
        less_precise = do(True)
        if SAME_SIZE:
            assert more_precise == less_precise
        else:
>           assert abs(more_precise - less_precise) > 0.1
E           assert 0.0 > 0.1
E            +  where 0.0 = abs((0.0 - 0.0))
testing/cffi0/test_verify.py:199: AssertionError
__________________________ test_longdouble_precision ___________________________
    def test_longdouble_precision():
        # Test that we don't loose any precision of 'long double' when
        # passing through Python and CFFI.
        ffi = FFI()
        ffi.cdef("long double step1(long double x);")
        SAME_SIZE = ffi.sizeof("long double") == ffi.sizeof("double")
        lib = ffi.verify("""
            long double step1(long double x)
            {
                return 4*x-x*x;
            }
        """)
        def do(cast_to_double):
            x = 0.9789
            for i in range(10000):
                x = lib.step1(x)
                if cast_to_double:
                    x = float(x)
            return float(x)
    
        more_precise = do(False)
        less_precise = do(True)
        if SAME_SIZE:
            assert more_precise == less_precise
        else:
>           assert abs(more_precise - less_precise) > 0.1
E           assert 0.0 > 0.1
E            +  where 0.0 = abs((0.0 - 0.0))
testing/cffi0/test_verify.py:199: AssertionError

Comment 7 Dan Horák 2022-01-27 11:24:33 UTC
does python-cffi interact with libffi or is it a standalone module? libffi will need updates for the "long double" change, it is FTBFS too

Comment 8 Miro Hrončok 2022-01-27 11:47:17 UTC
It has:

BuildRequires:  libffi-devel


And python3-cffi requires (on x86_64):

libffi.so.8()(64bit)
libffi.so.8(LIBFFI_BASE_8.0)(64bit)
libffi.so.8(LIBFFI_CLOSURE_8.0)(64bit)

Comment 9 Miro Hrončok 2022-01-31 13:48:57 UTC
Retrying in https://src.fedoraproject.org/rpms/python-cffi/pull-request/13 with libffi-3.4.2-8.fc36

Comment 10 Miro Hrončok 2022-01-31 16:41:26 UTC
It still fails :(

Comment 11 Dan Horák 2022-01-31 16:43:56 UTC
I wonder if it needs python to be rebuilt too, it uses libffi-devel in its buildroot too ...

Comment 12 Miro Hrončok 2022-01-31 17:09:26 UTC
Trying a Python rebuild at ppc64le-test.fedorainfracloud.org

Comment 13 Miro Hrončok 2022-01-31 18:04:48 UTC
Bah, still the same problem.

Comment 14 Miro Hrončok 2022-02-02 11:14:22 UTC
python3.10 got rebuilt for another reason in rawhide. Trying https://src.fedoraproject.org/rpms/python-cffi/pull-request/13 again in case my local testing was not bulletproof.

Comment 15 Miro Hrončok 2022-02-02 11:27:45 UTC
Same failure.

Comment 16 Dan Horák 2022-02-02 11:37:47 UTC
yeah, I think we have exhausted the simple tricks, now is hard work needed ...

Comment 17 Ben Cotton 2022-02-08 20:16:07 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 36 development cycle.
Changing version to 36.

Comment 18 Miro Hrončok 2022-02-27 00:09:58 UTC
This poses a significant risk for timely Python 3.11 delivery in Fedora 37 - a month has passed and there is no clear way forward. Hence, rising severity.

Comment 19 Miro Hrončok 2022-03-16 14:02:34 UTC
Still happening with gcc-12.0.1-0.12.fc37.ppc64le.

Comment 20 Petr Viktorin (pviktori) 2022-03-18 12:21:50 UTC
Narrowed it down to `force_generic_engine`, which is apparently used in PyPy and tests.
FWIW, the skips ("don't know the very exact precision of 'long double'") should be fine, that's an extra part of the test explicitly for some Intel-like arches.
Will look further.

Smaller reproducer:

from cffi import FFI

ffi = FFI()
ffi.cdef("long double step1(long double x);")

lib = ffi.verify(r"""
    #include <stdio.h>
        long double step1(long double x)
        {
            printf("C got: %Lf\n", x);
            long double result =  4*x-x*x;
            printf("C returns: %Lf\n", x);
            return result;
        }
    """,
    force_generic_engine=True,
)

x = lib.step1(0.9789)
print(f"Python: {x = }, {float(x) = }")


----
C got: 0.978900
C returns: 0.978900
Python: x = <cdata 'long double' 5.130162E-4937>, float(x) = 0.0

Comment 21 Petr Viktorin (pviktori) 2022-03-18 13:02:10 UTC
(That should be `result`, and `C returns: 2.957355`)

Comment 22 Petr Viktorin (pviktori) 2022-03-18 15:44:43 UTC
Looks like an alignment issue, goes away with the following PoC patch for generating cif_descr.exchange_offset_arg (offsets to return value & arguments in the buffer used when calling a ffi function).
Hardcoding long double alignment isn't the right solution, I'll dig further for a real fix.

diff -rU3 cffi-1.15.0-orig/c/_cffi_backend.c cffi-1.15.0/c/_cffi_backend.c
--- cffi-1.15.0-orig/c/_cffi_backend.c	2021-10-13 01:59:28.000000000 +0200
+++ cffi-1.15.0/c/_cffi_backend.c	2022-03-18 16:33:38.086767827 +0100
@@ -5665,7 +5665,7 @@
     }
 }
 
-#define ALIGN_ARG(n)  ((n) + 7) & ~7
+#define ALIGN_ARG(n)  ((n) + 15) & ~15
 
 static int fb_build(struct funcbuilder_s *fb, PyObject *fargs,
                     CTypeDescrObject *fresult)

Comment 23 Petr Viktorin (pviktori) 2022-03-18 16:40:57 UTC
I opened an upstream issue: https://foss.heptapod.net/pypy/pypy/-/issues/3708

Comment 26 Dan Horák 2022-03-30 12:51:26 UTC
thanks guys, it makes sense about the alignment, the new "long double" is 16B long and might require a "natural" alignment

Comment 27 Fedora Update System 2022-03-30 17:41:01 UTC
FEDORA-2022-6042335ce9 has been submitted as an update to Fedora 36. https://bodhi.fedoraproject.org/updates/FEDORA-2022-6042335ce9

Comment 28 Fedora Update System 2022-03-30 17:42:14 UTC
FEDORA-2022-a41682259c has been submitted as an update to Fedora 37. https://bodhi.fedoraproject.org/updates/FEDORA-2022-a41682259c

Comment 29 Fedora Update System 2022-03-30 17:43:53 UTC
FEDORA-2022-a41682259c has been pushed to the Fedora 37 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 30 Petr Viktorin (pviktori) 2022-03-31 09:03:29 UTC
Follow-up on the CPython side:

- I checked that PyObject_Malloc() currently aligns to 16B (on 64-bit arches).
- I filed https://bugs.python.org/issue47179 to use correct alignment, using C11's `max_align_t`.

Comment 31 Fedora Update System 2022-03-31 18:25:10 UTC
FEDORA-2022-6042335ce9 has been pushed to the Fedora 36 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2022-6042335ce9`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2022-6042335ce9

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 32 Fedora Update System 2022-04-05 14:27:43 UTC
FEDORA-2022-6042335ce9 has been pushed to the Fedora 36 stable repository.
If problem still persists, please make note of it in this bug report.


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