placeholder

So you want to live-reload Rust - fasterthanli.me

Good morning! It is still 2020, and the world is literally on fire , so I guess we could all use a distraction. This article continues the tradition of me getting shamelessly n...

Click to view the original at fasterthanli.me

Hasnain says:

Enter the world of ungodly, crazy hacks when live reloading code. I learnt a lot more than I think I’ll ever need to about process lifetimes and how the linker works on Linux. But this is really cool.

“With our workaround, or "breakaround", as I've recently taken to calling it, we've entered the land of super-duper-undefined behavior, aka SDUB.

Because events are happening in this order:

T1 (main thread) spawns a second thread, T2
In T2, libgreet.so is loaded
In T2, greet() from libgreet.so is called
In T2, greet() calls println!(), which accesses LOCAL_STDOUT, which is initialized, and for which a TLS destructor is registered (using the fallback, since we hid __cxa_thread_atexit_impl)
In T2, lib is dropped, so libgreet.so is unloaded
T2 finishes, so all pthreads TLS key destructors are called (this is how the fallback works)

...however, the destructors' code was in the DSO we just unloaded.”

Posted on 2020-09-28T00:09:23+0000