diff mbox series

PR82687, g++.dg/asan/default-options-1.C fails with PR82575 fix

Message ID 20171024093139.GF27132@bubble.grove.modra.org
State New
Headers show
Series PR82687, g++.dg/asan/default-options-1.C fails with PR82575 fix | expand

Commit Message

Alan Modra Oct. 24, 2017, 9:31 a.m. UTC
Was Re: PR82575, lto debugobj references __gnu_lto_slim, ld test liblto-17 fails
On Fri, Oct 20, 2017 at 12:00:04AM +1030, Alan Modra wrote:
> 	PR lto/82575
> 	* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
> 	Make discarded non-local symbols weak and hidden.

The problem with making discarded symbols hidden is that the
non-default visibility is sticky.  When symbols other than the
__gnu_lto ones are discarded that turns out to be a bad idea.

Bootstrapped and regression tested powerpc64le-linux.  OK?

	PR lto/82687
	PR lto/82575
	* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
	Only make __gnu_lto symbols hidden.  Delete outdated comment.
	Silence ISO C warning.

Comments

Richard Biener Oct. 24, 2017, 9:48 a.m. UTC | #1
On Tue, 24 Oct 2017, Alan Modra wrote:

> Was Re: PR82575, lto debugobj references __gnu_lto_slim, ld test liblto-17 fails
> On Fri, Oct 20, 2017 at 12:00:04AM +1030, Alan Modra wrote:
> > 	PR lto/82575
> > 	* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
> > 	Make discarded non-local symbols weak and hidden.
> 
> The problem with making discarded symbols hidden is that the
> non-default visibility is sticky.  When symbols other than the
> __gnu_lto ones are discarded that turns out to be a bad idea.

So a UNDEF weak hidden causes a later non-weak defined default
visibility symbol to become hidden?  The wonders of ELF ...

> Bootstrapped and regression tested powerpc64le-linux.  OK?

Ok.

Richard.

> 	PR lto/82687
> 	PR lto/82575
> 	* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
> 	Only make __gnu_lto symbols hidden.  Delete outdated comment.
> 	Silence ISO C warning.
> 
> diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c
> index 1afd3eb..14f7105 100644
> --- a/libiberty/simple-object-elf.c
> +++ b/libiberty/simple-object-elf.c
> @@ -1088,6 +1088,7 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
>    off_t shstroff;
>    unsigned char *names;
>    unsigned int i;
> +  int changed;
>    int *pfnret;
>    const char **pfnname;
>  
> @@ -1161,7 +1162,6 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
>  
>    /* Mark sections as preserved that are required by to be preserved
>       sections.  */
> -  int changed;
>    do
>      {
>        changed = 0;
> @@ -1349,9 +1349,6 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
>  		     and __gnu_lto_slim which otherwise cause endless
>  		     LTO plugin invocation.  */
>  		  if (st_shndx == SHN_COMMON)
> -		    /* Setting st_name to "" seems to work to purge
> -		       COMMON symbols (in addition to setting their
> -		       size to zero).  */
>  		    discard = 1;
>  		  /* We also need to remove symbols refering to sections
>  		     we'll eventually remove as with fat LTO objects
> @@ -1368,17 +1365,29 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
>  		      /* Make discarded symbols undefined and unnamed
>  		         in case it is local.  */
>  		      int bind = ELF_ST_BIND (*st_info);
> +		      int other = STV_DEFAULT;
> +		      size_t st_name;
> +
>  		      if (bind == STB_LOCAL)
> -			{
> -			  ELF_SET_FIELD (type_functions, ei_class, Sym,
> -					 ent, st_name, Elf_Word, 0);
> -			  *st_other = STV_DEFAULT;
> -			}
> +			ELF_SET_FIELD (type_functions, ei_class, Sym,
> +				       ent, st_name, Elf_Word, 0);
>  		      else
>  			{
>  			  bind = STB_WEAK;
> -			  *st_other = STV_HIDDEN;
> +			  st_name = ELF_FETCH_FIELD (type_functions, ei_class,
> +						     Sym, ent, st_name,
> +						     Elf_Word);
> +			  if (st_name < strsz)
> +			    {
> +			      char *p = strings + st_name;
> +			      if (p[0] == '_'
> +				  && p[1] == '_'
> +				  && strncmp (p + (p[2] == '_'),
> +					      "__gnu_lto_", 10) == 0)
> +				other = STV_HIDDEN;
> +			    }
>  			}
> +		      *st_other = other;
>  		      *st_info = ELF_ST_INFO (bind, STT_NOTYPE);
>  		      ELF_SET_FIELD (type_functions, ei_class, Sym,
>  				     ent, st_value, Elf_Addr, 0);
Alan Modra Oct. 25, 2017, 12:27 a.m. UTC | #2
On Tue, Oct 24, 2017 at 11:48:27AM +0200, Richard Biener wrote:
> On Tue, 24 Oct 2017, Alan Modra wrote:
> > The problem with making discarded symbols hidden is that the
> > non-default visibility is sticky.  When symbols other than the
> > __gnu_lto ones are discarded that turns out to be a bad idea.
> 
> So a UNDEF weak hidden causes a later non-weak defined default
> visibility symbol to become hidden?  The wonders of ELF ...

Yes..

> > Bootstrapped and regression tested powerpc64le-linux.  OK?
> 
> Ok.

Committed r254042.  Let's hope this works.  Rewriting the symbol
table, which of course is the right thing to do rather than these
hacks, is a pain.  Relocations would need r_info updates, and so would
group signatures.
Richard Biener Oct. 25, 2017, 5:48 a.m. UTC | #3
On October 25, 2017 2:27:12 AM GMT+02:00, Alan Modra <amodra@gmail.com> wrote:
>On Tue, Oct 24, 2017 at 11:48:27AM +0200, Richard Biener wrote:
>> On Tue, 24 Oct 2017, Alan Modra wrote:
>> > The problem with making discarded symbols hidden is that the
>> > non-default visibility is sticky.  When symbols other than the
>> > __gnu_lto ones are discarded that turns out to be a bad idea.
>> 
>> So a UNDEF weak hidden causes a later non-weak defined default
>> visibility symbol to become hidden?  The wonders of ELF ...
>
>Yes..
>
>> > Bootstrapped and regression tested powerpc64le-linux.  OK?
>> 
>> Ok.
>
>Committed r254042.  Let's hope this works.  Rewriting the symbol
>table, which of course is the right thing to do rather than these
>hacks, is a pain.  Relocations would need r_info updates, and so would
>group signatures.

Yeah. There's a reason why I didn't do that...

Richard.
diff mbox series

Patch

diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c
index 1afd3eb..14f7105 100644
--- a/libiberty/simple-object-elf.c
+++ b/libiberty/simple-object-elf.c
@@ -1088,6 +1088,7 @@  simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
   off_t shstroff;
   unsigned char *names;
   unsigned int i;
+  int changed;
   int *pfnret;
   const char **pfnname;
 
@@ -1161,7 +1162,6 @@  simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
 
   /* Mark sections as preserved that are required by to be preserved
      sections.  */
-  int changed;
   do
     {
       changed = 0;
@@ -1349,9 +1349,6 @@  simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
 		     and __gnu_lto_slim which otherwise cause endless
 		     LTO plugin invocation.  */
 		  if (st_shndx == SHN_COMMON)
-		    /* Setting st_name to "" seems to work to purge
-		       COMMON symbols (in addition to setting their
-		       size to zero).  */
 		    discard = 1;
 		  /* We also need to remove symbols refering to sections
 		     we'll eventually remove as with fat LTO objects
@@ -1368,17 +1365,29 @@  simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
 		      /* Make discarded symbols undefined and unnamed
 		         in case it is local.  */
 		      int bind = ELF_ST_BIND (*st_info);
+		      int other = STV_DEFAULT;
+		      size_t st_name;
+
 		      if (bind == STB_LOCAL)
-			{
-			  ELF_SET_FIELD (type_functions, ei_class, Sym,
-					 ent, st_name, Elf_Word, 0);
-			  *st_other = STV_DEFAULT;
-			}
+			ELF_SET_FIELD (type_functions, ei_class, Sym,
+				       ent, st_name, Elf_Word, 0);
 		      else
 			{
 			  bind = STB_WEAK;
-			  *st_other = STV_HIDDEN;
+			  st_name = ELF_FETCH_FIELD (type_functions, ei_class,
+						     Sym, ent, st_name,
+						     Elf_Word);
+			  if (st_name < strsz)
+			    {
+			      char *p = strings + st_name;
+			      if (p[0] == '_'
+				  && p[1] == '_'
+				  && strncmp (p + (p[2] == '_'),
+					      "__gnu_lto_", 10) == 0)
+				other = STV_HIDDEN;
+			    }
 			}
+		      *st_other = other;
 		      *st_info = ELF_ST_INFO (bind, STT_NOTYPE);
 		      ELF_SET_FIELD (type_functions, ei_class, Sym,
 				     ent, st_value, Elf_Addr, 0);