Replace __attribute__((visibility("protected")))

Message ID 20150306194153.GA30470@intel.com
State Superseded
Headers

Commit Message

Lu, Hongjiu March 6, 2015, 7:41 p.m. UTC
  With copy relocation, address of protected data defined in the shared
library may be external.  Compiler shouldn't asssume protected data will
be local.  But due to

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65248

__attribute__((visibility("protected"))) doesn't work correctly, we need
to use asm (".protected xxx") instead.

OK for master?

Thanks.


H.J.
---
	* elf/ifuncdep2.c (global): Replace
	__attribute__((visibility("protected"))) with
	asm (".protected xxx").
	* elf/ifuncmod1.c (global): Likewise.
	* elf/ifuncmod5.c (global): Likewise.
---
 elf/ifuncdep2.c | 3 ++-
 elf/ifuncmod1.c | 3 ++-
 elf/ifuncmod5.c | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)
  

Comments

Andreas Schwab March 6, 2015, 8:11 p.m. UTC | #1
"H.J. Lu" <hongjiu.lu@intel.com> writes:

> diff --git a/elf/ifuncdep2.c b/elf/ifuncdep2.c
> index 99d1926..599eba7 100644
> --- a/elf/ifuncdep2.c
> +++ b/elf/ifuncdep2.c
> @@ -2,7 +2,8 @@
>  
>  #include "ifunc-sel.h"
>  
> -int global __attribute__ ((visibility ("protected"))) = -1;
> +int global = -1;
> +asm (".protected global");

Some architectures use a symbol prefix.

Andreas.
  
Joseph Myers March 6, 2015, 10:25 p.m. UTC | #2
On Fri, 6 Mar 2015, Andreas Schwab wrote:

> "H.J. Lu" <hongjiu.lu@intel.com> writes:
> 
> > diff --git a/elf/ifuncdep2.c b/elf/ifuncdep2.c
> > index 99d1926..599eba7 100644
> > --- a/elf/ifuncdep2.c
> > +++ b/elf/ifuncdep2.c
> > @@ -2,7 +2,8 @@
> >  
> >  #include "ifunc-sel.h"
> >  
> > -int global __attribute__ ((visibility ("protected"))) = -1;
> > +int global = -1;
> > +asm (".protected global");
> 
> Some architectures use a symbol prefix.

No such architectures are currently supported by glibc, and I expect lots 
of places would need fixing if support were to be added for any such 
architecture.  (Using symbol prefixes with ELF also violates the gABI, 
which says "External C symbols have the same names in C and object files' 
symbol tables.".)
  
Roland McGrath March 6, 2015, 10:28 p.m. UTC | #3
It needs comments.
  
H.J. Lu March 6, 2015, 10:37 p.m. UTC | #4
On Fri, Mar 6, 2015 at 2:28 PM, Roland McGrath <roland@hack.frob.com> wrote:
> It needs comments.

Did you mean duplicate my commit log to each
__attribute__ ((visibility ("protected"))) change?
What about existing

asm (".protected xxx");

Do they also need comments?  I don't think it is necessary
since the commit log explains why a change is made.
  
Roland McGrath March 6, 2015, 10:59 p.m. UTC | #5
> On Fri, Mar 6, 2015 at 2:28 PM, Roland McGrath <roland@hack.frob.com> wrote:
> > It needs comments.
> 
> Did you mean duplicate my commit log to each
> __attribute__ ((visibility ("protected"))) change?
> What about existing
> 
> asm (".protected xxx");
> 
> Do they also need comments?  I don't think it is necessary
> since the commit log explains why a change is made.

What's necessary is that comments next to the actual code explain why it's
any nonobvious way it is.  In this case, you need a short comment
mentioning the GCC bug in each place that you're avoiding using the obvious
compiler feature because of a bug.
  

Patch

diff --git a/elf/ifuncdep2.c b/elf/ifuncdep2.c
index 99d1926..599eba7 100644
--- a/elf/ifuncdep2.c
+++ b/elf/ifuncdep2.c
@@ -2,7 +2,8 @@ 
 
 #include "ifunc-sel.h"
 
-int global __attribute__ ((visibility ("protected"))) = -1;
+int global = -1;
+asm (".protected global");
 
 static int
 one (void)
diff --git a/elf/ifuncmod1.c b/elf/ifuncmod1.c
index 2b8195c..c99ac11 100644
--- a/elf/ifuncmod1.c
+++ b/elf/ifuncmod1.c
@@ -6,7 +6,8 @@ 
  */
 #include "ifunc-sel.h"
 
-int global __attribute__ ((visibility ("protected"))) = -1;
+int global = -1;
+asm (".protected global");
 
 static int
 one (void)
diff --git a/elf/ifuncmod5.c b/elf/ifuncmod5.c
index 9a08e8c..1d79d80 100644
--- a/elf/ifuncmod5.c
+++ b/elf/ifuncmod5.c
@@ -1,7 +1,8 @@ 
 /* Test STT_GNU_IFUNC symbols without direct function call.  */
 #include "ifunc-sel.h"
 
-int global __attribute__ ((visibility ("protected"))) = -1;
+int global = -1;
+asm (".protected global");
 
 static int
 one (void)