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

Unbreak PowerPC build on macOS #419

Merged
merged 3 commits into from
Sep 20, 2024
Merged

Conversation

barracuda156
Copy link
Contributor

Current code is broken, see #418

Looks like this is a silly copy-paste error – compare macOS file (which was likely made blindly) vs Linux one (which hopefully was actually tested).

Also, fix PowerPC macro for Darwin, so that a meaningful implementation is picked when building for ppc64 too. I cannot test it now, but given that Darwin does not use TOC and insns in the header are supported both in 32- and 64-bit ABI, it should work fine.

@barracuda156
Copy link
Contributor Author

CI error has obviously nothing to do with my PR:

Error: The version '3.7' with architecture 'arm64' was not found for macOS 14.6.1.

Python 3.7 does not build on macOS arm64, AFAIK, someone should fix a broken CI setup :)

@barracuda156
Copy link
Contributor Author

@jamadden @oremanj Could someone please review this? CI errors are unrelated.

@cclauss
Copy link

cclauss commented Sep 4, 2024

@barracuda156
Copy link
Contributor Author

@cclauss Thank you, rebased.

@oremanj
Copy link
Contributor

oremanj commented Sep 4, 2024

Seems fine to me. I don't have merge permission, hopefully someone who does will see this.

@glaubitz
Copy link

@barracuda156 Does the testsuite actually pass for you on 32-bit PowerPC with these changes? I'm asking, because I'm getting a segmentation fault on 32-bit PowerPC on Linux.

Looking at the assembly code for 32-bit PowerPC on Linux and Unix and macOS, the former looks quite different.

@barracuda156
Copy link
Contributor Author

@glaubitz How do I run it? I tried now sudo port -v test py311-greenlet, and MacPorts does something silly:

--->  Testing py311-greenlet
Executing:  cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_python_py-greenlet/py311-greenlet/work/greenlet-3.0.3" && /opt/local/Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11 -m unittest discover 

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

Perhaps port test was last time tested prior to pep517 move or prior to some breaking updates of dependencies. So now it just does not try to run anything.

@barracuda156
Copy link
Contributor Author

If this is relevant from setup.py:

        'test': [
            'objgraph',
            'psutil',
        ],

then I need to add py-objgraph first, since apparently there is no port for it.

@glaubitz
Copy link

I'm running it like this and it crashes with a segmentation fault:

(sid_powerpc-dchroot)glaubitz@perotto:~/greenlet/build/lib.linux-ppc-cpython-312/greenlet$ PYTHONPATH=/home/glaubitz/greenlet/build/lib.linux-ppc-cpython-312 python3.12 -m
 unittest discover -v 
test_break_ctxvars (tests.test_contextvars.ContextVarsTests.test_break_ctxvars) ... Segmentation fault
(sid_powerpc-dchroot)glaubitz@perotto:~/greenlet/build/lib.linux-ppc-cpython-312/greenlet$

@barracuda156
Copy link
Contributor Author

@glaubitz Unless I miss something (on mobile now), this looks similar/identical to what MacPorts does, save for -v. If so, then perhaps I do not get a segfault, but I do not see any actual tests been run either.
I will try again when I am back to the PowerMac.

@glaubitz
Copy link

So, the crash looks like this:

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0fa9830c in green_init (self=..., args=<error reading variable: Cannot access memory at address 0x0>, kwargs=<error reading variable: Cannot access memory at address 0x0>)
    at src/greenlet/greenlet.cpp:253
253         if (!PyArg_ParseTupleAndKeywords(
(gdb) bt
#0  0x0fa9830c in green_init (self=..., args=<error reading variable: Cannot access memory at address 0x0>, kwargs=<error reading variable: Cannot access memory at address 0x0>)
    at src/greenlet/greenlet.cpp:253
#1  0x10161ebc in type_call (type=<optimized out>, type@entry=0xfac0278 <PyGreenlet_Type>, args=args@entry=(<built-in method run of _contextvars.Context object at remote 0xf7c52f28>,),
    kwds=kwds@entry=0x0) at ../Objects/typeobject.c:1677
#2  0x100da1b4 in _PyObject_MakeTpCall (tstate=0x107c1f08 <_PyRuntime+235672>, callable=callable@entry=<type at remote 0xfac0278>, args=args@entry=0xf7d6b664, nargs=1,
    keywords=<optimized out>, keywords@entry=0x0) at ../Objects/call.c:240
#3  0x100db0a0 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=<optimized out>, args=0xf7d6b664, callable=<type at remote 0xfac0278>, tstate=<optimized out>)
    at ../Include/internal/pycore_call.h:90
#4  0x101bc314 in _PyEval_EvalFrameDefault (tstate=0x107c1f08 <_PyRuntime+235672>, frame=0xf7d6b628, throwflag=<optimized out>) at Python/bytecodes.c:2715
#5  0x100dc1c8 in _PyFunction_Vectorcall (kwnames=0x0, nargsf=3, stack=0xff8e639c, func=<function at remote 0xf793dca8>) at ../Objects/call.c:419

Let me know if you're seeing this as well.

@jamadden
Copy link
Contributor

That's probably the same thing as #422. If so, it should be fixed in trunk.

@glaubitz
Copy link

That's probably the same thing as #422. If so, it should be fixed in trunk.

Not 100% sure. There could still be syntax errors in the actual assembly code.

@barracuda156 needs to test-build and run the testsuite on MacOS X on PowerPC.

@jamadden
Copy link
Contributor

jamadden commented Sep 12, 2024

Not 100% sure. There could still be syntax errors in the actual assembly code.

Sorry, I should have been more clear. I meant this branch, with the patch, rebased on master to pull in the fix for 422. The backtrace was clearly the same problem as LinuxPPC-32 was having.

But now that I look more closely, I see that it's the same problem, but possibly from a different source. I'll have to make another change.

@barracuda156
Copy link
Contributor Author

@jamadden So should I wait for the fix before trying to make tests run?

@glaubitz
Copy link

Not 100% sure. There could still be syntax errors in the actual assembly code.

Sorry, I should have been more clear. I meant this branch, with the patch, rebased on master to pull in the fix for 422.

OK, I misunderstood.

The backtrace was clearly the same problem as LinuxPPC-32 was having.

But now that I look more closely, I see that it's the same problem, but from a different source. I'll have to make another change.

But @barracuda156 never ran the testsuite because he didn't know why, did he? I don't think there are other changes necessary, the SysV ABI should be the same across Linux, NetBSD and MacOS X.

@jamadden Before making any more changes, please let @barracuda156 run the tests with on master with #419 applied.

@barracuda156
Copy link
Contributor Author

@glaubitz I think macOS should not be using SysV ABI, though a given code can be identical between SysV and PowerOpen.

I will try running tests today and update here.

@barracuda156
Copy link
Contributor Author

Is there a way to run tests really manually, test-by-test? This unitframework does not seem to do anything.

36-202% sudo PYTHONPATH=/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_python_py-greenlet/py311-greenlet/work/destroot/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/greenlet python3.11 -m unittest discover -v
Password:

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

@jamadden
Copy link
Contributor

The backtrace was clearly the same problem as LinuxPPC-32 was having.

But now that I look more closely, I see that it's the same problem, but from a different source. I'll have to make another change.

But @barracuda156 never ran the testsuite because he didn't know why, did he?

Argh. Reading from the top of the thread down and not bottom up, I see why the backtrace looked like the Linux problem: Because the backtrace you posted actually was the Linux crash. Reading comprehension fail.

Is there a way to run tests really manually, test-by-test? This unitframework does not seem to do anything.

