Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does _dl_runtime_resolve achieve thread safety?

Tags:

linker

libc

elf

I'm reading this article: https://ypl.coffee/dl-resolve/

Since the GOT table is resolved at runtime (at first call to this function), I'm wondering how does _dl_runtime_resolve ensure it's multi-thread safe?

like image 211
daisy Avatar asked Jan 23 '26 03:01

daisy


1 Answers

how does _dl_runtime_resolve ensure it's multi-thread safe?

Any pure function is thread-safe by definition.

_dl_runtime_resolve is not pure (updates the GOT slot), but if two threads are resolving the same symbol in parallel, both threads will resolve to the same symbol (i.e. they'll compute the exact same target address), and will write the same value into the GOT slot.

While technically this is a data race, practically it doesn't lead to any observable problems.

like image 61
Employed Russian Avatar answered Jan 25 '26 20:01

Employed Russian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!