You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove libjulia-internal.so dependency on libstdc++ and libgcc (#60248)
Some testing by @BenChung has revealed how hard it is to load a
JuliaC-built library into a program that has already loaded a very old
version of libstdc++. Even with probing disabled, `libjulia-internal.so`
fails because of missing GLIBCXX symbols.
We use so little of the C++ standard library in `libjulia-internal.so`
that it's worth the tradeoff to link it statically: it barely changes
the size of the resulting library, removes a medium-size library we have
to ship in trimmed bundles, and solves some of our hermeticity issues
when being loaded by other software. `libjulia-codegen.so` uses it more
extensively, and we expect to be able to load it as a plugin for `opt`,
meaning it may have to remain dynamically linked.
This PR contains a series of changes to enable statically linked
libstdc++ by default and mitigate the size impact:
- We enable `--gc-sections` when building with gcc/ld.bfd. This saves us
some code already, since we can trim out a lot of
libLLVMSupport/libLLVMTargetParser. On macOS, we can use `-dead_strip`
to save some space even though the rest of these changes are not
applicable.
- Two flags for `-static-libstdc++` and `-static-libgcc`, called
`USE_RT_STATIC_LIBSTDCXX` and `USE_RT_STATIC_LIBGCC`, are added and
enabled by default.
- Most of the additional code that gets linked into
`libjulia-internal.so` is related to locales for iostreams. Replace
these with standard C IO and LLVM helpers that don't have weird
locale-related behaviour.
- (NOT IMPLEMENTED) `--gc-sections` removes unused executable code, but
leaves us with a lot of irrelevant debug info. I tested the effect of
`llvm-dwarfutil --garbage-collection` and saw pretty good savings, but
that is not included in this PR because BinaryBuilder doesn't have a new
enough version of the LLVM tools.
| Change | Size of `libjulia-internal.so` (KiB) |
|--------------------------------------|--------------------------------------|
| No change | 14524 |
| Linker GC enabled | 13220 |
| -static-libstdc++ and -static-libgcc | 22136 |
| Excise iostreams | 15036 |
| DWARF GC (not in this PR) | 11488 |
This is a comparison of symbols that were added and removed. Even though
15 times more code is removed than added, the resulting
`libjulia-internal.so` has a similar size to the original because of the
additional debug info.
(cherry picked from commit f36882f)
0 commit comments