[SR-10152] [Driver] Missing --whole-archive
in linker invocation
#52554
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
legacy driver
Area → compiler: the integrated C++ legacy driver. Succeeded by the swift-driver project
Environment
Linux
/swift-DEVELOPMENT-SNAPSHOT-2019-03-17-a-ubuntu18.04
Additional Detail from JIRA
md5: 71edd170c1983b68c68b76f6a4980b35
Issue 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
The text was updated successfully, but these errors were encountered: