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

[Driver] Missing `--whole-archive` in linker invocation

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:
    • Environment:

      Linux

      /swift-DEVELOPMENT-SNAPSHOT-2019-03-17-a-ubuntu18.04

      Description

      On Linux, when compiling a simple C program with clang and a sanitizer enabled the driver ensures that all parts of the sanitizer runtime (*.a file) make it into the final executable via `--whole-archive <runtime.a> --no-whole-archive`.

      clang simple.c -fsanitize=thread -v [...]
      <compile step>
      <link step>:
      "/usr/bin/ld" -z relro
      [...]
      -L/home/yln/swift-DEVELOPMENT-SNAPSHOT-2019-03-17-a-ubuntu18.04/usr/bin/../lib
      --whole-archive /home/yln/swift-DEVELOPMENT-SNAPSHOT-2019-03-17-a-ubuntu18.04/usr/lib/clang/7.0.0/lib/linux/libclang_rt.tsan-x86_64.a --no-whole-archive
      --dynamic-list=/home/yln/swift-DEVELOPMENT-SNAPSHOT-2019-03-17-a-ubuntu18.04/usr/lib/clang/7.0.0/lib/linux/libclang_rt.tsan-x86_64.a.syms
      [...]

      When compiling a simple swift program (swiftc simple.swift -sanitize=thread), these linker directives are missing.
      My understanding is that for the linking step: swift driver -> clang driver -> system linker.
      The swift driver directly specifies the sanitizer runtime, but does not wrap it in `--whole-archive` (which is required for static archives).

      If there is nothing preventing it, then a better option would probably be to pass through the `-sanitize=xxx` to the clang invocation (instead of directly specifying the sanitizer runtime) and let the clang driver figure out the right sanitizer runtime and linker flags to use.
      https://github.com/llvm/llvm-project/blob/master/clang/lib/Driver/ToolChains/CommonArgs.cpp#L541

        Attachments

          Activity

            People

            • Assignee:
              jlettner Julian Lettner
              Reporter:
              jlettner Julian Lettner
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: