Link system libraries by default - #10998
Conversation
625dd71 to
507c80c
Compare
|
Actually in most cases the way libraries work is that you only link the parts that you use anyway. DCE can achieve even more of course, both the normal dce that that linker doees and the metadce that emscripten does.
Yes, this is a alternative less intrusive version of that change. |
e87bae6 to
c1ef1ae
Compare
Sometime emcc wants to add extra libraries the link, but when it does do there is no need to use `--whole-archive` which is what is used for FORCE_STDLIBS This change was split out from: #10998
Sometime emcc wants to add extra libraries the link, but when it does do there is no need to use `--whole-archive` which is what is used for FORCE_STDLIBS This change was split out from: #10998
3cf16a8 to
15efd54
Compare
aheejin
left a comment
There was a problem hiding this comment.
I like this change! Some minor questions and typo fixes.
| // Enabled when building C++ code (for example via em++ or via -c c++) | ||
| var USE_CXX = 0; | ||
|
|
||
| // Sometime was want to force linking with C++ libraries. For example, the |
There was a problem hiding this comment.
| // Sometime was want to force linking with C++ libraries. For example, the | |
| // Sometimes we want to force linking with C++ libraries. For example, the |
Not sure this is what you were gonna write, but it looks like a typo?
| # Regression test for issue #4522: Incorrect CC vs CXX detection | ||
| def test_incorrect_c_detection(self): | ||
| # This auto-detection only works for the compile phase. | ||
| # For linking you need to use `em++` or pass `-x c++` |
There was a problem hiding this comment.
How is the library change related to this?
There was a problem hiding this comment.
Because if you use emcc you don't get libc++ or libc++abi included in your link.. and you will have undefined symbols.
I could make that a separate change perhaps?
There was a problem hiding this comment.
Oh I see. No I think this is fine as is.
|
|
||
|
|
||
| class libc_extras(MuslInternalLibrary): | ||
| class libc_extras(NoBCLibrary, MuslInternalLibrary): |
There was a problem hiding this comment.
Why? Doesn't fastcomp use bc files?
There was a problem hiding this comment.
For some libraries yes. The advantage of the .bc library is: everything is in single file. The disadvantage is: The linker can't skip over it and will always reference it (including any static constructors therein). The whole point of libc_extras I believe is so that its not part of the main libc.bc file and can be selectively included. It only contains the single file: extras_fastcomp.c.
With this change we starting including it on the link line every time, which has the effect that it cannot be ignored.. by making it into a .a archive the linker process can ignore it when its not needed.
There was a problem hiding this comment.
Sorry I might be mistaken, but does fastcomp use .a files? I thought it only uses .bc...
There was a problem hiding this comment.
Fastcomp and handle .a files, but the code that handles it is not very nice. It has to extract the archive and into a temp directory and inspect each object file. This is (I believe) why it uses .bc files for things like libc, a an optimization. I mean I can't think of any other reason to make libc into into big .bc file. Perhaps @kripken can remember the history here.
There was a problem hiding this comment.
I think historically we just had a single .bc file for every library. That was easiest as we just let llvm-link do the linking.
Later we made some libraries be .a, where it mattered, like libc++ which has global ctors, and we wrote python code to extract the archive and pick the members to link etc. (as we couldn't use llvm-link there).
|
Does this affect build times with upstream? And how much slower is fastcomp? (Can maybe compare bot times, but would be good to test locally too for less noise. |
|
My expectation is that it won't actaully effect either backend much because the numbr of programs that don't need libc at all should be tiny. I'll look at the numbers though. |
Sometime emcc wants to add extra libraries the link, but when it does do there is no need to use `--whole-archive` which is what is used for FORCE_STDLIBS This change was split out from: #10998
|
Looking at the CI results we don't a huge impact: |
15efd54 to
5dc19f1
Compare
|
Testing locally I don't see much difference. |
89473bd to
b77f35b
Compare
b77f35b to
9fbfd2c
Compare
|
I managed to simplify again and default to linking C++ libraries by default for now. |
After this change system library no longer linked on demand based `.symbols` files, to simply included by default in all cases. The `.symbols` file logic were originally added as an optimization would allow only the libraries needed to be considered at link time. However, this optimization I believe was put in place for fastcomp where the build time cost (in build) of including a library was significant. This optimization does not apply with the wasm backend where linking is fast and `.a` libraries are handled efficiently. Also are basically no real programs that don't use libc and for those programs we already have the `-nostdlib` option. The `.symbols` files are still used for some optional libraries such as libhtml, libgl and libal. However the plan is to also remove that logic in STRICT mode too. Once we do that we can avoid having to run llvm-nm on each input object file. See #8912.
3779102 to
6b68e89
Compare
6b68e89 to
ce1c0ce
Compare
The order of the system libraries is now fixed as of #10998
The order of the system libraries is now fixed as of #10998
The order of the system libraries is now fixed as of #10998
The order of the system libraries is now fixed as of #10998
This should have been removed in #10998.
This should have been removed in #10998.
After this change system library no longer linked on demand based
.symbolsfiles, to simply included by default in all cases.The
.symbolsfile logic were originally added as an optimizationwould allow only the libraries needed to be considered at link time.
However, this optimization I believe was put in place for fastcomp where
the build time cost (in build) of including a library was significant.
This optimization does not apply with the wasm backend where linking is
fast and
.alibraries are handled efficiently. Also are basically noreal programs that don't use libc and for those programs we already have
the
-nostdliboption.The
.symbolsfiles are still used for some optional libraries suchas libhtml, libgl and libal. However the plan is to also remove that
logic in STRICT mode too. Once we do that we can avoid having to
run llvm-nm on each input object file.
See #8912.