RFC: PATCH: PR middle-end/20218: Can't use __attribute__ ((visibility ("hidden"))) to hide a symbol

H. J. Lu hjl@lucon.org
Tue Mar 1 00:31:00 GMT 2005


On Mon, Feb 28, 2005 at 04:52:33PM -0500, Andrew Pinski wrote:
> 
> On Feb 28, 2005, at 4:49 PM, H. J. Lu wrote:
> 
> >This is the first attempt to to fix PR 20218. It keeps a list of
> >referenced global symbols and outputs non-default visibility at the
> >end. I only verified it on Linux/ia32, Linux/x86_64 and Linux/ia64.
> 
> You still have not explained why .hidden is needed for object files 
> which

I thought it was explained in PR 20218.

> use the hidden functions. It seems to me that this should be fixed up in
> binutils while linking where also know if function/variable is hidden.
> 

Gcc doesn't tell linker that a symbol, foo, is hidden when foo is
undefined. The problem is with

# gcc -o libbar.so -shared bar.o libfoo.a

gcc optimizes access to a hidden symbol, foo, in bar.o while foo is
defined in foo.o as a normal symbol. If foo isn't marked as hidden,
you will get a runtime/linktime error on ELF targets since the
optimization is only valid for hidden symbol.

BTW, foo in libfoo.a isn't marked hidden since libfoo.a may be used in
other places where foo shouldn't be hidden.


H.J.



More information about the Gcc-patches mailing list