unittest discover needs to look at the project's source code. By default, that means you need your working directory to be the project's directory, i.e., the repo checkout/unpacked tarball. To change that, you use the --start-directory argument, e.g. to test an installed version, try something like:

python -m unittest discover --start-directory /.../lib/python3.12/site-packages/greenlet/

(One tests depends on being run from a project directory, so expect a version test to fail.)

That said, most test files will be runnable directly (they'll have a call to unittest.main() at the bottom. For example,

python -m greenlet.tests.test_greenlet

@barracuda156
Copy link
Contributor Author

@jamadden Thank you, that indeed works, however it wants a package which we do not have:

36-202% cd /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_python_py-greenlet/py311-greenlet/work/greenlet-8cb3791357b42b31d48cc0030ba68d73e0ee3b09/src/greenlet 
36-202% /opt/local/bin/python3.11 -m unittest discover
E
======================================================================
ERROR: tests (unittest.loader._FailedTest.tests)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/loader.py", line 452, in _find_test_path
    package = self._get_module_from_name(name)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/loader.py", line 362, in _get_module_from_name
    __import__(name)
  File "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_python_py-greenlet/py311-greenlet/work/greenlet-8cb3791357b42b31d48cc0030ba68d73e0ee3b09/src/greenlet/tests/__init__.py", line 24, in <module>
    from . import leakcheck
  File "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_python_py-greenlet/py311-greenlet/work/greenlet-8cb3791357b42b31d48cc0030ba68d73e0ee3b09/src/greenlet/tests/leakcheck.py", line 34, in <module>
    import objgraph
ModuleNotFoundError: No module named 'objgraph'


----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)

I will try adding it.

@jamadden
Copy link
Contributor

To run the tests, you must install greenlet with the dependencies listed in the 'test' extra. Normally this is done with pip install $GREENLET[test], where $GREENLET is the specifier, such as the path to the greenlet checkout. There is also a similar command to have pip fetch the required dependencies without installing them. This is also found in the project metadata generated during the build process. But the important part is the "[test]" tacked on to the end.

If you're not using pip or running setup.py, then you'll need to read setup.py and look for the "test" section of the "extras_require" section. Currently, that specifies objgraph and psutil, but that may change at any time (including point releases).

BTW, I'm a huge MacPorts fan, and have been since at least 2010. Thanks for your involvement!

@barracuda156
Copy link
Contributor Author

Ok, I made a port for py-objgraph (it is trivial, thankfully), but it pulls in py-graphviz, and that one seems broken: xflr6/graphviz#225
Its source code uses platform.system all over, and Python errs out on that:

AttributeError: module 'platform' has no attribute 'system'

(Sorry if it is something silly on my side, I know nothing about how Python stuff should work.)

@jamadden
Copy link
Contributor

jamadden commented Sep 13, 2024

AttributeError: module 'platform' has no attribute 'system'

platform.system is part of the standard library, and has been since the Python 2 days, so that means there is some other file or directory named "platform.py" or "platform/", respectively, first on the PYTHONPATH.

Greenlet has a package (directory) called greenlet.platform (greenlet/platform/__init__py). That suggests to me that you have dir1/dir2/parent/greenlet/ (as opposed to dir1/dir2/parent/) on the PYTHONPATH (or you're using greenlet/ as your working directory such that it contains the platform/ directory. Could that be possible?

One way to confirm would be to use the same interpreter from the same working directory in the same shell as you used to report the graphviz bug, and execute this:

$ /opt/local/bin/python3.11 -c 'import platform; print(platform.__file__)'
/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/platform.py

If you don't get that output, but instead get something like the following, it means one of those possibilities I mentioned above is true.

$ pwd
/.../GithubSources/greenlet/src/greenlet 
$ /opt/local/bin/python3.11 -c 'import platform; print(platform.__file__)'
/.../GithubSources/greenlet/src/greenlet/platform/__init__.py

(Setting the PYTHONSAFEPATH environment variable to 1 can solve the problem of the current working directory containing platform.py or platform/__init__.py; it prevents putting the current working directory first on the PYTHONPATH.)

@barracuda156
Copy link
Contributor Author

@jamadden Hmm, I can get the correct directory upon setting env variable, but Python test fails to run like before:

36-202% export PYTHONSAFEPATH=1

36-202% cd /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/greenlet
36-202% /opt/local/bin/python3.11 -m unittest discover
E
======================================================================
ERROR: tests (unittest.loader._FailedTest.tests)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/loader.py", line 452, in _find_test_path
    package = self._get_module_from_name(name)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/loader.py", line 362, in _get_module_from_name
    __import__(name)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/greenlet/tests/__init__.py", line 27, in <module>
    from . import leakcheck
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/greenlet/tests/leakcheck.py", line 34, in <module>
    import objgraph
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/objgraph.py", line 51, in <module>
    import graphviz
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphviz/__init__.py", line 31, in <module>
    from .backend import (DOT_BINARY, UNFLATTEN_BINARY,
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphviz/backend/__init__.py", line 3, in <module>
    from .dot_command import DOT_BINARY
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphviz/backend/dot_command.py", line 7, in <module>
    from .. import exceptions
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphviz/exceptions.py", line 3, in <module>
    from .backend.execute import ExecutableNotFound, CalledProcessError
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphviz/backend/execute.py", line 10, in <module>
    from .. import _compat
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphviz/_compat.py", line 25, in <module>
    if platform.system() == 'Windows':  # pragma: no cover
       ^^^^^^^^^^^^^^^
AttributeError: module 'platform' has no attribute 'system'


----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)

36-202% /opt/local/bin/python3.11 -c 'import platform; print(platform.__file__)'
/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/platform.py

36-202% /opt/local/bin/python3.11 -m unittest discover --start-directory /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/greenlet
E
======================================================================
ERROR: tests (unittest.loader._FailedTest.tests)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/loader.py", line 452, in _find_test_path
    package = self._get_module_from_name(name)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/loader.py", line 362, in _get_module_from_name
    __import__(name)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/greenlet/tests/__init__.py", line 27, in <module>
    from . import leakcheck
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/greenlet/tests/leakcheck.py", line 34, in <module>
    import objgraph
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/objgraph.py", line 51, in <module>
    import graphviz
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphviz/__init__.py", line 31, in <module>
    from .backend import (DOT_BINARY, UNFLATTEN_BINARY,
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphviz/backend/__init__.py", line 3, in <module>
    from .dot_command import DOT_BINARY
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphviz/backend/dot_command.py", line 7, in <module>
    from .. import exceptions
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphviz/exceptions.py", line 3, in <module>
    from .backend.execute import ExecutableNotFound, CalledProcessError
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphviz/backend/execute.py", line 10, in <module>
    from .. import _compat
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/graphviz/_compat.py", line 25, in <module>
    if platform.system() == 'Windows':  # pragma: no cover
       ^^^^^^^^^^^^^^^
AttributeError: module 'platform' has no attribute 'system'


----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)

@jamadden
Copy link
Contributor

None of released versions of 10.6.x will boot and run on PowerPC.
10.5.8 is a working option. I just do not have pre-built ports for it.

Got it, thanks! It may be awhile before I can get to this.

Just remembered, is pthread_threadid_np relevant here?

It shouldn't be. greenlet doesn't directly use that API, nor does it call PyThread_get_thread_native_id

I have managed to rebuild greenlet with -UNDEBUG, and here is the crash:

Thank you, that is different and helps localize a bit. Any luck with -g?

@jamadden
Copy link
Contributor

Any luck with -g?

Oh, never mind. It was scrolled off to the right. (Why does github insist on limiting the width of the comment column?)

@barracuda156
Copy link
Contributor Author

Oh, never mind. It was scrolled off to the right.

Yeah, I added that in the end.

Got it, thanks! It may be awhile before I can get to this.

Sorry that I can't do much for 10.5, but 10.6 ppc already takes all of the spare time. If only I had another Quad to run both in parallel.

@glaubitz
Copy link

10.6 ppc

Huh? Snow Leopard on PowerPC? How is that possible?

@barracuda156
Copy link
Contributor Author

10.6 ppc

Huh? Snow Leopard on PowerPC? How is that possible?

There are developer builds which run on PowerPC.

(Recently we got 10.6.8 running, however for a reason yet unknown DNS/DHCP are broken on it, so it is of little utility at the moment.)

@barracuda156
Copy link
Contributor Author

@glaubitz This:
image

@jamadden
Copy link
Contributor

jamadden commented Sep 19, 2024

These are the top three frames (lightly edited for clarity):

0   greenlet.so        0x023f2b58 PyObjectPointer::operator bool()  (greenlet_refs.hpp:221)
1   org.python.python  0x0069e96c 0x4d7000 + 1866092
2   greenlet.os        0x023f00cc MarkGreenletDeadIfNeeded(greenlet::ThreadState*) (TThreadStateDestroy.cpp:70)

Starting from the bottom, TThreadStateDestroy.cpp:70 is simply if (state and state->has_main_greenlet()). The variable state is a simple pointer, so the first part of the condition is just checking against a null pointer. The second part is a method call that translates into another null pointer check, essentially state->_main_greenlet->_ptr != NULL.

The next frame up is...jumping into the Python binary image!? There's nothing there that should make that possible; at no time does this execute any CPython functions. Now, has_main_greenlet() is an inline function, so perhaps that explains it---optimizations can mess up debugging.

Finally, the top frame is where we're actually executing _main_greenlet->_ptr != NULL. The only way that could crash with a segfault is if _main_greenlet, the object itself, is now deallocated somehow. But _main_greenlet is a struct in the ThreadState struct, meaning the only way it could get deallocated is if ThreadState is already deallocated (but not yet null).

The ThreadState object is allocated from the heap (using PyObject_Malloc), and it is deallocated only by this particular code path (using PyObject_Free). This particular code path is only invoked by the C runtime when the thread exits and the runtime cleans up thread-local variables (these are frames 5, 6, and 7). So how could ThreadState already be deallocated? I see two possibilities:

First, Python itself could be doing something at thread exit time and freeing memory allocated by the thread. It doesn't do that, so we can rule that out.

Second, something is broken with thread local variables (and/or thread local variable cleanup) such that it's running more than once, or has already deallocated the memory (holding the pointer itself) before running the cleanup code.

Since this is a pre-release of an ancient platform (2009) running code that depends on C++ 11 features, that second possibility seems the more likely.

I can only think of three possible ways forward.

First, you can try compiling with optimizations disabled (-O0). That's been known to solve strange problems like this.

Second, you could try experimenting with the PYTHONMALLOC environment variable at test time, setting it to use different allocators (malloc and malloc_debug would be the only ones that make sense) and see if that makes any difference. (I would be surprised if it did, and that's probably not something you'd want to recommend for end users anyway.)

Failing that, we can disable thread-local cleanup for this platform and just let thread data leak. Since nobody should be using this platform for anything serious, that's unlikely to be a major problem.

@barracuda156 Could you try with optimizations disabled? If that's a no-go, I'll disable cleanup, merge this patch, and call it good.

@barracuda156
Copy link
Contributor Author

barracuda156 commented Sep 19, 2024

@jamadden Sure, I will rebuild with optimizations off and update on the results.

P. S. I am not aware of anything in C++11 not working on this platform. Of course, for C++11 and up it uses modern libstdc++ from GCC (libgcc14 presently). As long as there are no SDK-dependent features, it is irrelevant what macOS version it is.
In fact, even C++23 is mostly supported and ports using C++23 build fine. There are a couple of exceptions which result from usage of -D_GLIBCXX_USE_CXX11_ABI=0 (that makes a few features unavailable, but so far this affected 2–3 ports out of thousands).

@jamadden
Copy link
Contributor

jamadden commented Sep 19, 2024

I am not aware of anything in C++11 not working on this platform. Of course, for C++11 and up it uses modern libstdc++ from GCC (libgcc14 presently). As long as there are no SDK-dependent features, it is irrelevant what macOS version it is.

I'm not sure that's true. Here are the bottom three frames; the first column is the shared library that the code is from, the second is the address of the function being executed:

5   libstdc++.6.dylib             	0x02433588 __cxxabiv1::__array_type_info::~__array_type_info() + 56
6   libSystem.B.dylib             	0x00c574a8 _pthread_tsd_cleanup + 244
7   libSystem.B.dylib             	0x00c56fc0 _pthread_exit + 116

Obviously the actual threading exit and thread local cleanup (frames 6 and 7) is initiated by libSystem, which of course is part of the OS.

Frame 5 is the C++ cleanup, from libstdc++.6.dylib. Earlier, when you posted the complete crash report, we saw:

 0x11e2000 -  0x124cffb  libstdc++.6.dylib ??? (???) <5824de0c43054a01c556e9ef288f33c7> /usr/lib/libstdc++.6.dylib
 0x241c000 -  0x2582ff3 +libstdc++.6.dylib ??? (???) <45dc6049a880333f99d32835fae31186> /opt/local/lib/libgcc/libstdc++.6.dylib
 0x3000000 -  0x3166ff3 +libstdc++.6.dylib ??? (???) <45dc6049a880333f99d32835fae31186> /opt/local/lib/libgcc/libstdc++.6.dylib

There are THREE libstdc++ libraries being loaded. MacOS uses two-level namespacing for resolving symbols, so it wouldn't be surprising to see TWO libraries (the system and the gcc), but seeing three is surprising. It wouldn't shock me if greenlet is using one, and the system is calling into the other; they'll have separate data sections, and I can imagine that they're not fully compatible or synchronized, and I can further imagine that being a problem.

@barracuda156
Copy link
Contributor Author

/opt/local/lib/libgcc/libstdc++.6.dylib is listed twice, it cannot be two different libraries, since they point to the same file.
/usr/lib/libstdc++.6.dylib is the system one.

The good question is whether the right one is being used. I will look into this. (libSystem.B.dylib is, of course, a part of the OS, but I was only talking about C++ support, not that it does not matter for anything whatsoever.)

@jamadden
Copy link
Contributor

/opt/local/lib/libgcc/libstdc++.6.dylib is listed twice, it cannot be two different libraries, since they point to the same file.

It's mapped to two different address ranges. Hence there are two copies loaded.

@barracuda156
Copy link
Contributor Author

Thanks for bringing this C++ runtime issue, it is a well-known thing, but I did not consider that tests are compiling stuff and therefore need this issue taken care of.

After export DYLD_LIBRARY_PATH=/opt/local/lib/libgcc I reran tests, and the crash is different:

Process:         Python [37689]
Path:            /opt/local/Library/Frameworks/Python.framework/Versions/3.11/Resources/Python.app/Contents/MacOS/Python
Identifier:      Python
Version:         ??? (???)
Code Type:       PPC (Native)
Parent Process:  Python [37686]

Date/Time:       2024-09-19 22:58:06.573 +0800
OS Version:      Mac OS X 10.6 (10A190)
Report Version:  6

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Crashed Thread:  0

Application Specific Information:
abort() called

Thread 0 Crashed:
0   libSystem.B.dylib             	0x00c90d48 __kill + 12
1   libSystem.B.dylib             	0x00d34808 abort + 116
2   org.python.python             	0x005fec6c fatal_error + 52
3   org.python.python             	0x005ff020 _Py_FatalErrorFunc + 64
4   ...enlet.cpython-311-darwin.so	0x024c28ac greenlet::Greenlet::g_switchstack() + 688 (TGreenlet.cpp:196)
5   ...enlet.cpython-311-darwin.so	0x024c6a00 greenlet::BrokenGreenlet::g_switchstack() + 76 (TBrokenGreenlet.cpp:42)
6   ...enlet.cpython-311-darwin.so	0x024c4c30 greenlet::UserGreenlet::g_switch() + 380 (TUserGreenlet.cpp:155)
7   ...enlet.cpython-311-darwin.so	0x024c85c0 __ZL12green_switchP9_greenletP7_objectS2_ + 220
8   org.python.python             	0x00520b30 method_vectorcall_VARARGS_KEYWORDS + 224
9   org.python.python             	0x00516a38 _PyObject_VectorcallTstate + 128
10  org.python.python             	0x005cb818 _PyEval_EvalFrameDefault + 29156
11  org.python.python             	0x005cdd20 _PyEval_Vector + 200
12  org.python.python             	0x005cdde4 PyEval_EvalCode + 168
13  org.python.python             	0x006023fc run_eval_code_obj + 72
14  org.python.python             	0x0060268c run_mod + 168
15  org.python.python             	0x00602734 pyrun_file + 148
16  org.python.python             	0x00604850 _PyRun_SimpleFileObject + 972
17  org.python.python             	0x00604984 _PyRun_AnyFileObject + 188
18  org.python.python             	0x0061c210 Py_RunMain + 1556
19  org.python.python             	0x0061c4b4 Py_BytesMain + 40
20  org.python.python             	0x00002f84 0x1000 + 8068

Thread 0 crashed with PPC Thread State 32:
  srr0: 0x00c90d48  srr1: 0x0200f030   dar: 0x6ff6b000 dsisr: 0x42000000
    r0: 0x00000025    r1: 0xbfffeb60    r2: 0x0000017f    r3: 0x00000000
    r4: 0x00000000    r5: 0x00000001    r6: 0x00000000    r7: 0x00000000
    r8: 0x0072e314    r9: 0x00e1bedc   r10: 0x00c5cbc4   r11: 0x000014f9
   r12: 0x00c90d34   r13: 0x022da668   r14: 0x024b70c8   r15: 0x02842a3c
   r16: 0x00000000   r17: 0x02274afa   r18: 0x000000ab   r19: 0x007c6544
   r20: 0xbfffebf8   r21: 0xbfffebfc   r22: 0xbfffec00   r23: 0xffffffff
   r24: 0x007bec40   r25: 0x00000001   r26: 0x007cdeb4   r27: 0x007db114
   r28: 0x006a3d07   r29: 0x007db114   r30: 0x00000002   r31: 0x00d347a0
    cr: 0x22002402   xer: 0x00000000    lr: 0x00d3480c   ctr: 0x00c90d34
vrsave: 0x00000000

Binary Images:
    0x1000 -     0x2fff +org.python.python 3.11.10 (3.11.10) <481ef62fcb236d8f44661d80f6c51cf0> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/Resources/Python.app/Contents/MacOS/Python
    0x5000 -     0x5fff +libgcc_s.1.dylib ??? (???) <52f8e6b93cfbb9fa40f44e2651069377> /opt/local/lib/libgcc/libgcc_s.1.dylib
    0x9000 -     0xfffb +libgcc_s.1.1.dylib ??? (???) <76536840887abc14c11e4540683ab052> /opt/local/lib/libgcc/libgcc_s.1.1.dylib
   0x12000 -    0x17fff +libgcc_ehs.1.1.dylib ??? (???) <e85639846153a4238fabdb431bf1e591> /opt/local/lib/libgcc/libgcc_ehs.1.1.dylib
   0x1f000 -    0x38fff +libintl.8.dylib ??? (???) <e614775697f80c705e9a5000be1a088a> /opt/local/lib/libintl.8.dylib
   0x3e000 -    0x3effa  com.apple.CoreServices 41 (41) <97bf3903384c706ba0f7d19577f0ef8c> /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices
   0x54000 -    0x59ff6  libmathCommon.A.dylib ??? (???) <e166c8e59a80a82b4504b1dd43d1f50a> /usr/lib/system/libmathCommon.A.dylib
   0x5d000 -    0x90ff1  libauto.dylib ??? (???) <2848423526fb9c0f381c6ceacc4f2c27> /usr/lib/libauto.dylib
   0x9c000 -    0xaafff  libz.1.dylib ??? (???) <c296d00fd65aa7271f3d5592c25c0f96> /usr/lib/libz.1.dylib
   0xaf000 -    0xb8fff  com.apple.DiskArbitration 2.2.1 (2.2.1) <daa422fc5a934366c8f0a12204b46cb1> /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration
   0xe4000 -    0xf6fff  libbsm.0.dylib ??? (???) <c43c47af4211639e8828d3e8ff93a019> /usr/lib/libbsm.0.dylib
  0x114000 -   0x137fff  com.apple.DictionaryServices 1.0.0 (1.0.0) <f2f1f85469f3036ec9890bfa888edbe2> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/DictionaryServices.framework/Versions/A/DictionaryServices
  0x1fb000 -   0x208ffe  NetFS ??? (???) <5125b2c825637b243afa1ea942ba8220> /System/Library/Frameworks/NetFS.framework/Versions/A/NetFS
  0x20f000 -   0x218ffc  libkxld.dylib ??? (???) <725cd6e644549962b0110493f4bb7c08> /usr/lib/system/libkxld.dylib
  0x4d7000 -   0x702ffb +org.python.python 3.11.10, (c) 2001-2023 Python Software Foundation. (3.11.10) <83ced5a242580512eafec1ca5970e2a5> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/Python
  0x9ae000 -   0xb06ff7  com.apple.CoreFoundation 6.6 (511.1) <b82d52070a5949f92c5001e06d67044b> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
  0xc10000 -   0xddafe7  libSystem.B.dylib ??? (???) <420b38fe0fa0944f6f5bc4840bf29a4e> /usr/lib/libSystem.B.dylib
  0xe62000 -   0xf67fff +libiconv.2.dylib ??? (???) <71dfab8f77eb71baebdb38550a0ed408> /opt/local/lib/libiconv.2.dylib
  0xf76000 -  0x10fffff  libicucore.A.dylib ??? (???) <28f339176d9e26b663f19c1cad91784e> /usr/lib/libicucore.A.dylib
 0x114f000 -  0x11d0fe7  libobjc.A.dylib ??? (???) <bb09ce82013fa9c4a4010c58fe6c1e10> /usr/lib/libobjc.A.dylib
 0x11e2000 -  0x1348ff3 +libstdc++.6.dylib ??? (???) <45dc6049a880333f99d32835fae31186> /opt/local/lib/libgcc/libstdc++.6.dylib
 0x13c8000 -  0x16eeff7  com.apple.CoreServices.CarbonCore 818 (818) <3e631022aef7f9d15373e1f56e74ff00> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/CarbonCore
 0x1777000 -  0x1837ffb  com.apple.CFNetwork 417.1 (417.1) <911e0fa87591b77e8bb8ec4759941216> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CFNetwork.framework/Versions/A/CFNetwork
 0x189f000 -  0x18dffff  com.apple.Metadata 10.6.0 (429.1) <d8b50a8ca605800f8f36caf448daed42> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Metadata.framework/Versions/A/Metadata
 0x18f8000 -  0x19d0fff  com.apple.CoreServices.OSServices 310 (310) <633ea4081155a516c80bf948f004d235> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Versions/A/OSServices
 0x1a3b000 -  0x1ab8ffb  com.apple.SearchKit 1.3.0 (1.3.0) <4c7ffa79c1cd48d28eb165768fbfc2f4> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/SearchKit.framework/Versions/A/SearchKit
 0x1af7000 -  0x1b2ffff  com.apple.AE 464 (464) <492b7cdb81e64fca5af300b0c231ebec> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/AE
 0x1b47000 -  0x1bdeff7  com.apple.LaunchServices 318.1 (318.1) <5ee43f629f636d1863e73dc312c736c2> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/LaunchServices
 0x1c24000 -  0x1c7aff3  com.apple.framework.IOKit 1.5.1 (???) <21f9b751b7578a33306804af2c6ded8d> /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit
 0x1c93000 -  0x1ec1ff7  com.apple.security 6.0 (34772) <df4f0710dfee6e04e7fdba557064977b> /System/Library/Frameworks/Security.framework/Versions/A/Security
 0x1fd8000 -  0x2089ff7  libsqlite3.0.dylib ??? (???) <cc6135a5433e43988bf825e149e47483> /usr/lib/libsqlite3.0.dylib
 0x2095000 -  0x20d0fff  com.apple.SystemConfiguration 1.10 (1.10) <2daf422a1a7ca90ba32720000e56b3aa> /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration
 0x20ec000 -  0x2118fff  libxslt.1.dylib ??? (???) <da4552da93bf856897f6b399bb10806d> /usr/lib/libxslt.1.dylib
 0x2121000 -  0x223cfff  libxml2.2.dylib ??? (???) <2bdb2ca8d4aabba550ba9f2111ebf46a> /usr/lib/libxml2.2.dylib
 0x24c0000 -  0x24e7fff +_greenlet.cpython-311-darwin.so ??? (???) <cbb0d9c89c133dd97dc3e197f72e50aa> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/greenlet/_greenlet.cpython-311-darwin.so
0x8fe00000 - 0x8fe31143  dyld 113.0 (???) <ee555e655e1cf66cac80728801add419> /usr/lib/dyld
0xffff8000 - 0xffff9703  libSystem.B.dylib ??? (???) /usr/lib/libSystem.B.dylib

@jamadden
Copy link
Contributor

There are at least two expected crashes of subprocesses during the test run, but I don't think that's one of them. Could you say which test was running?

Assuming it's not an expected crash, that's a failure in slp_switch; it returned an error (< 0). slp_switch, of course, is the function being patched here.

@barracuda156
Copy link
Contributor Author

@jamadden Let me rerun this cleanly. I will also rebuild with -O0 prior to that.

@barracuda156
Copy link
Contributor Author

Yes, I copied a wrong crash earlier. This is the third one:

Process:         Python [1400]
Path:            /opt/local/Library/Frameworks/Python.framework/Versions/3.11/Resources/Python.app/Contents/MacOS/Python
Identifier:      Python
Version:         ??? (???)
Code Type:       PPC (Native)
Parent Process:  zsh [1355]

Date/Time:       2024-09-20 00:04:39.846 +0800
OS Version:      Mac OS X 10.6 (10A190)
Report Version:  6

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000c08c1867
Crashed Thread:  1

Thread 0:
0   org.python.python             	0x005981c0 handle_callback + 8
1   org.python.python             	0x0059b2dc PyObject_ClearWeakRefs + 280
2   org.python.python             	0x005e3cc4 _PyFrame_Clear + 292
3   org.python.python             	0x005c137c _PyEvalFrameClearAndPop + 40
4   org.python.python             	0x005cdd30 _PyEval_Vector + 216
5   org.python.python             	0x005cce8c _PyEval_EvalFrameDefault + 34904
6   org.python.python             	0x005cdd20 _PyEval_Vector + 200
7   org.python.python             	0x00517724 _PyObject_FastCallDictTstate + 164
8   org.python.python             	0x005179b4 _PyObject_Call_Prepend + 132
9   org.python.python             	0x00569d40 slot_tp_call + 108
10  org.python.python             	0x00516918 _PyObject_MakeTpCall + 236
11  org.python.python             	0x005cb818 _PyEval_EvalFrameDefault + 29156
12  org.python.python             	0x005cdd20 _PyEval_Vector + 200
13  org.python.python             	0x00518ac4 _PyObject_VectorcallTstate + 116
14  org.python.python             	0x00518d98 method_vectorcall + 272
15  org.python.python             	0x005cce8c _PyEval_EvalFrameDefault + 34904
16  org.python.python             	0x005cdd20 _PyEval_Vector + 200
17  org.python.python             	0x00517724 _PyObject_FastCallDictTstate + 164
18  org.python.python             	0x005179b4 _PyObject_Call_Prepend + 132
19  org.python.python             	0x00569d40 slot_tp_call + 108
20  org.python.python             	0x00516918 _PyObject_MakeTpCall + 236
21  org.python.python             	0x005cb818 _PyEval_EvalFrameDefault + 29156
22  org.python.python             	0x005cdd20 _PyEval_Vector + 200
23  org.python.python             	0x00518ac4 _PyObject_VectorcallTstate + 116
24  org.python.python             	0x00518d98 method_vectorcall + 272
25  org.python.python             	0x005cce8c _PyEval_EvalFrameDefault + 34904
26  org.python.python             	0x005cdd20 _PyEval_Vector + 200
27  org.python.python             	0x00517724 _PyObject_FastCallDictTstate + 164
28  org.python.python             	0x005179b4 _PyObject_Call_Prepend + 132
29  org.python.python             	0x00569d40 slot_tp_call + 108
30  org.python.python             	0x00516918 _PyObject_MakeTpCall + 236
31  org.python.python             	0x005cb818 _PyEval_EvalFrameDefault + 29156
32  org.python.python             	0x005cdd20 _PyEval_Vector + 200
33  org.python.python             	0x00518ac4 _PyObject_VectorcallTstate + 116
34  org.python.python             	0x00518d98 method_vectorcall + 272
35  org.python.python             	0x005cce8c _PyEval_EvalFrameDefault + 34904
36  org.python.python             	0x005cdd20 _PyEval_Vector + 200
37  org.python.python             	0x00517724 _PyObject_FastCallDictTstate + 164
38  org.python.python             	0x005179b4 _PyObject_Call_Prepend + 132
39  org.python.python             	0x00569d40 slot_tp_call + 108
40  org.python.python             	0x00516918 _PyObject_MakeTpCall + 236
41  org.python.python             	0x005cb818 _PyEval_EvalFrameDefault + 29156
42  org.python.python             	0x005cdd20 _PyEval_Vector + 200
43  org.python.python             	0x00517724 _PyObject_FastCallDictTstate + 164
44  org.python.python             	0x005179b4 _PyObject_Call_Prepend + 132
45  org.python.python             	0x00569c4c slot_tp_init + 108
46  org.python.python             	0x00566910 type_call + 324
47  org.python.python             	0x00516918 _PyObject_MakeTpCall + 236
48  org.python.python             	0x005cb818 _PyEval_EvalFrameDefault + 29156
49  org.python.python             	0x005cdd20 _PyEval_Vector + 200
50  org.python.python             	0x005cdde4 PyEval_EvalCode + 168
51  org.python.python             	0x005becbc builtin_exec + 668
52  org.python.python             	0x005503a8 cfunction_vectorcall_FASTCALL_KEYWORDS + 84
53  org.python.python             	0x00516a38 _PyObject_VectorcallTstate + 128
54  org.python.python             	0x005cb818 _PyEval_EvalFrameDefault + 29156
55  org.python.python             	0x005cdd20 _PyEval_Vector + 200
56  org.python.python             	0x0061b8a4 pymain_run_module + 420
57  org.python.python             	0x0061c060 Py_RunMain + 1124
58  org.python.python             	0x0061c4b4 Py_BytesMain + 40
59  org.python.python             	0x00002f84 0x1000 + 8068

Thread 1 Crashed:
0   ...enlet.cpython-311-darwin.so	0x02512b58 greenlet::refs::PyObjectPointer<_greenlet, &(greenlet::refs::MainGreenletExactChecker(void*))>::operator bool() const + 20 (greenlet_refs.hpp:221)
1   org.python.python             	0x0069e96c 0x4d7000 + 1866092
2   ...enlet.cpython-311-darwin.so	0x025100cc greenlet::ThreadState_DestroyNoGIL::MarkGreenletDeadIfNeeded(greenlet::ThreadState*) + 48 (TThreadStateDestroy.cpp:70)
3   ...enlet.cpython-311-darwin.so	0x02510044 greenlet::ThreadState_DestroyNoGIL::MarkGreenletDeadAndQueueCleanup(greenlet::ThreadState*) + 28 (TThreadStateDestroy.cpp:43)
4   ...enlet.cpython-311-darwin.so	0x02517dc0 greenlet::ThreadStateCreator<&(greenlet::ThreadState_DestroyNoGIL::MarkGreenletDeadAndQueueCleanup(greenlet::ThreadState*))>::~ThreadStateCreator() + 56
5   libstdc++.6.dylib             	0x011e5588 __cxxabiv1::__array_type_info::~__array_type_info() + 56
6   libSystem.B.dylib             	0x00c574a8 _pthread_tsd_cleanup + 244
7   libSystem.B.dylib             	0x00c56fc0 _pthread_exit + 116

Thread 1 crashed with PPC Thread State 32:
  srr0: 0x02512b58  srr1: 0x0200f030   dar: 0xc08c1867 dsisr: 0x00200000
    r0: 0x0250f194    r1: 0xf1000c30    r2: 0xc08c1867    r3: 0xc08c1867
    r4: 0x00000000    r5: 0x00000000    r6: 0x00000001    r7: 0x023fc094
    r8: 0x00000180    r9: 0xc08c1865   r10: 0x000d2500   r11: 0x0252863c
   r12: 0x02512b44   r13: 0x00000000   r14: 0x00000000   r15: 0x00000000
   r16: 0x00000000   r17: 0x00000000   r18: 0x00000000   r19: 0x00000000
   r20: 0x00000000   r21: 0x00000000   r22: 0x00de73bc   r23: 0x00de73bc
   r24: 0x00e16b7c   r25: 0x00000000   r26: 0x00de73bc   r27: 0xf1001000
   r28: 0x00000107   r29: 0xf1001464   r30: 0xf1000c30   r31: 0x025100b4
    cr: 0x88000444   xer: 0x20000000    lr: 0x0250f194   ctr: 0x02512b44
vrsave: 0x00000fff

Binary Images:
    0x1000 -     0x2fff +org.python.python 3.11.10 (3.11.10) <481ef62fcb236d8f44661d80f6c51cf0> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/Resources/Python.app/Contents/MacOS/Python
    0x5000 -     0x5fff +libgcc_s.1.dylib ??? (???) <52f8e6b93cfbb9fa40f44e2651069377> /opt/local/lib/libgcc/libgcc_s.1.dylib
    0x9000 -     0xfffb +libgcc_s.1.1.dylib ??? (???) <76536840887abc14c11e4540683ab052> /opt/local/lib/libgcc/libgcc_s.1.1.dylib
   0x12000 -    0x17fff +libgcc_ehs.1.1.dylib ??? (???) <e85639846153a4238fabdb431bf1e591> /opt/local/lib/libgcc/libgcc_ehs.1.1.dylib
   0x1f000 -    0x38fff +libintl.8.dylib ??? (???) <e614775697f80c705e9a5000be1a088a> /opt/local/lib/libintl.8.dylib
   0x3e000 -    0x3effa  com.apple.CoreServices 41 (41) <97bf3903384c706ba0f7d19577f0ef8c> /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices
   0x54000 -    0x59ff6  libmathCommon.A.dylib ??? (???) <e166c8e59a80a82b4504b1dd43d1f50a> /usr/lib/system/libmathCommon.A.dylib
   0x5d000 -    0x90ff1  libauto.dylib ??? (???) <2848423526fb9c0f381c6ceacc4f2c27> /usr/lib/libauto.dylib
   0x9c000 -    0xaafff  libz.1.dylib ??? (???) <c296d00fd65aa7271f3d5592c25c0f96> /usr/lib/libz.1.dylib
   0xaf000 -    0xb8fff  com.apple.DiskArbitration 2.2.1 (2.2.1) <daa422fc5a934366c8f0a12204b46cb1> /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration
   0xe4000 -    0xf6fff  libbsm.0.dylib ??? (???) <c43c47af4211639e8828d3e8ff93a019> /usr/lib/libbsm.0.dylib
  0x114000 -   0x137fff  com.apple.DictionaryServices 1.0.0 (1.0.0) <f2f1f85469f3036ec9890bfa888edbe2> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/DictionaryServices.framework/Versions/A/DictionaryServices
  0x1fb000 -   0x208ffe  NetFS ??? (???) <5125b2c825637b243afa1ea942ba8220> /System/Library/Frameworks/NetFS.framework/Versions/A/NetFS
  0x20f000 -   0x218ffc  libkxld.dylib ??? (???) <725cd6e644549962b0110493f4bb7c08> /usr/lib/system/libkxld.dylib
  0x224000 -   0x227ffd +_heapq.cpython-311-darwin.so ??? (???) <9418d1a11b34db571c4867b9575932a5> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/_heapq.cpython-311-darwin.so
  0x4d7000 -   0x702ffb +org.python.python 3.11.10, (c) 2001-2023 Python Software Foundation. (3.11.10) <83ced5a242580512eafec1ca5970e2a5> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/Python
  0x9ae000 -   0xb06ff7  com.apple.CoreFoundation 6.6 (511.1) <b82d52070a5949f92c5001e06d67044b> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
  0xc10000 -   0xddafe7  libSystem.B.dylib ??? (???) <420b38fe0fa0944f6f5bc4840bf29a4e> /usr/lib/libSystem.B.dylib
  0xe62000 -   0xf67fff +libiconv.2.dylib ??? (???) <71dfab8f77eb71baebdb38550a0ed408> /opt/local/lib/libiconv.2.dylib
  0xf76000 -  0x10fffff  libicucore.A.dylib ??? (???) <28f339176d9e26b663f19c1cad91784e> /usr/lib/libicucore.A.dylib
 0x114f000 -  0x11d0fe7  libobjc.A.dylib ??? (???) <bb09ce82013fa9c4a4010c58fe6c1e10> /usr/lib/libobjc.A.dylib
 0x11e2000 -  0x1348ff3 +libstdc++.6.dylib ??? (???) <45dc6049a880333f99d32835fae31186> /opt/local/lib/libgcc/libstdc++.6.dylib
 0x13c8000 -  0x16eeff7  com.apple.CoreServices.CarbonCore 818 (818) <3e631022aef7f9d15373e1f56e74ff00> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/CarbonCore
 0x1777000 -  0x1837ffb  com.apple.CFNetwork 417.1 (417.1) <911e0fa87591b77e8bb8ec4759941216> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CFNetwork.framework/Versions/A/CFNetwork
 0x189f000 -  0x18dffff  com.apple.Metadata 10.6.0 (429.1) <d8b50a8ca605800f8f36caf448daed42> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Metadata.framework/Versions/A/Metadata
 0x18f8000 -  0x19d0fff  com.apple.CoreServices.OSServices 310 (310) <633ea4081155a516c80bf948f004d235> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Versions/A/OSServices
 0x1a3b000 -  0x1ab8ffb  com.apple.SearchKit 1.3.0 (1.3.0) <4c7ffa79c1cd48d28eb165768fbfc2f4> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/SearchKit.framework/Versions/A/SearchKit
 0x1af7000 -  0x1b2ffff  com.apple.AE 464 (464) <492b7cdb81e64fca5af300b0c231ebec> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/AE
 0x1b47000 -  0x1bdeff7  com.apple.LaunchServices 318.1 (318.1) <5ee43f629f636d1863e73dc312c736c2> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/LaunchServices
 0x1c24000 -  0x1c7aff3  com.apple.framework.IOKit 1.5.1 (???) <21f9b751b7578a33306804af2c6ded8d> /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit
 0x1c93000 -  0x1ec1ff7  com.apple.security 6.0 (34772) <df4f0710dfee6e04e7fdba557064977b> /System/Library/Frameworks/Security.framework/Versions/A/Security
 0x1fd8000 -  0x2089ff7  libsqlite3.0.dylib ??? (???) <cc6135a5433e43988bf825e149e47483> /usr/lib/libsqlite3.0.dylib
 0x2095000 -  0x20d0fff  com.apple.SystemConfiguration 1.10 (1.10) <2daf422a1a7ca90ba32720000e56b3aa> /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration
 0x20ec000 -  0x2118fff  libxslt.1.dylib ??? (???) <da4552da93bf856897f6b399bb10806d> /usr/lib/libxslt.1.dylib
 0x2121000 -  0x223cfff  libxml2.2.dylib ??? (???) <2bdb2ca8d4aabba550ba9f2111ebf46a> /usr/lib/libxml2.2.dylib
 0x2500000 -  0x2527fff +_greenlet.cpython-311-darwin.so ??? (???) <92293da4486193b1c60090f43c042cee> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/greenlet/_greenlet.cpython-311-darwin.so
 0x2610000 -  0x2610ffe +_opcode.cpython-311-darwin.so ??? (???) <be7904e7abbbd5b4b70f2b778a55fe54> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/_opcode.cpython-311-darwin.so
 0x2613000 -  0x261cfff +math.cpython-311-darwin.so ??? (???) <383a1047b358d11c718e1a5057d105bc> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/math.cpython-311-darwin.so
 0x2623000 -  0x2625ffc +fcntl.cpython-311-darwin.so ??? (???) <5c0ab3597712a7e5f59751959ec05c35> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/fcntl.cpython-311-darwin.so
 0x2628000 -  0x262affd +_posixsubprocess.cpython-311-darwin.so ??? (???) <0e838013f07d3579fe619ea4efc82d58> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/_posixsubprocess.cpython-311-darwin.so
 0x262e000 -  0x262fffd +_bisect.cpython-311-darwin.so ??? (???) <415b2b38122a3110cbff444959bff5d0> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/_bisect.cpython-311-darwin.so
 0x2773000 -  0x277fffb +_datetime.cpython-311-darwin.so ??? (???) <55249b02b5a7da9b024dd8d8f8104eaa> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/_datetime.cpython-311-darwin.so
 0x278b000 -  0x278effe +select.cpython-311-darwin.so ??? (???) <d48f12428fb711dc94ad11cf7dd307f1> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/select.cpython-311-darwin.so
 0x2792000 -  0x279fffc +_socket.cpython-311-darwin.so ??? (???) <c22d8f5f9dd1602b79e012e8f47de39a> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/_socket.cpython-311-darwin.so
 0x27a7000 -  0x27aeffe +array.cpython-311-darwin.so ??? (???) <f06b90f4014a0bdeba7e5ef65e98d461> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/array.cpython-311-darwin.so
 0x27f6000 -  0x27fbffd +zlib.cpython-311-darwin.so ??? (???) <0f07649f811221d6471214af6b87fb69> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/zlib.cpython-311-darwin.so
 0x3000000 -  0x3013ffc +libz.1.dylib ??? (???) <b137603b6672e715558e6403b48f02ad> /opt/local/lib/libz.1.dylib
 0x3017000 -  0x3019ffd +_bz2.cpython-311-darwin.so ??? (???) <e38f682cf6a1a340f2a66fb6bd3d53cb> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/_bz2.cpython-311-darwin.so
 0x301d000 -  0x302bff5 +libbz2.1.0.dylib ??? (???) <561eabf373907c3899487650867150dc> /opt/local/lib/libbz2.1.0.dylib
 0x302f000 -  0x3034ffd +_lzma.cpython-311-darwin.so ??? (???) <2bda2c6d751cadc380fc1a3ddf891378> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/_lzma.cpython-311-darwin.so
 0x3039000 -  0x305fff8 +liblzma.5.dylib ??? (???) <0c04cedbfcb4e1a313590e997f6ea784> /opt/local/lib/liblzma.5.dylib
 0x30a5000 -  0x30adfff +_psutil_osx.abi3.so ??? (???) <2e04cd0ee5db9def2f709cd9e85f9bd6> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/psutil/_psutil_osx.abi3.so
 0x30b3000 -  0x30b5fff +_psutil_posix.abi3.so ??? (???) <8240d2ffa9e5687440b61a1f1b273e58> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/psutil/_psutil_posix.abi3.so
 0x30b9000 -  0x30bafff +_random.cpython-311-darwin.so ??? (???) <894a627a5928e1a5db979d9b0d003e06> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/_random.cpython-311-darwin.so
 0x30be000 -  0x30c5ffc +_sha512.cpython-311-darwin.so ??? (???) <c03c56a0fa4874bfb7d5d94fd92e48ec> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/_sha512.cpython-311-darwin.so
 0x3149000 -  0x3149fff +_typing.cpython-311-darwin.so ??? (???) <4bbc87f80651c648ff17e53e36dc5914> /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/_typing.cpython-311-darwin.so
0x8fe00000 - 0x8fe31143  dyld 113.0 (???) <ee555e655e1cf66cac80728801add419> /usr/lib/dyld
0xffff8000 - 0xffff9703  libSystem.B.dylib ??? (???) /usr/lib/libSystem.B.dylib

Re optimizations: I passed -O0, however the build also adds -O3 and -Os (the last one perhaps from MacPorts side). I am not sure this works correctly. Can I override whatever Python itself adds?

@jamadden
Copy link
Contributor

Re optimizations: I passed -O0, however the build also adds -O3 and -Os (the last one perhaps from MacPorts side). I am not sure this works correctly.

So long as -O0 comes last on the command line, that should be the one that takes effect. Quoth the manual:

If you use multiple -O options, with or without level numbers, the last such option is the one that is effective.

Can I override whatever Python itself adds?

The only way I know of doing this is to actually edit the sysconfig data file and remove all occurrences of whatever flag you're trying to get rid of. For MacPorts 3.11, it should be /opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/_sysconfigdata__darwin_darwin.py

I wish I knew a better way. I maintain two copies of that file, one being the original file containing the right flags for clang, and the other being modified to work with gcc.

@jamadden
Copy link
Contributor

I'm unable to make further progress on this. Despite the excellent instructions provided by @barracuda156 I'm simply not going to have the time to set up a pre-release development environment on one of my 32-bit machines.

Therefore, I will go with the fallback plan of merging this patch and disabling thread cleanup on this platform. If we get more information or someone comes forward with a patch, I will happily revisit the issue.

@jamadden jamadden merged commit 6081a16 into python-greenlet:master Sep 20, 2024
23 checks passed
@glaubitz
Copy link

Therefore, I will go with the fallback plan of merging this patch and disabling thread cleanup on this platform. If we get more information or someone comes forward with a patch, I will happily revisit the issue.

I would suggest pinging @he32 before merging a patch that touches BSD code.

@jamadden
Copy link
Contributor

This doesn't touch BSD code. It's strictly 32-bit PPC on MacOSX.

@barracuda156
Copy link
Contributor Author

@jamadden The setup from scratch will probably take about 2 hrs all in, but debugging may take a lot more, of course. Time is a scarce resource.

I support your suggestion for now, but I hope we can improve on that. (Sorry, I can‘t really be useful for Python debugging myself beyond running tests, I consistently avoided Python so far, LOL.)

@barracuda156 barracuda156 deleted the powerpc branch September 20, 2024 14:55
@barracuda156
Copy link
Contributor Author

@jamadden And that you very much for caring to fix this. This is really appreciated.

@glaubitz
Copy link

This doesn't touch BSD code. It's strictly 32-bit PPC on MacOSX.

This commit touched BSD code for PowerPC.

@jamadden
Copy link
Contributor

True, it did, and it seems correct to me. If there's a regression on NetBSD, the only platform using that file, I await the bug report and patch. I need to close this out and move on. I've spent far too much time on it as is.

@barracuda156
Copy link
Contributor Author

@glaubitz I have a strong impression the earlier commit changing that code was off. Correct me if I am wrong, but AFAIK the only platform using r-prefixed registers is Darwin, not even AIX (though otherwise they are supposed to be at least close).
Errors happen (Boost still has a chunk of ppc64 code commented out, accidentally, and unfixed for years), we are correcting one here, IMO.

@barracuda156
Copy link
Contributor Author

@glaubitz UPD. In fact commits here do not touch that, I confused another recent issue with ppc assembler elsewhere with this.
But if something looks wrong to you, please correct it for BSD or Linux.

@glaubitz
Copy link

My point is that there was a change to a slightly unrelated platform without actually testing the change.

You should have installed NetBSD for macppc on your PowerMac and verified the change before submitting it.

@barracuda156
Copy link
Contributor Author

Well, honestly I’d be surprised if the correct assembler for NetBSD is identical to a wrong one on macOS and Linux on the same architecture, but I can try requesting someone with BSD to verify this. (I do get your point, but I think this case is fairly trivial.)

shaldengeki referenced this pull request in shaldengeki/monorepo Sep 24, 2024
Bumps [greenlet](https://github.com/python-greenlet/greenlet) from 3.0.3
to 3.1.1.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/python-greenlet/greenlet/blob/master/CHANGES.rst">greenlet's
changelog</a>.</em></p>
<blockquote>
<h1>3.1.1 (2024-09-20)</h1>
<ul>
<li>Fix crashes on 32-bit PPC Linux. Note that there is no CI for this,
and support is best effort; there may be other issues lurking.
See <code>issue 422
&lt;https://github.com/python-greenlet/greenlet/issues/422&gt;</code>_.</li>
<li>Remove unnecessary logging sometimes during interpreter shutdown.
See <code>issue 426
&lt;https://github.com/python-greenlet/greenlet/issues/426&gt;</code>_.</li>
<li>Fix some crashes on 32-bit PPC MacOS. This is a very old platform,
and is only known to be tested on beta versions of an operating
system that was never released, using the GCC 14 only provided by
MacPorts; it may or may not work on the final MacOS X release that
supported 32-bit PowerPC. It has the known issue of leaking memory
when greenlets are used in multiple threads. Help debugging this
would be appreciated. See <code>PR 419
&lt;https://github.com/python-greenlet/greenlet/pull/419&gt;</code>_.</li>
</ul>
<h1>3.1.0 (2024-09-10)</h1>
<p>.. note::</p>
<pre><code>This will be the last release to support Python 3.7 and 3.8.
</code></pre>
<ul>
<li>Adds support for Python 3.13.</li>
</ul>
<p>.. note::</p>
<p>greenlet will not work in no-gil (free threaded) builds of CPython.
Internally, greenlet heavily depends on the GIL.</p>
<ul>
<li>Greatly reduce the chances for crashes during interpreter shutdown.
See <code>issue 411
&lt;https://github.com/python-greenlet/greenlet/issues/411&gt;</code>_.</li>
</ul>
<h2>Platform Support</h2>
<p>Support for the following platforms was contributed by the community.
Note that they are untested by this project's continuous integration
services.</p>
<ul>
<li>Hitachi's <code>SuperH CPU
&lt;https://github.com/python-greenlet/greenlet/issues/166&gt;</code>_.</li>
<li><code>NetBSD on PowerPC.
&lt;https://github.com/python-greenlet/greenlet/pull/402&gt;</code>_</li>
<li>RiscV 64 with <code>-fno-omit-frame-pointer
&lt;https://github.com/python-greenlet/greenlet/pull/404&gt;</code><em>.
Note that
there are <code>known test failures
&lt;https://github.com/python-greenlet/greenlet/issues/403&gt;</code></em>,
so this</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/python-greenlet/greenlet/commit/dd0a948da112a574864b518e5739bd90d068a1b0"><code>dd0a948</code></a>
Preparing release 3.1.1</li>
<li><a
href="https://github.com/python-greenlet/greenlet/commit/ab8d3bc1245f0e454cd3865009f6332a8c0090a0"><code>ab8d3bc</code></a>
Disable thread-local cleanup on 32-bit MacOS PPC with GCC. This will
result i...</li>
<li><a
href="https://github.com/python-greenlet/greenlet/commit/e9db22a94101e10909829c198b6d693ccf11f48f"><code>e9db22a</code></a>
Merge pull request <a
href="https://github.com/python-greenlet/greenlet/issues/429">#429</a>
from python-greenlet/issue419redux</li>
<li><a
href="https://github.com/python-greenlet/greenlet/commit/6081a16bb1c560262b34cf112896a6982756d02c"><code>6081a16</code></a>
Merge pull request <a
href="https://github.com/python-greenlet/greenlet/issues/419">#419</a>
from barracuda156/powerpc</li>
<li><a
href="https://github.com/python-greenlet/greenlet/commit/dbf311a021d80aecb38033a9f44fcf13be9e7a6f"><code>dbf311a</code></a>
Greater safety and fewer assumptions doing cross-thread cleanup.</li>
<li><a
href="https://github.com/python-greenlet/greenlet/commit/9e8a90b1a47e1254df65057af444671e22ca61e0"><code>9e8a90b</code></a>
Set back greenlet_thread_state.hpp file</li>
<li><a
href="https://github.com/python-greenlet/greenlet/commit/1bf374f4d8aaa8039012f70f93249726d23bdf59"><code>1bf374f</code></a>
Duplicate greenlet_thread_state.hpp history.</li>
<li><a
href="https://github.com/python-greenlet/greenlet/commit/64e0b4f6ceaa5cc2debafe551caea1276aa84aa9"><code>64e0b4f</code></a>
Copy greenlet_thread_state.hpp into TThreadStateCreator.hpp</li>
<li><a
href="https://github.com/python-greenlet/greenlet/commit/358a2e8f20816a68e65703b5488dd0337722a9a9"><code>358a2e8</code></a>
Keep greenlet_thread_state.hpp</li>
<li><a
href="https://github.com/python-greenlet/greenlet/commit/5144f7070cd7882f643f6b16a3dbc9138dbbf483"><code>5144f70</code></a>
Sigh. Pip hides compiler output which is, you know, important, and the
only w...</li>
<li>Additional commits viewable in <a
href="https://github.com/python-greenlet/greenlet/compare/3.0.3...3.1.1">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=greenlet&package-manager=pip&previous-version=3.0.3&new-version=3.1.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

5 participants