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

Teach the driver to accept multiple swiftmodules as linker inputs, for static linking

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: In Progress
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:
    • Environment:

      Apple Swift version 3.0 (swiftlang-800.0.46.2 clang-800.0.38)
      Target: x86_64-apple-macosx10.9

      Description

      Suppose we have an Objective-C program that uses two Swift modules. We would like to debug this program with LLDB without having a dSYM for faster builds.

                               ┌───────┐
                            ┌──│ Swift │
      ┌───────┐   ┌───────┐ │  └───────┘
      │  Bin  │◀──│ ObjC  │◀┤           
      └───────┘   └───────┘ │  ┌───────┐
                            └──│ Swift │
                               └───────┘
      

      Each Swift module consist of a .swiftmodule, .o, and the .h header.

      swiftc -c -g src/foo.swift \
        -module-name Foo \
        -emit-module-path out/Foo.swiftmodule \
        -emit-objc-header-path out/Foo-Swift.h \
        ...
      

      We then link the two Swift objects and Objective-C objects into the final binary. It looks like LLDB needs to have .swiftmodule information for debugging, so we include references as AST entries.

      clang src/main.m -fobjc-arc -o out/main out/foo.o out/bar.o \
        -Xlinker -add_ast_path -Xlinker out/Foo.swiftmodule \
        -Xlinker -add_ast_path -Xlinker out/Bar.swiftmodule
        ...
      

      When we run LLDB on this binary and set breakpoints inside of the code for Foo and Bar modules, only the Foo types are picked up by LLDB. It only reads the first AST reference, ignoring others. If we swap the order of add_ast_path options we get symbols from the other module.

      The full build is in attached zip file. Unpack and run build.sh. In its output, you will see that frame variable self command only correctly prints the variable for one module, not both.

        Attachments

        1. build.sh
          1 kB
        2. Build App_2017-10-31T17-29-26.rtf
          64 kB
        3. MacSwifter.zip
          13 kB
        4. swift_sample.zip
          5 kB
        5. TestApp.zip
          44 kB

          Issue Links

            Activity

              People

              • Assignee:
                JDevlieghere Jonas Devlieghere
                Reporter:
                tfiala Todd Fiala
              • Votes:
                0 Vote for this issue
                Watchers:
                12 Start watching this issue

                Dates

                • Created:
                  Updated: