Uploaded image for project: 'Swift'
  1. Swift
  2. SR-13605

Build script ‘swift/utils/build-parser-lib’ fails with undefined symbols

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reopened
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: SwiftSyntax
    • Labels:
      None
    • Environment:

      Description

      Hey there folks. I greatly appreciate your time. If there's anything at all I can supply to help solve this - or to help produce a better bug/support ticket - please let me know!

      The context

      I am attempting to build a custom version of `lib_InternalSwiftSyntaxParser.dylib` to embed in *iOS* as described in the repositories below:

      https://github.com/apple/swift-syntax
      https://github.com/apple/swift

      My configuration is:

      # swift-DEVELOPMENT-SNAPSHOT-2020-09-23-a installed at /Library/Developer/Toolchains
      $ echo $TOOLCHAINS
      swift
      
      $ xcrun --find swift
      /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-09-23-a.xctoolchain/usr/bin/swift
      
      $ xcrun --toolchain default --find swift
      /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
      
      $ xcrun --toolchain swift --find swift
      /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-09-23-a.xctoolchain/usr/bin/swift
      
      # showing that --toolchain with bad input goes back to default
      $ xcrun --toolchain random_string_that_shouldnt_do_anything --find swift
      /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
      

      So far, I have successfully built the main swift repository with

      $ ./swift/utils/build-script --clean
      

      ... and I am using the built `.dylib` from that effectively in a macOS application. 

      The crash

      $ ./swift/utils/build-parser-lib --release --no-assertions --build-dir /tmp/parser-lib-build-ios --host iphoneos --architectures arm64
      
      [ ... many many lines of build information later ...]
      
      [1/2] Linking CXX shared library lib/lib_InternalSwiftSyntaxParser.dylib
      FAILED: lib/lib_InternalSwiftSyntaxParser.dylib
      : && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -arch arm64 -miphoneos-version-min=10.0 -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -Wno-nested-anon-types -Werror=switch -Wdocumentation -Wimplicit-fallthrough -Wunreachable-code -Woverloaded-virtual -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -O2 -g -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.0.sdk -dynamiclib -Wl,-headerpad_max_install_names -Wl,-exported_symbols_list,"/tmp/parser-lib-build-ios/arm64/obj/tools/swift/tools/libSwiftSyntaxParser/libSwiftSyntaxParser.exports" -Wl,-dead_strip -target arm64-apple-ios10.0 -Xlinker -dead_strip -Xlinker -compatibility_version -Xlinker 1 -o lib/lib_InternalSwiftSyntaxParser.dylib -install_name @rpath/lib_InternalSwiftSyntaxParser.dylib tools/swift/tools/libSwiftSyntaxParser/CMakeFiles/libSwiftSyntaxParser.dir/c-include-check.c.o tools/swift/tools/libSwiftSyntaxParser/CMakeFiles/libSwiftSyntaxParser.dir/libSwiftSyntaxParser.cpp.o lib/libswiftParse.a lib/libswiftSyntaxParse.a lib/libswiftParse.a lib/libswiftSyntaxParse.a lib/libswiftAST.a lib/libswiftBasic.a lib/libLLVMSupport.a -lm lib/libLLVMDemangle.a lib/libswiftDemangling.a ./lib/libclangBasic.a lib/libswiftSyntax.a && :
      Undefined symbols for architecture arm64:
       "clang::MacroInfo::dump() const", referenced from:
       swift::ClangNode::dump() const in libswiftAST.a(Decl.cpp.o)
       "clang::Type::dump() const", referenced from:
       swift::UnexpectedClangTypeError::dump() in libswiftAST.a(ExtInfo.cpp.o)
       "clang::Decl::dump() const", referenced from:
       swift::ClangNode::dump() const in libswiftAST.a(Decl.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
      

      (You can find the full, gorey, exciting log at https://gist.github.com/tikimcfee/75c24cdce8cc352645da78da4b015daf)

       

      There are a couple of things I noticed in the build log that have me questioning some kind of cache or local configuration. Specifically, lines that mention build tools from a different toolchain:

      -- Found libtool - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool
      [...]
      -- CMake (/usr/local/Cellar/cmake/3.18.2/bin/cmake) Version: 3.18.2
      -- CMake Make Program (/usr/local/bin/ninja) Version: 1.10.1
      -- C Compiler (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc) Version: 12.0.0.12000032
      -- C++ Compiler (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++) Version: 12.0.0.12000032
      

      I'm guessing I'm doing something wrong with the invoking of this script, but I've also tried a number of path hacks within the actual build script to try to point to a different toolchain or compiler - all of which are things I am completely unfamiliar with and am stabbing at in the dark with print debugging.

        Attachments

          Activity

            People

            Assignee:
            akyrtzi Argyrios Kyrtzidis
            Reporter:
            TikiMcFee Ivan Lugo
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: