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
Why linker strips about 90% of used files / classes? #21725
Comments
If you want your static constructors to run the linker needs to have some reason to include the object file from the library. You can force the linker to include all of the objects in the library using Or you add references to the symbol in the object files that you want from some other part of the application (e.g. main.c). This is the save behaviour as native/desktop linkers. |
so if i use -Wl,--whole-archive - it will not strip anything ? Even if class is never referenced ? |
It will force the object files to be included, which will in turn force any static constructors to run. If you just want to include what you need then you should just reference what you need and should not be stripped. The linker will never strip code that is referenced. |
Using |
Will nested static libs also work? For example mediaPipe static lib includes lot of other libs: target_link_libraries(mediaPipe PRIVATE Will then final linking stage use all obj files in nested libs as well? |
There is no such thing as a nested library for static |
Hello,
I'm currently working on the project which is using proto buffers, which register descriptors globally this way:
Here ::_pbi::AddDescriptors - just registeres the class in the global factory.
There are over 100 such .proto files / classes.
But during parsing .pbtxt files parser throws lot of errors regarding missing extensions.
It turns out linker just strips majority of my classes with self registration.
Currently i log all the registered descriptors and I was surprized that over 90% of my classes just stripped away.
Why linker strips the code which is potentially used in the final executable?
I checked generated ninja file and those .o files are linked to the static library libmediaPipe.a which is linked to final executable. So those classes should not be stripped.
The text was updated successfully, but these errors were encountered: