-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Restore -static-executable on Linux. #29039
Conversation
Please test with following pull request: @swift-ci please test |
@@ -144,6 +152,8 @@ int swift::lookupSymbol(const void *address, SymbolInfo *info) { | |||
return 1; | |||
} | |||
|
|||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just use the alternate version always? The cost is nearly negligible - the cost is largely associated with the fact that the information from the ELF header parsing may be cached by the loader, which is not guaranteed.
340fd22
to
15ac30f
Compare
@swift-ci test |
Build failed |
Build failed |
Please test with following pull request: @swift-ci please test |
Build failed |
Please test with following pull request: @swift-ci please test linux |
Build failed |
Please test with following pull request: @swift-ci please test linux |
Build failed |
@swift-ci smoke test linux |
1 similar comment
@swift-ci smoke test linux |
Please test with following pull request: @swift-ci please test linux |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I missed it or something ... why not use the parsing logic even for the shared linking?
int (*__strong_pthread_once)(pthread_once_t *, void (*)(void)) = pthread_once; | ||
|
||
__attribute__((__visibility__("hidden"))) | ||
int (*__strong_pthread_key_create)(pthread_key_t *, void (*)(void *)) = pthread_key_create; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really wish we had linker options ... -u pthread_self -u pthread_once -u pthead_key_create
is so much better than this. sigh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had used ---defsym=__import_pthread_self=pthread_self
options to the linker before but it looks like that doesnt create strong linkage anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--defsym
creating a strong reference sounds like a bug. If you want to create a strong reference, you should use --require-defined
or -u
at the very least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didnt know about this option! I had to use -undefined (-u)
since ld.gold
is being used, --require-defined
seems to only work on ld
- Add back StaticBinaryELF.cpp which provides swift::lookupSymbol() for statically linked ELF binaries. - Build libswiftImageInspectionStatic.a from StaticBinaryELF.cpp - Update static-executable-args.lnk and replace libswiftImageInspectionShared with libswiftImageInspectionStatic. - Fix linkage to pthreads to avoid weak linkage issues in a static executable. - Add driver test for '-static-executable' on Linux to validate that output binary is statically linked.
15ac30f
to
3b25795
Compare
Please test with following pull request: @swift-ci please test |
Build failed |
Build failed |
Please test with following pull request: @swift-ci please smoketest macos |
Please test with following pull request: @swift-ci please smoke test macos |
Please test with following pull request: @swift-ci please test macos |
Build failed |
This will only parse 1 ELF file and wont handle the extra shared libraries that are dynamically linked in or their relocations. There would also be no benefit to replacing a platform's |
Please test with following pull request: @swift-ci please test macos |
Build failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will only parse 1 ELF file and wont handle the extra shared libraries that are dynamically linked in or their relocations. There would also be no benefit to replacing a platform's
dladdr()
even if a full implementation was written.
The registration is per module, and is not shared across dynamically shared libraries. I think that you are focusing too much about the fact that there is a wrapper for the dladdr
in this file. That doesn't really belong in there, it was just convenient for it to get placed there I think.
int (*__strong_pthread_once)(pthread_once_t *, void (*)(void)) = pthread_once; | ||
|
||
__attribute__((__visibility__("hidden"))) | ||
int (*__strong_pthread_key_create)(pthread_key_t *, void (*)(void *)) = pthread_key_create; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--defsym
creating a strong reference sounds like a bug. If you want to create a strong reference, you should use --require-defined
or -u
at the very least.
pthread functions.
Please test with following pull request: @swift-ci please test |
Build failed |
Build failed |
|
Thats correct, its only really used for stack traces hence why it doesnt matter too much if the |
For server side work, I think we'd want to encourage building with at least
IIRC, at some point |
After checking the man pages and doing a test I found that
So |
@spevans I think more than main bin vs library, IIRC |
An updated and more simplified version of this pr is #34180 |
Add back StaticBinaryELF.cpp which provides swift::lookupSymbol()
for statically linked ELF binaries.
Build libswiftImageInspectionStatic.a from StaticBinaryELF.cpp
Update static-executable-args.lnk and replace
libswiftImageInspectionShared with libswiftImageInspectionStatic.
Add driver tests for '-static-executable' on Linux to validate
that output binary is statically linked.
Fix linkage to pthreads to avoid weak linkage issues in a static
executable.
This is a rebase of a previous PR but that didnt work with Ubutnu18.04 only 16.04. This version has been tested with 16.04, 18.04 and 19.10.
Note, as with
-static-stdlib
, onlyDispatch
can be used with-static-executable
,Foundation
cannot at this time.Integration tests have also been added to catch any future breakage of this change.