Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ppc: support 32bit AIX and OSX #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

carenas
Copy link
Contributor

@carenas carenas commented Sep 27, 2023

Fixes a problem in 32bit AIX, where functions using doubles will fail to map correctly their function parameters.

$ bin/sljit_test -s
test58 case 4 failed
test59 case 4 failed
test70 case 9 failed
test71 case 9 failed
test73 case 17 failed
SLJIT tests: 5 (4%) tests FAILED on PowerPC 32bit (big endian + unaligned) (with fpu)

Tested in AIX, Linux and OSX (thanks to @sevan)

Using r11 for TMP_REG1 might be controversial, but seem safe in practice, with the caveat that it wouldn't be preserved around inter module calls.

There is also the possibility this change might be needed for other systems (ex: BSD), althought NetBSD/macppc and and older OpenBSD 6.6 seems to work (at least in 32bit) without it when tested on an QEMU emulated "mac".

@carenas carenas marked this pull request as ready for review September 27, 2023 10:43
@carenas carenas force-pushed the aix32 branch 2 times, most recently from 8bd033e to e26ec11 Compare September 28, 2023 04:04
@carenas carenas changed the title ppc: support 32bit AIX ppc: support 32bit AIX and OSX Oct 3, 2023
@carenas carenas marked this pull request as draft October 3, 2023 03:36
@carenas carenas marked this pull request as ready for review October 3, 2023 16:12
Since c0270dc (Support floating point arguments by more ABIs., 2017-10-21)
tests had been failing in 32bit AIX, because the ABI it uses is slightly
different than the one implemented.

Reuse the 64bit implementation for 32bit AIX, but add the ability to skip
two 32bit general registers for each 64bit floating point argument.

To support a fourth argument when all three previous ones are doubles
r9 had to be make accessible as a scratch register, so add r11 to replace it
as TMP_REG1, with the caveat it might be clobbered by inter module calls.
@barracuda156
Copy link

@carenas While I am not aware if the issue affects macOS ppc, I am interested to test that.

It is enough to build this and run the test suite to find out if the bug is relevant?

@carenas
Copy link
Contributor Author

carenas commented Dec 7, 2024

@barracuda156: not sure I understand what you mean by "issue".

This PR adds support for SLJIT to work in OSX when the CPU is a 32-bit PowerPC, without it, SLJIT will probably crash if anything that touches a FPU register is used.

PCRE2 doesn't "normally" use FPU registers, but that is changing with the addition of SIMD (which most of the times reuses those registers for vector operations).

That being said, I don't think the current version of PCRE2 would be affected, but that can change with any future version unless this is merged (needs rebasing first).

If you have access to systems running those CPUs/OS building and runniing the tests should be enough to validate support was added correctly; a version of PCRE2 that includes this version of JIT which is widely used would be the next obvious step to confirm that the controversial ABI change (using r11 for SLJIT) was also safe for those OS.

@barracuda156
Copy link

This is without your patch, from eb8ef1e commit:

36-148% sudo ./sljit_test -v
Run executable allocator test
Run test1
Run test2
Run test3
Run test4
Run test5
Run test6
Run test7
Run test8
Run test9
Run test10
Run test11
Run test12
Run test13
Run test14
Run test15
Run test16
Run test17
Run test18
Run test19
Run test20
Run test21
Run test23
Run test24
Run test25
Run test26
Run test27
Run test28
Run test29
Run test30
Run test31
Run test32
Run test33
Run test34
Run test35
Run test36
Run test37
Run test38
Run test39
Run test40
Run test41
Run test42
Run test43
Run test44
Run test45
Run test46
Run test47
Run test48
Run test49
Run test50
Run test51
Run test52
Run test53
Run test54
Run test55
Run test56
Run test57
Run test58
Run test59
Run test60
Run test61
Run test62
Run test63
Run test64
Run test65
Run test66
Run test67
Run test68
Run test69
Run test70
Run test71
Run test72
Run test73
Run test74
Run test75
Run test76
---- Call tests ----
Run test_call1
Run test_call2
Run test_call3
test_call3 case 4 failed
Run test_call4
test_call4 case 4 failed
Run test_call5
Run test_call6
test_call6 case 3 failed
Run test_call7
Run test_call8
Run test_call9
Run test_call10
Run test_call11
Run test_call12
Run test_call13
---- Float tests ----
Run test_float1
Run test_float2
Run test_float3
Run test_float4
Run test_float5
Run test_float6
Run test_float7
Run test_float8
Run test_float9
Run test_float10
Run test_float11
Run test_float12
test_float12 case 1 failed
Run test_float13
Run test_float14
test_float14 case 1 failed
Run test_float15
Run test_float16
Run test_float17
Run test_float18
Run test_float19
Run test_float20
Run test_float21
f32 register pairs are not available, test_float21 skipped
Run test_float22
Run test_float23
no simd available, simd tests are skipped
---- Serialize tests ----
Run test_serialize1
Run test_serialize2
Run test_serialize3
SLJIT tests: 5 (3%) tests FAILED on PowerPC 32bit (big endian + unaligned) (with fpu)

So yeah, failures are there. I will try your branch now (the patch does not apply cleanly onto the master).

@barracuda156
Copy link

@carenas From your branch ed98de1
This fails (and MAP_JIT is not defined on any macOS on PowerPC):

