Fix missing table types when using linStat as a static library#13
Fix missing table types when using linStat as a static library#13JJL772 wants to merge 1 commit into
Conversation
When using static libraries, the linker will eliminate object files that it determines to be unreferenced, leading to linStat table types not being registered. The only sure-fire way to fix this is to generate references to symbols within the eliminated object files. This can be done at link time with -Wl,-u or with ugly hacky methods like the one in this commit.
oops... I have added a GHA job for, and fixed static linking, with e07c61a. I opted to dispense with special section cleverness, and use DBD and registrars instead.
This situation is a bit broader actually. It also applies to global constructors. This involves the process by which the linker chooses which object files to include. By long standing tradition, object files passed explicitly when invoking the linker are always included. However, object files in static libraries are only included if needed to satisfy some otherwise missing symbol. As you say, |
|
Thanks for fixing this @mdavidsaver! Using registrars is definitely the right way to go (and is a lot cleaner.) |
I ran into this issue when compiling an IOC with static libraries for an embedded target.
Unfortunately
__attribute__((used))and__attribute__((retain))are not enough to prevent the linker from eliminating "unused" object files (presumably the linker has no knowledge of these attributes).To my knowledge, the only sure-fire ways to fix this are by using
-Wl,-uto reference symbols defined in each object, doing the ugly hacky thing I did here, or by using-Wl,--whole-archive(which can cause other issues with certain static libraries).Prior to this patch, I was getting:
Just as a note, I'm on GCC 15.2.0 with binutils 2.46 here.