Stream: platform development

Topic: linkage issues with static variables in platform


view this post on Zulip Nathan Kamenchu (May 14 2025 at 08:46):

I was experiencing linking issues when building a platform around an undefined reference to __dso_handle which as I understand is used in dynamic linking

I'd structured the platform similar to the basic-webserver platform and at some point in time I included a OnceCell in the roc.rs file and a function that used this at which point the roc builds started failing with the trace

/nix/store/qsx2xqqm0lp6d8hi86r4y0rz5v9m62wn-binutils-2.42/bin/ld: examples/../platform/linux-x64.a(host-bdc4bbc507ddd135.host.2987e4b620d406c7-cgu.0.rcgu.o):(.data._rust_extern_with_linkage___dso_handle+0x0): undefined reference to `__dso_handle'

/nix/store/qsx2xqqm0lp6d8hi86r4y0rz5v9m62wn-binutils-2.42/bin/ld: /nix/store/0wydilnf1c9vznywsvxqnaing4wraaxp-glibc-2.39-52/lib/libc_nonshared.a(pthread_atfork.oS): in function `__pthread_atfork':
(.text+0x7): undefined reference to `__dso_handle'

/nix/store/qsx2xqqm0lp6d8hi86r4y0rz5v9m62wn-binutils-2.42/bin/ld: examples/hello_world: hidden symbol `__dso_handle' isn't defined

/nix/store/qsx2xqqm0lp6d8hi86r4y0rz5v9m62wn-binutils-2.42/bin/ld: final link failed: bad value

I'm not very familiar with the message but I've seen that pthread_atfork is used in registering functions to run at thread boundaries which may be useful in locks. Guessing ways to fix this I ended up moving the static Oncecell to the crate root and this seemed to resolve the issue.

Is this a known problem / was this the actual cause

view this post on Zulip Luke Boswell (May 14 2025 at 12:02):

@Brendan Hansknecht may be able to help here.

There are mysterious things we need to do sometimes to get rust playing along with the way we do linking with the current Roc implementation.

view this post on Zulip Nathan Kamenchu (May 14 2025 at 13:05):

Yeah the linkage has been very hit and miss and the error messages have been unhelpful at times

view this post on Zulip Brendan Hansknecht (May 14 2025 at 15:53):

Hmmm :thinking:

view this post on Zulip Brendan Hansknecht (May 14 2025 at 15:55):

:thinkies:
I wish I had a good answer, but these are the kind of finicky issues that require messing with things. And it has been so long since I have done so that I don't have an immediate set of tips.

view this post on Zulip Brendan Hansknecht (May 14 2025 at 15:56):

Are you building the host with musl libc?

view this post on Zulip Brendan Hansknecht (May 14 2025 at 15:57):

Also, I know it is a long while away, but I really hope the new ffi plans for the roc v0.1 end up fixing this class of issues in general....or at least making them much rarer.

view this post on Zulip Anton (May 16 2025 at 08:50):

Is this a known problem / was this the actual cause

This is a known issue #4049. If you are on linux you can try using the surgical linker, it is used by default if you don't specify the linker flag. But the surgical linker does not work with the basic-webserver platform so it may also not work with your platform.


Last updated: Jul 05 2025 at 12:14 UTC