In file included from /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/sljit-ed98de18c70897827a15f2ff96dcf18da32aac33/sljit_src/sljitLir.c:313:
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/sljit-ed98de18c70897827a15f2ff96dcf18da32aac33/sljit_src/allocator_src/sljitExecAllocatorApple.c: In function ‘alloc_chunk’:
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/sljit-ed98de18c70897827a15f2ff96dcf18da32aac33/sljit_src/allocator_src/sljitExecAllocatorApple.c:101: error: ‘MAP_JIT’ undeclared (first use in this function)
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/sljit-ed98de18c70897827a15f2ff96dcf18da32aac33/sljit_src/allocator_src/sljitExecAllocatorApple.c:101: error: (Each undeclared identifier is reported only once
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/sljit-ed98de18c70897827a15f2ff96dcf18da32aac33/sljit_src/allocator_src/sljitExecAllocatorApple.c:101: error: for each function it appears in.)
make[2]: *** [CMakeFiles/sljit_test.dir/sljit_src/sljitLir.c.o] Error 1

But from where exactly it fails, looks like OS detecting does not work, since apparently nothing sets TARGET_OS_OSX.

If I change that to a standard #ifdef __APPLE__, then there is also a failure with the arch itself:

In file included from /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/sljit-ed98de18c70897827a15f2ff96dcf18da32aac33/sljit_src/sljitLir.c:313:
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/sljit-ed98de18c70897827a15f2ff96dcf18da32aac33/sljit_src/allocator_src/sljitExecAllocatorApple.c:72:2: error: #error "Unsupported architecture"
In file included from /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/sljit-ed98de18c70897827a15f2ff96dcf18da32aac33/sljit_src/sljitLir.c:313:
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/sljit-ed98de18c70897827a15f2ff96dcf18da32aac33/sljit_src/allocator_src/sljitExecAllocatorApple.c: In function ‘apple_update_wx_flags’:
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/sljit-ed98de18c70897827a15f2ff96dcf18da32aac33/sljit_src/allocator_src/sljitExecAllocatorApple.c:85: error: ‘macos’ undeclared (first use in this function)
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/sljit-ed98de18c70897827a15f2ff96dcf18da32aac33/sljit_src/allocator_src/sljitExecAllocatorApple.c:85: error: (Each undeclared identifier is reported only once
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/sljit-ed98de18c70897827a15f2ff96dcf18da32aac33/sljit_src/allocator_src/sljitExecAllocatorApple.c:85: error: for each function it appears in.)
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/sljit-ed98de18c70897827a15f2ff96dcf18da32aac33/sljit_src/allocator_src/sljitExecAllocatorApple.c:85: error: expected ‘)’ before numeric constant
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/sljit-ed98de18c70897827a15f2ff96dcf18da32aac33/sljit_src/allocator_src/sljitExecAllocatorApple.c: In function ‘alloc_chunk’:
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/sljit-ed98de18c70897827a15f2ff96dcf18da32aac33/sljit_src/allocator_src/sljitExecAllocatorApple.c:101: error: ‘MAP_JIT’ undeclared (first use in this function)
make[2]: *** [CMakeFiles/sljit_test.dir/sljit_src/sljitLir.c.o] Error 1
make[2]: Leaving directory `/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/build'
make[1]: *** [CMakeFiles/sljit_test.dir/all] Error 2
make[1]: Leaving directory `/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_sljit/sljit/work/build'
make: *** [all] Error 2

@barracuda156
Copy link

@carenas Looks like MAP_JIT issue has been fixed in the master. Could you please rebase your ppc patch to the master branch? I will run the tests for it then.

@barracuda156
Copy link

@carenas Is this intended? The logic of macros looks a bit unusual here.

#if ((defined(SLJIT_CONFIG_PPC_64) && SLJIT_CONFIG_PPC_64) && (!defined(_CALL_ELF) || _CALL_ELF == 1) && !defined(__APPLE__)) \
	|| ((defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) && defined _AIX)

@sevan
Copy link
Contributor

sevan commented Dec 7, 2024

Basically trying to avoid applying to Darwin. Originally it was assumed that the AIX support would overlap with Darwin/PowerPC, turned out to be not so.

@sevan
Copy link
Contributor

sevan commented Dec 7, 2024

You can follow the development in PR #179 that lead up to this.

@barracuda156
Copy link

@sevan Thank you for the reference. Is there some branch to test for ppc which has all needed patches present?

I can test on 10.6 ppc and probably 10.5 ppc64 (provided it can build with cmake-bootstrap; my toolchain on 10.5 is kinda defunct, since I nuked libgcc and don't get time to rebuild everything, but Xcode compilers work, of course).

@sevan
Copy link
Contributor

sevan commented Dec 7, 2024

@sevan Thank you for the reference. Is there some branch to test for ppc which has all needed patches present?

Based on my comment in the other PR, at the time I tested with the patches from PR 211 & 214.
Looking at PR 214, it looks like it was merged into master some time ago, haven't checked if it's made it into release though.

@barracuda156
Copy link

@sevan Test results above #211 (comment) are from the latest commit from the master (OS detection and MAP_JIT issue are fixed there, so the build works, but a few tests fail).

(I was just hoping to avoid rebasing patches myself, the one from this PR does not apply onto the current master.)

@barracuda156
Copy link

P. S. Well, there is one thing which breaks the build: #283
But it is just a matter of deleting an invalid linker flag from CMakeLists.

@sevan
Copy link
Contributor

sevan commented Dec 7, 2024

I guess it is broken due to changes since October 2023, as it was passing all tests according to #179 (comment). Bisect time?

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