Skip to content

Keep backend objects in static builds with GCC and Clang - #135

Merged
ethindp merged 1 commit into
ethindp:masterfrom
trypsynth:fix/gnu-backend-anchors
Sep 22, 2026
Merged

ethindp merged 1 commit into
ethindp:masterfrom
trypsynth:fix/gnu-backend-anchors

Conversation

@trypsynth

Copy link
Copy Markdown
Contributor

Fixes #130.

A static prism linked with GCC or Clang registers no backends unless the archive is linked whole. gnu::used and gnu::retain keep a registrar inside its own object, but nothing references a backend's object, so the linker never pulls it out of the archive in the first place. #125 solved this for MSVC with /include: directives. Every other toolchain was still relying on the attributes.

What this does

The anchors #125 added are already emitted on every compiler. The generated backend_anchors.h now also covers GCC and Clang: it declares each backend's anchor and takes its address in a [[gnu::used]] array. The header is included by prism.cpp, which the linker always keeps because the application calls prism_init, so those references pull every backend object in. MSVC keeps its directives, unchanged.

The header is generated and included on every platform now, rather than only under MSVC.

Testing

The reproduction from #130, on GitHub's runners, linking libprism.a with no --whole-archive or -force_load:

Ubuntu 24.04, GCC 13.3 (speech_dispatcher=on):

registered backends: 1
  Speech Dispatcher

macOS, Apple Clang (avspeech=on voiceover=on):

registered backends: 2
  VoiceOver
  AVSpeech

The MSVC static build was checked as well, in a .NET Native AOT application that links prism.lib and lists its backends on x64, x86 and ARM64.

@ethindp
ethindp merged commit a2d405e into ethindp:master Sep 22, 2026
65 checks passed
Orinks added a commit to orinks-games/Freight-Fate that referenced this pull request Oct 2, 2026
prismer 0.1.4 vendors Prism 0.18.3, which loads the optional Windows
screen-reader DLLs (PC-Talker, ZDSR, BoyPCReader) with LoadLibrary and
Linux's libspeechd with dlopen, and anchors its backends for GCC and
Clang (ethindp/prism#135, #136, #146). So build.rs no longer emits the
/DELAYLOAD list, the /INCLUDE of the delay-load failure hook, the
whole-archive link of libprism.a, or a link of speech-dispatcher.

The release exe now has no delay imports at all, and
--list-speech-backends reports every absent reader as not installed
instead of risking 0xC06D007E. On Linux the game starts without Speech
Dispatcher; the nightly's Debian, Ubuntu and openSUSE boots now run
without its client library to prove it, while Fedora still has to pick
it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

Static builds on Linux (GCC) register no backends: the #125 anchors only cover MSVC

2 participants