Skip to content

gh-161475: Fix ctypes structures with float arrays returned on Linux SPARC - #161476

Merged
vstinner merged 1 commit into
python:mainfrom
shalseth:sparc64-ctypes-array-int-regs
Nov 7, 2026
Merged

vstinner merged 1 commit into
python:mainfrom
shalseth:sparc64-ctypes-array-int-regs

Conversation

@shalseth

@shalseth shalseth commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

On Linux, GCC and clang pass arrays of floating-point type in a structure in integer registers, only Solaris follows the vendor ABI there (GCC PR target/114416). This describes such array elements to libffi as integers of the same size on Linux SPARC, so libffi reads them from the right registers. Solaris is unchanged.

Tested on a SPARC T7-1 (Linux, GCC 16): test_ctypes passes on main and 3.15, and the full test suite passes on main.

@kulikjak this shouldn't change anything on Solaris, but you may want to have a look since it's next to your gh-110190 change.

…Linux SPARC

On Linux, GCC and clang pass arrays of floating-point type in a structure
in integer registers; only Solaris follows the vendor ABI there (GCC PR
target/114416). Since pythongh-110190, ctypes described such array elements to
libffi as floats on all SPARC, so libffi read structures returned by value
from the FP registers on Linux.

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

The changed code is already tested by ctypes. Extract of the issue:

test_ctypes fails on Linux sparc64 in test_array_in_struct

@vstinner vstinner added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 6, 2026
@vstinner

vstinner commented Nov 6, 2026

Copy link
Copy Markdown
Member

cc @encukou

@kulikjak

kulikjak commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for the ping. I tested it and it (as expected) doesn't break Solaris.

I believe that the original fix in gcc was done specifically to Solaris only because they wanted to be careful and we were the only ones who reported it. But now that you also encountered it, maybe they would extend that gcc fix to Linux as well?

@shalseth

shalseth commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

I believe that the original fix in gcc was done specifically to Solaris only because they wanted to be careful and we were the only ones who reported it. But now that you also encountered it, maybe they would extend that gcc fix to Linux as well?

Thanks for testing it on Solaris!

I don't think GCC will change it on Linux. The commit (1d238c84025a) says the decision was to fix it on Solaris only, and on Linux there's no vendor compiler to be compatible with, so what GCC does is effectively the ABI there.
Changing it now would break calls between old and new binaries that pass these structs, and clang does the same as GCC. So I think ctypes has to follow the compilers on Linux.

@vstinner
vstinner merged commit 91ba786 into python:main Nov 7, 2026
66 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @shalseth for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 7, 2026

Copy link
Copy Markdown

GH-161558 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 7, 2026
@bedevere-app

bedevere-app Bot commented Nov 7, 2026

Copy link
Copy Markdown

GH-161559 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 7, 2026
@vstinner

vstinner commented Nov 7, 2026

Copy link
Copy Markdown
Member

Merged. Thanks for your fix!

@kulikjak:

Thanks for the ping. I tested it and it (as expected) doesn't break Solaris.

Ah thanks, I'm feeling safer with your manual test :-)

@shalseth:

Long double arrays have the same problem, I'll send that separately with a test.

You can cc-me on your follow-up fix, I will try to review it.

vstinner pushed a commit that referenced this pull request Nov 7, 2026
… Linux SPARC (GH-161476) (#161559)

gh-161475: Fix ctypes structures with float arrays returned on Linux SPARC (GH-161476)

On Linux, GCC and clang pass arrays of floating-point type in a structure
in integer registers; only Solaris follows the vendor ABI there (GCC PR
target/114416). Since gh-110190, ctypes described such array elements to
libffi as floats on all SPARC, so libffi read structures returned by value
from the FP registers on Linux.
(cherry picked from commit 91ba786)

Co-authored-by: Stian Halseth <33956011+shalseth@users.noreply.github.com>
vstinner pushed a commit that referenced this pull request Nov 7, 2026
… Linux SPARC (GH-161476) (#161558)

gh-161475: Fix ctypes structures with float arrays returned on Linux SPARC (GH-161476)

On Linux, GCC and clang pass arrays of floating-point type in a structure
in integer registers; only Solaris follows the vendor ABI there (GCC PR
target/114416). Since gh-110190, ctypes described such array elements to
libffi as floats on all SPARC, so libffi read structures returned by value
from the FP registers on Linux.
(cherry picked from commit 91ba786)

Co-authored-by: Stian Halseth <33956011+shalseth@users.noreply.github.com>
@shalseth

shalseth commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

@shalseth:

Long double arrays have the same problem, I'll send that separately with a test.

You can cc-me on your follow-up fix, I will try to review it.

Thanks!

The follow up has to wait a bit: its test for a struct with a single long double returns nan on x86-64, which turned out to be a libffi bug (libffi/libffi#1058). It will take while before updated libffi is available in all distros. I've parked it for now, but might get back to it in the future.

@vstinner

vstinner commented Nov 7, 2026

Copy link
Copy Markdown
Member

Ah, maybe close the current Python issue, and create a new one for long double arrays once the libffi issue has been addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants