Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-10152] [Driver] Missing --whole-archive in linker invocation #52554

Closed
yln opened this issue Mar 22, 2019 · 2 comments
Closed

[SR-10152] [Driver] Missing --whole-archive in linker invocation #52554

yln opened this issue Mar 22, 2019 · 2 comments
Assignees
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

Comments

@yln
Copy link
Contributor

yln commented Mar 22, 2019

Previous ID SR-10152
Radar None
Original Reporter @yln
Type Bug
Status Resolved
Resolution Done
Environment

Linux

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

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Driver
Assignee @yln
Priority Medium

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

@belkadan
Copy link
Contributor

I like the idea of just asking Clang to figure out how to link for us on platforms where we use Clang as the linker.

@yln
Copy link
Contributor Author

yln commented Mar 27, 2019

Resolved by #23508

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants