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-521] Public symbols are never dead stripped #5326
Comments
Some programs do load plugins that rely on public symbols in the executable. Why do you have public declarations in your executable? |
The example is a bit contrived to keep it small, but the same problem occurs if I use the Swift package manager with two targets—a library with public symbols, and an executable that imports the library. If the library is large and the executable only uses a small number of symbols from it, it would be nice to have the option to strip the unused code out of the final binary. |
I agree it should be possible to strip unused public functions from executables. Seems like the Swift team have more pressing problems. Probably though you could write the patch. |
I have added |
Strictly, this is not done, one part is done, the issue described with the build-chain is still present. |
For GNU ld, it looks like we could use |
|
I'll remove `--dead-strip`. |
Thanks @mxcl. I filed https://bugs.swift.org/browse/SR-1021 for a better compiler-side solution. |
Comment by Walter (JIRA) Is there any further progress on this issue? @mxcl |
As noted, SR-1021 is tracking further work. |
Environment
Tested on OS X:
Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 51a9cea5cd)
Target: x86_64-apple-macosx10.9
Tested on Linux:
Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 1f2908b4f7)
Target: x86_64-unknown-linux-gnu
Additional Detail from JIRA
md5: 58e0a16182b3604b18df177057c9bc29
relates to:
Issue Description:
Symbols declared with public visibility are never dead stripped by the linker, even when linking an executable where there is no expectation that the result would be linked into anything else (and thus unused symbols could be safely discarded).
Stripping these symbols is important when building an executable that links to a large library that it only uses a portion of, to prevent code bloat.
STEPS TO REPRODUCE
1. Create functions.swift, first using internal visibility:
2. Create main.swift:
bar()
3. Build an executable (example provided is for OS X):
swiftc functions.swift main.swift -Xlinker -dead_strip
4. Run
nm main
and observe thatfoo
has been stripped from the executable.5. Modify functions.swift to declare the functions with public visibility:
6. Build the executable again:
swiftc functions.swift main.swift -Xlinker -dead_strip
7. Run
nm main
and observe thatfoo
is still present.EXPECTED BEHAVIOR
foo
should be removed because we are building an executable and it is never referenced within that binary.OTHER NOTES
On OS X, adding the
-whole-module-optimization
option to swiftc has no effect.On Linux, the behavior differs.
-Xlinker -dead_strip
doesn't apply here; instead, we see the following based on-whole-module-optimization
:1. Internal visibility compiled without
-whole-module-optimization
:foo
is not stripped2. Internal visibility compiled with
-whole-module-optimization
:foo
is stripped3. Public visibility regardless of the presence of
-whole-module-optimization
:foo
is not strippedThe text was updated successfully, but these errors were encountered: