swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.57k stars 10.36k forks source link

Build toolchain failed:ld: symbol(s) not found for architecture arm64 #58708

Closed ZiLingNiu closed 2 years ago

ZiLingNiu commented 2 years ago

Describe the bug Hi, I tried to build the toolchain and unfortunately failed. What can I do to improve it?

To Reproduce Steps to reproduce the behavior:

1. git clone --branch swift-5.5.2-RELEASE https://github.com/apple/swift
2. git clone --branch swift-5.5.2-RELEASE https://github.com/apple/llvm-project
3. ./swift/utils/update-checkout --tag swift-5.5.2-RELEASE --clone
update-checkout succeeded
cmake                              : skip                               
cmark                              : 9c8096a23f44794bde297452d87c455fc4f76d42
icu                                : skip                               
indexstore-db                      : e771994778265c2efe8d33a7ca30adf5f3d2065a
llbuild                            : 83c4bcb8dfca48cc065325287b55d08ff7b26428
llvm-project                       : c315411fac10439aa7a09dce976b5716af9f149c
ninja                              : e72d1d581c945c158ed68d9bc48911063022a2c6
sourcekit-lsp                      : 1abe633602f7974bc56569c7a362b277305e73c6
swift                              : 4c45f525dc315a618868caae7d976d95359700a4
swift-argument-parser              : 986d191f94cec88f6350056da59c2e59e83d1229
swift-corelibs-foundation          : 491a217baa8a0ef4ae9c8603c434c069cc090c50
swift-corelibs-libdispatch         : 5cc1c6679822fd18368664482a5bba57270467f4
swift-corelibs-xctest              : 39926a836fc49efb977f26b9046c830fc72b0750
swift-crypto                       : 0141f53dd525706c803b0c20aa8ad36f9ecd45e5
swift-driver                       : 86c54dacd270e0c43374c0cb9b2ceb2924c9ea72
swift-format                       : f872223e16742fd97fabd319fbf4a939230cc796
swift-integration-tests            : fe78b5eabe09fc4597c74d1ccd209b7192ca6273
swift-stress-tester                : 4aaabe1bebd00424ff1f041bfcfd4e44af6c3c07
swift-syntax                       : 2ca29758ed04c0a209221db59f922d4faf539f03
swift-tools-support-core           : 3b586ce12865db205081acdcea79fe5509b28152
swift-xcode-playground-support     : dd0d8c8d121d2f20664e4779a3d29482a55908bb
swiftpm                            : 7a1f113534689c77b3a4110288478580b7b8d91c
yams                               : 51ef46468fda5a0fa1a201b8843791d0149d3c01

4. ./swift/utils/build-toolchain tool

Expected behavior I want to build the toolchain for iPhone device testing.

Screenshots

lldb_private::python::PythonCallable::operator()<lldb_private::python::PythonObject, lldb_private::python::PythonObject, lldb_private::python::PythonDictionary>(lldb_private::python::PythonObject const&, lldb_private::python::PythonObject, lldb_private::python::PythonDictionary) in LLDBWrapPython.cpp.o
      _LLDBSwigPythonCallTypeScript in LLDBWrapPython.cpp.o
      ...
  "_PyLong_AsDouble", referenced from:
      _wrap_SBStructuredData_GetFloatValue(_object*, _object*) in LLDBWrapPython.cpp.o
  "_PyErr_SetString", referenced from:
      _wrap_new_SBAddress(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_delete_SBAddress(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_SBAddress_IsValid(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_SBAddress___nonzero__(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_SBAddress___ne__(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_SBAddress_Clear(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_SBAddress_GetFileAddress(_object*, _object*) in LLDBWrapPython.cpp.o
      ...
  "_PyTuple_New", referenced from:
      SWIG_Python_NewPointerObj(_object*, void*, swig_type_info*, int) in LLDBWrapPython.cpp.o
      SwigPyClientData_New(_object*) in LLDBWrapPython.cpp.o
      lldb_private::python::PythonTuple::PythonTuple(std::initializer_list<lldb_private::python::PythonObject>) in liblldbPluginScriptInterpreterPython.a(PythonDataObjects.cpp.o)
  "_PyThreadState_Get", referenced from:
      lldb_private::ScriptInterpreterPythonImpl::Locker::DoAcquireLock() in liblldbPluginScriptInterpreterPython.a(ScriptInterpreterPython.cpp.o)
      lldb_private::ScriptInterpreterPythonImpl::ScriptInterpreterPythonImpl(lldb_private::Debugger&) in liblldbPluginScriptInterpreterPython.a(ScriptInterpreterPython.cpp.o)
      lldb_private::ScriptInterpreterPythonImpl::Interrupt() in liblldbPluginScriptInterpreterPython.a(ScriptInterpreterPython.cpp.o)
      lldb_private::ScriptInterpreterPythonImpl::CreateFrameRecognizer(char const*) in liblldbPluginScriptInterpreterPython.a(ScriptInterpreterPython.cpp.o)
      lldb_private::ScriptInterpreterPythonImpl::GetRecognizedArguments(std::__1::shared_ptr<lldb_private::StructuredData::Object> const&, std::__1::shared_ptr<lldb_private::StackFrame>) in liblldbPluginScriptInterpreterPython.a(ScriptInterpreterPython.cpp.o)
      lldb_private::ScriptInterpreterPythonImpl::OSPlugin_CreatePluginObject(char const*, std::__1::shared_ptr<lldb_private::Process>) in liblldbPluginScriptInterpreterPython.a(ScriptInterpreterPython.cpp.o)
      lldb_private::ScriptInterpreterPythonImpl::OSPlugin_RegisterInfo(std::__1::shared_ptr<lldb_private::StructuredData::Object>) in liblldbPluginScriptInterpreterPython.a(ScriptInterpreterPython.cpp.o)
      ...
  "_PyEval_RestoreThread", referenced from:
      _wrap_new_SBAddress(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_delete_SBAddress(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_SBAddress_IsValid(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_SBAddress___nonzero__(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_SBAddress___ne__(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_SBAddress_Clear(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_SBAddress_GetFileAddress(_object*, _object*) in LLDBWrapPython.cpp.o
      ...
  "_PyLong_AsLong", referenced from:
      _wrap_SBBlock_GetVariables(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_SBBreakpoint_FindLocationByID(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_SBBreakpointList_FindBreakpointByID(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_SBBreakpointList_AppendByID(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_SBBreakpointLocation_GetDescription(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_SBCommandInterpreter_GetArgumentTypeAsCString(_object*, _object*) in LLDBWrapPython.cpp.o
      _wrap_SBCommandInterpreter_GetArgumentDescriptionAsCString(_object*, _object*) in LLDBWrapPython.cpp.o
      ...
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
ERROR: command terminated with a non-zero exit status 1, aborting

ERROR: command terminated with a non-zero exit status 1, aborting

More error info: error.txt

Environment (please complete the following information):

Additional context In fact, I also tried the swift-5.5.1-RELEASE version, with the same failure result as 5.5.2.

milch commented 2 years ago

I just ran into the same issue. I was able to fix it by uninstalling python from homebrew. The reason for the failure seems to be that homebrew only installs binaries with the architecture of your machine, not universal binaries, so when the linker tries to link LLVM it can't find those symbols for arm64. The system version of python does come with both arm64 and x86_64.

ZiLingNiu commented 2 years ago

I just ran into the same issue. I was able to fix it by uninstalling python from homebrew. The reason for the failure seems to be that homebrew only installs binaries with the architecture of your machine, not universal binaries, so when the linker tries to link LLVM it can't find those symbols for arm64. The system version of python does come with both arm64 and x86_64.

Great, this solved my current problem, thanks. Describe my few hours of exploration: 1 First brew uninstall python3; 2 When trying to build with ./swift/utils/build-toolchain: env: python: No such file or directory; 3 Tried sudo ln -s /usr/local/bin/python3 python, but failed on MacOS 12.3.1; 4 Download the general version of Python3 from the official website: https://www.python.org/downloads/ and install; 5 The error "ld: symbol(s) not found for architecture arm64" no longer appears when using build-toolchain to build.