https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65886
--- Comment #11 from H.J. Lu <hjl.tools at gmail dot com> --- (In reply to Thiago Macieira from comment #8) > (In reply to H.J. Lu from comment #6) > > /export/build/gnu/gcc-5/build-x86_64-linux/gcc/xgcc > > -B/export/build/gnu/gcc-5/build-x86_64-linux/gcc/ -flto -Wl,-Bsymbolic -g > > -O2 -fsymbolic -shared -o libb.so b.o a.o > > Will the LTO be required here? Or will it work without LTO too? > > > Dump of assembler code for function bar: > > 0x00000000000005e0 <+0>: movl $0x1e,0x2002be(%rip) # 0x2008a8 > > <a> > > 0x00000000000005ea <+10>: retq > > End of assembler dump. LTO is required only when definition and references aren't in the same file. > I've been accomplishing the same with protected visibility, but I keep > running into linker bugs, so I haven't been able to enable it by default. > Looks like the option here will be the proper solution. Protected data symbol means that it can't be pre-emptied. It doesn't mean its address won't be external. This is true for pointer to protected function. With copy relocation, address of protected data defined in the shared library may also be external. We only know that for sure at run-time: https://sourceware.org/bugzilla/show_bug.cgi?id=17711 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65248 What you want is -fsymbolic with -Bsymbolic.