Gcc fvisibility at compile time or link time

I am trying to restrict the ABI of a shared library using the gcc fvisibility function. However, I am confused that this is the right way to do this.

My makefile organizes the build process in two steps. In the first step, all .cpp files are created for object files using some gcc options. Then all the object files are linked to each other using a different set of gcc and ld parameters. From what I read, fvisibility has to do with the second step. However, this contradicts the results that I observe. If I add fvisibility = hidden to the compile time options, the result will be as expected, nm -D will report a much smaller set of exported characters. On the contrary, if I add it to the link time parameters, this does not seem to affect the assembly.

When searching for an explanation, I compared object files created with and without visibility. There seems to be a difference in the addresses of the characters inside the object file. However, I do not know how this difference in addresses transfers the message to the linker so that it can hide characters in one of the cases and expose them in another.

Can anyone explain this to me. Thank you for your time.

+4
source share
1 answer

You can find http://gcc.gnu.org/wiki/Visibility to be useful.

0
source

Source: https://habr.com/ru/post/1314745/


All Articles