Skip to content

Fix missing table types when using linStat as a static library#13

Closed
JJL772 wants to merge 1 commit into
mdavidsaver:masterfrom
JJL772:master
Closed

Fix missing table types when using linStat as a static library#13
JJL772 wants to merge 1 commit into
mdavidsaver:masterfrom
JJL772:master

Conversation

@JJL772

@JJL772 JJL772 commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

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,-u to 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:

############################################################################
## EPICS R7.0.10.1-DEV
## Rev. R7.0.10-41-g0597021afc897ed12288-dirty
## Rev. Date Git: 2026-02-06 23:34:31 -0800
############################################################################
sioc-sys-info:IRQ_MAX ERROR devLinInitRecord, "irq|localhost|max_irq" : Not such table factory: irq
sioc-sys-info:SYS_UP ERROR devLinInitRecord, "uptime|localhost|uptime" : Not such table factory: uptime
sioc-sys-info:T_MAX ERROR devLinInitRecord, "hwmon|localhost|temp_max" : Not such table factory: hwmon
sioc-sys-info:MEM_SCAN ERROR devLinInitRecord, "memInfo|localhost|MemTotal" : Not such table factory: memInfo
sioc-sys-info:HOST_SCAN ERROR devLinInitRecord, "host|localhost|ncpu" : Not such table factory: host
sioc-sys-info:STAT_SCAN ERROR devLinInitRecord, "stat|localhost|cpu:2" : Not such table factory: stat
sioc-sys-info:UP_SCAN ERROR devLinInitRecord, "uptime|localhost|uptime" : Not such table factory: uptime
...

Just as a note, I'm on GCC 15.2.0 with binutils 2.46 here.

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.
@mdavidsaver

Copy link
Copy Markdown
Owner

I ran into this issue when compiling an IOC with static libraries for an embedded target.

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.

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).

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, whole-archive or --relocatable (partial linking) would also work. However, that seems like too much cleverness.

@JJL772

JJL772 commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for fixing this @mdavidsaver! Using registrars is definitely the right way to go (and is a lot cleaner.)

@JJL772 JJL772 closed this Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants