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

Python library segfaulting on macOS Montery, Intel Core I9, python 3.9 with Conda #24

Open
taalexander opened this issue Jan 6, 2023 · 4 comments

Comments

@taalexander
Copy link
Collaborator

Invoking pytest test/python_lib gives:

Current thread 0x0000000108bc6600 (most recent call first):
  File "<frozen importlib._bootstrap>", line 228 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 1173 in create_module
  File "<frozen importlib._bootstrap>", line 565 in module_from_spec
  File "<frozen importlib._bootstrap>", line 666 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 986 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1007 in _find_and_load
  File "/Users/thomas/Devel/ibm/internal/qss-compiler/build/qss-compiler/python_lib/qss_compiler/__init__.py", line 7 in <module>
  File "<frozen importlib._bootstrap>", line 228 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 855 in exec_module
  File "<frozen importlib._bootstrap>", line 680 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 986 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1007 in _find_and_load
  File "/Users/thomas/Devel/ibm/internal/qss-compiler/qss-compiler/test/python_lib/test_compile.py", line 11 in <module>
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/assertion/rewrite.py", line 171 in exec_module
  File "<frozen importlib._bootstrap>", line 680 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 986 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1007 in _find_and_load
  File "<frozen importlib._bootstrap>", line 1030 in _gcd_import
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/importlib/__init__.py", line 127 in import_module
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/pathlib.py", line 533 in import_path
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/python.py", line 599 in _importtestmodule
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/python.py", line 510 in _getobj
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/python.py", line 296 in obj
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/python.py", line 527 in _inject_setup_module_fixture
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/python.py", line 513 in collect
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/runner.py", line 371 in <lambda>
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/runner.py", line 340 in from_call
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/runner.py", line 371 in pytest_make_collect_report
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/runner.py", line 544 in collect_one_node
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/main.py", line 825 in genitems
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/main.py", line 657 in perform_collect
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/main.py", line 332 in pytest_collection
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/main.py", line 321 in _main
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/main.py", line 268 in wrap_session
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/main.py", line 315 in pytest_cmdline_main
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/pluggy/_callers.py", line 39 in _multicall
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/pluggy/_manager.py", line 80 in _hookexec
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/pluggy/_hooks.py", line 265 in __call__
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/config/__init__.py", line 165 in main
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/lib/python3.9/site-packages/_pytest/config/__init__.py", line 188 in console_main
  File "/Users/thomas/opt/anaconda3/envs/qss-compiler/bin/pytest", line 8 in <module>
zsh: segmentation fault  pytest ../qss-compiler/test/python_lib

Similarily import qss_compiler segfaults.

Of note when building is ld: warning: -undefined dynamic_lookup may not work with chained fixups

@taalexander
Copy link
Collaborator Author

See - pybind/pybind11#4301

@taalexander
Copy link
Collaborator Author

I attempted installing llvm with brew and using -fuse-ld=lld (based on #14, note to self we need instructions for using brew to be added with this PR) as well as manually editing the ninja build files with the potential fix specified here. While the fix above does remove the warning ld: warning: -undefined dynamic_lookup may not work with chained fixups importing of the library still yields a segfault and it is not clear yet that this is related to the behaviour of undefined symbols.

@taalexander
Copy link
Collaborator Author

taalexander commented Jan 7, 2023

Dropping into the debugger with test.py

import qss_compiler
print(qss_compiler.__file__)
>>> PYTHONPATH=$(which python) sudo lldb python
>>> (lldb) r test.py

Gives

Process 27899 launched: '/Users/thomas/opt/anaconda3/envs/qss-compiler/bin/python' (x86_64)
Process 27899 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x000000015b5c42b4 py_qssc.cpython-39-darwin.so`std::__1::__tree<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::__map_value_compare<unsigned int, std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::less<unsigned int>, true>, std::__1::allocator<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*> > >::__insert_node_at(this=0x000000015d1c9c80, __parent=0x000000015d1c9c88, __child=0x000000015d1c9c88, __new_node=0x0000600000c0c4b0) at __tree:2081:33
   2078	    __new_node->__parent_ = __parent;
   2079	    // __new_node->__is_black_ is initialized in __tree_balance_after_insert
   2080	    __child = __new_node;
-> 2081	    if (__begin_node()->__left_ != nullptr)
   2082	        __begin_node() = static_cast<__iter_pointer>(__begin_node()->__left_);
   2083	    _VSTD::__tree_balance_after_insert(__end_node()->__left_, __child);
   2084	    ++size();
Likely cause: __child.&__child.__left_ accessed 0x0

Which seems to indicate this is related to the qasm library. This is purely conjecture but I might imagine this is related to static initialization ordering that we have been running into.

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x000000015b5c42b4 py_qssc.cpython-39-darwin.so`std::__1::__tree<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::__map_value_compare<unsigned int, std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::less<unsigned int>, true>, std::__1::allocator<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*> > >::__insert_node_at(this=0x000000015d1c9c80, __parent=0x000000015d1c9c88, __child=0x000000015d1c9c88, __new_node=0x0000600000c0c4b0) at __tree:2081:33
    frame #1: 0x000000015b894cf7 py_qssc.cpython-39-darwin.so`std::__1::pair<std::__1::__tree_iterator<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::__tree_node<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, void*>*, long>, bool> std::__1::__tree<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::__map_value_compare<unsigned int, std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::less<unsigned int>, true>, std::__1::allocator<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*> > >::__emplace_unique_key_args<unsigned int, std::__1::pair<unsigned int, QASM::ASTDeclarationContext const*> >(this=0x000000015d1c9c80, __k=0x00007ff7bfefc118, __args=0x00007ff7bfefc118) at __tree:2099:9
    frame #2: 0x000000015b894c03 py_qssc.cpython-39-darwin.so`std::__1::pair<std::__1::__tree_iterator<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::__tree_node<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, void*>*, long>, bool> std::__1::__tree<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::__map_value_compare<unsigned int, std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::less<unsigned int>, true>, std::__1::allocator<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*> > >::__emplace_unique_extract_key<std::__1::pair<unsigned int, QASM::ASTDeclarationContext const*> >(this=0x000000015d1c9c80, __x=0x00007ff7bfefc118, (null)=__extract_key_first_tag @ 0x00007ff7bfefbf60) at __tree:1202:14
    frame #3: 0x000000015b894b7b py_qssc.cpython-39-darwin.so`std::__1::pair<std::__1::__tree_iterator<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::__tree_node<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, void*>*, long>, bool> std::__1::__tree<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::__map_value_compare<unsigned int, std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::less<unsigned int>, true>, std::__1::allocator<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*> > >::__emplace_unique<std::__1::pair<unsigned int, QASM::ASTDeclarationContext const*> >(this=0x000000015d1c9c80, __x=0x00007ff7bfefc118) at __tree:1164:16
    frame #4: 0x000000015b894a5b py_qssc.cpython-39-darwin.so`std::__1::pair<std::__1::__tree_iterator<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::__tree_node<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, void*>*, long>, bool> std::__1::__tree<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::__map_value_compare<unsigned int, std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::less<unsigned int>, true>, std::__1::allocator<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*> > >::__insert_unique<std::__1::pair<unsigned int, QASM::ASTDeclarationContext const*>, void>(this=0x000000015d1c9c80, __v=0x00007ff7bfefc118) at __tree:1277:16
    frame #5: 0x000000015b88ba6b py_qssc.cpython-39-darwin.so`std::__1::pair<std::__1::__map_iterator<std::__1::__tree_iterator<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, std::__1::__tree_node<std::__1::__value_type<unsigned int, QASM::ASTDeclarationContext const*>, void*>*, long> >, bool> std::__1::map<unsigned int, QASM::ASTDeclarationContext const*, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, QASM::ASTDeclarationContext const*> > >::insert<std::__1::pair<unsigned int, QASM::ASTDeclarationContext const*>, void>(this=0x000000015d1c9c80 size=0, __p=0x00007ff7bfefc118) at map:1188:29
    frame #6: 0x000000015b88b6a6 py_qssc.cpython-39-darwin.so`QASM::ASTDeclarationContextTracker::Init() at ASTDeclarationContext.cpp:54:12
    frame #7: 0x000000015bd9e23b py_qssc.cpython-39-darwin.so`QASM::ASTDeclarationContextTracker::Instance() at ASTDeclarationContext.h:214:7
    frame #8: 0x000000015b74c186 py_qssc.cpython-39-darwin.so`QASM::ASTIdentifierNode::ASTIdentifierNode(this=0x000000015d1ca0a0, Id="char", STy=ASTTypeChar, B=8) at ASTIdentifier.h:127:7
    frame #9: 0x000000015b6cd9d7 py_qssc.cpython-39-darwin.so`QASM::ASTIdentifierNode::ASTIdentifierNode(this=0x000000015d1ca0a0, Id="char", STy=ASTTypeChar, B=8) at ASTIdentifier.h:130:27
    frame #10: 0x000000015b9f21d4 py_qssc.cpython-39-darwin.so`::__cxx_global_var_init() at ASTIdentifier.cpp:39:20
    frame #11: 0x000000015b9f692b py_qssc.cpython-39-darwin.so`_GLOBAL__I_000201 at ASTIdentifier.cpp:0
    frame #12: 0x00000001004a3e4f dyld`invocation function for block in dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const + 182
    frame #13: 0x00000001004caaad dyld`invocation function for block in dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 242
    frame #14: 0x00000001004c1e26 dyld`invocation function for block in dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const + 557
    frame #15: 0x0000000100490db3 dyld`dyld3::MachOFile::forEachLoadCommand(Diagnostics&, void (load_command const*, bool&) block_pointer) const + 129
    frame #16: 0x00000001004c1bb7 dyld`dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const + 179
    frame #17: 0x00000001004ca604 dyld`dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const + 466
    frame #18: 0x00000001004a3d82 dyld`dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const + 144
    frame #19: 0x00000001004a3f0e dyld`dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const + 178
    frame #20: 0x00000001004a3fb2 dyld`dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const + 108
    frame #21: 0x00000001004b2e00 dyld`dyld4::APIs::dlopen_from(char const*, int, void*) + 592
    frame #22: 0x00000001001e246f python`_imp_create_dynamic + 1551
    frame #23: 0x00000001000d10d3 python`cfunction_vectorcall_FASTCALL + 99
    frame #24: 0x00000001001a179f python`_PyEval_EvalFrameDefault + 44943
    frame #25: 0x0000000100195120 python`_PyEval_EvalCode + 528
    frame #26: 0x0000000100074361 python`_PyFunction_Vectorcall + 433
    frame #27: 0x00000001001a3a2c python`call_function + 172
    frame #28: 0x00000001001a155a python`_PyEval_EvalFrameDefault + 44362
    frame #29: 0x00000001000742a8 python`_PyFunction_Vectorcall + 248
    frame #30: 0x00000001001a3a2c python`call_function + 172
    frame #31: 0x00000001001a14b4 python`_PyEval_EvalFrameDefault + 44196
    frame #32: 0x00000001000742a8 python`_PyFunction_Vectorcall + 248
    frame #33: 0x00000001001a3a2c python`call_function + 172
    frame #34: 0x00000001001a1590 python`_PyEval_EvalFrameDefault + 44416
    frame #35: 0x00000001000742a8 python`_PyFunction_Vectorcall + 248
    frame #36: 0x00000001001a3a2c python`call_function + 172
    frame #37: 0x00000001001a1590 python`_PyEval_EvalFrameDefault + 44416
    frame #38: 0x00000001000742a8 python`_PyFunction_Vectorcall + 248
    frame #39: 0x00000001001a3a2c python`call_function + 172
    frame #40: 0x00000001001a1590 python`_PyEval_EvalFrameDefault + 44416
    frame #41: 0x00000001000742a8 python`_PyFunction_Vectorcall + 248
    frame #42: 0x0000000100075a9a python`object_vacall + 474
    frame #43: 0x0000000100075d4d python`_PyObject_CallMethodIdObjArgs + 253
    frame #44: 0x00000001001dc43b python`PyImport_ImportModuleLevelObject + 1051
    frame #45: 0x000000010019ed36 python`_PyEval_EvalFrameDefault + 34086
    frame #46: 0x0000000100195120 python`_PyEval_EvalCode + 528
    frame #47: 0x000000010018f5c2 python`builtin_exec + 370
    frame #48: 0x00000001000d10d3 python`cfunction_vectorcall_FASTCALL + 99
    frame #49: 0x00000001001a179f python`_PyEval_EvalFrameDefault + 44943
    frame #50: 0x0000000100195120 python`_PyEval_EvalCode + 528
    frame #51: 0x0000000100074361 python`_PyFunction_Vectorcall + 433
    frame #52: 0x00000001001a3a2c python`call_function + 172
    frame #53: 0x00000001001a155a python`_PyEval_EvalFrameDefault + 44362
    frame #54: 0x00000001000742a8 python`_PyFunction_Vectorcall + 248
    frame #55: 0x00000001001a3a2c python`call_function + 172
    frame #56: 0x00000001001a14b4 python`_PyEval_EvalFrameDefault + 44196
    frame #57: 0x00000001000742a8 python`_PyFunction_Vectorcall + 248
    frame #58: 0x00000001001a3a2c python`call_function + 172
    frame #59: 0x00000001001a1590 python`_PyEval_EvalFrameDefault + 44416
    frame #60: 0x00000001000742a8 python`_PyFunction_Vectorcall + 248
    frame #61: 0x00000001001a3a2c python`call_function + 172
    frame #62: 0x00000001001a1590 python`_PyEval_EvalFrameDefault + 44416
    frame #63: 0x00000001000742a8 python`_PyFunction_Vectorcall + 248
    frame #64: 0x0000000100075a9a python`object_vacall + 474
    frame #65: 0x0000000100075d4d python`_PyObject_CallMethodIdObjArgs + 253
    frame #66: 0x00000001001dc43b python`PyImport_ImportModuleLevelObject + 1051
    frame #67: 0x000000010019ed36 python`_PyEval_EvalFrameDefault + 34086
    frame #68: 0x0000000100195120 python`_PyEval_EvalCode + 528
    frame #69: 0x0000000100209021 python`pyrun_file + 321
    frame #70: 0x000000010020887a python`pyrun_simple_file + 394
    frame #71: 0x000000010020869d python`PyRun_SimpleFileExFlags + 109
    frame #72: 0x0000000100230fa9 python`pymain_run_file + 329
    frame #73: 0x0000000100230680 python`pymain_run_python + 992
    frame #74: 0x0000000100230245 python`Py_RunMain + 37
    frame #75: 0x00000001002319c1 python`pymain_main + 49
    frame #76: 0x00000001000016c8 python`main + 56
    frame #77: 0x000000010049452e dyld`start + 462

@steleman
Copy link

steleman commented Jan 7, 2023

Which seems to indicate this is related to the qasm library [ ... ]

We've discussed this before.

Please upgrade your Apple Toolchain to XCode 14.2.

This is purely conjecture [ ... ]

Not needed and not helpful.

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

No branches or pull requests

2 participants