-
Notifications
You must be signed in to change notification settings - Fork 13k
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
"Hello world!" binary links a bunch of unnecessary libraries #29482
Comments
/cc @alexcrichton |
Hm I've wondered the same from time to time. We pass The answer is that if you use 100% of the standard library you'll need all these libraries, but you normally don't use the entire standard library as the unused portions are stripped out. It looks like the linker orders this as "strip unused dynamic libraries, then strip unused object code" rather than the other way around, meaning that when the "strip unused dylibs" pass comes along they're all actually in use. Seems like an annoyance, but I'm not sure there's anything we can do about it or if it has any real impact beyond aesthetics. |
No, they're all used. libdl: dl_iterate_phdr |
It looks like they're used in terms of tools like It looks like libdl is used by libbacktrace which is in turn used for |
Cool. My current task is to remove the libgcc_s dependency (for complicated internal reasons), so any advice on how that would be accomplished? |
Any thoughts on something like function-sections to reduce the amount of unneeded code getting linked into the executable? |
Out of curiosity, what's the desire to remove libgcc_s? I don't know of any easy way off-hand to swap out that dependency for something else, although perhaps compiling everything with We actually do currently compile everything with function-sections and data-sections (which is why executables are as small as they are), but my comment above explains why this apparently doesn't strip out unused dynamic libraries. |
No, they all appear to be used...
(Yeah, it's not clock_gettime -- must have been a script error.) |
We don't have libgcc_s.so.1 deployed to our cloud systems because all of our binaries are supposed to be static-libgcc. Fixing that is... complicated, so I'm trying to find a way to avoid it here. |
Oh weird, we probably don't really need to link that in for librt, but oh well! I forget if there's a technical reason for using libgcc_s instead of a static copy, but it may just be historical. |
Should I open a separate feature request for static libgcc then? |
Sure! It looks like all the libs used in the initial report are indeed used, so I'm gonna close in favor of this to-be-opened issue. Thanks again for the report! |
Looking at a simple println!("hello world") binary, I get these:
libdl (why?)
libpthread (I'm not using threads)
librt (why?)
libgcc_s (apparently for unwinding, despite my not using any dynamically linked crates)
The text was updated successfully, but these errors were encountered: