3 ms·
It's interesting, I've been coding in C for 15 years and I wasn't aware of this caveat. I'm surprised I never encountered this issue in the wild but then again
by simias 8y ago
It's interesting, I've been coding in C for 15 years and I wasn't aware of this caveat. I'm surprised I never encountered this issue in the wild but then again I can't really imagine a situation where I'd share a raw extern array across ABI boundaries without any abstractions on top of it.
Still, it's noteworthy that the dynamic linker will attempt to fully copy the array in such a situation, that seems rather heavy handed even if I understand the justification. Maybe now that LTO is more prevalent the linker could figure out that the symbol is not part of the executable and insert the indirection through the GOT instead?
- foldr 8y ago>Maybe now that LTO is more prevalent the linker could figure out that the symbol is not part of the executable and insert the indirection through the GOT instead? I'm pretty sure this is already possible. I think the copy relocations are a kind of optimization. If a shared lib contains mutable variables then at least some of the library has to be copied every time a process modifies that variable. Copy relocations help to avoid this.