public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Share a prevailing name for remove debug info symbols w/ LTO.
@ 2019-08-27  9:09 Martin Liška
  2019-08-27 11:09 ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Liška @ 2019-08-27  9:09 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ian Lance Taylor, Richard Biener

[-- Attachment #1: Type: text/plain, Size: 652 bytes --]

Hi.

The patch is about better symbol table manipulation
for debug info objects. The patch fixes reported issue
on hppa64-hp-hpux11.11.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

libiberty/ChangeLog:

2019-08-27  Martin Liska  <mliska@suse.cz>

	PR lto/91478
	* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
	First find a WEAK HIDDEN symbol in symbol table that will be
	preserved.  Later, use the symbol name for all removed symbols.
---
 libiberty/simple-object-elf.c | 71 +++++++++++++++++++++++------------
 1 file changed, 48 insertions(+), 23 deletions(-)



[-- Attachment #2: 0001-Share-a-prevailing-name-for-remove-debug-info-symbol.patch --]
[-- Type: text/x-patch, Size: 4682 bytes --]

diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c
index 75159266596..b637e4b0c92 100644
--- a/libiberty/simple-object-elf.c
+++ b/libiberty/simple-object-elf.c
@@ -1366,30 +1366,17 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
 	  return errmsg;
 	}
 
-      /* If we are processing .symtab purge __gnu_lto_slim symbol
-	 from it and any symbols in discarded sections.  */
+      /* If we are processing .symtab purge any symbols
+	 in discarded sections.  */
       if (sh_type == SHT_SYMTAB)
 	{
 	  unsigned entsize = ELF_FETCH_FIELD (type_functions, ei_class, Shdr,
 					      shdr, sh_entsize, Elf_Addr);
 	  unsigned strtab = ELF_FETCH_FIELD (type_functions, ei_class, Shdr,
 					     shdr, sh_link, Elf_Word);
-	  unsigned char *strshdr = shdrs + (strtab - 1) * shdr_size;
-	  off_t stroff = ELF_FETCH_FIELD (type_functions, ei_class, Shdr,
-					  strshdr, sh_offset, Elf_Addr);
-	  size_t strsz = ELF_FETCH_FIELD (type_functions, ei_class, Shdr,
-					  strshdr, sh_size, Elf_Addr);
-	  char *strings = XNEWVEC (char, strsz);
-	  char *gnu_lto = strings;
+	  size_t prevailing_name_idx = 0;
 	  unsigned char *ent;
 	  unsigned *shndx_table = NULL;
-	  simple_object_internal_read (sobj->descriptor,
-				       sobj->offset + stroff,
-				       (unsigned char *)strings,
-				       strsz, &errmsg, err);
-	  /* Find first '\0' in strings.  */
-	  gnu_lto = (char *) memchr (gnu_lto + 1, '\0',
-				     strings + strsz - gnu_lto);
 	  /* Read the section index table if present.  */
 	  if (symtab_indices_shndx[i - 1] != 0)
 	    {
@@ -1404,6 +1391,41 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
 					   (unsigned char *)shndx_table,
 					   sidxsz, &errmsg, err);
 	    }
+
+	  /* Find a WEAK HIDDEN symbol which name we will use for removed
+	     symbols.  */
+	  for (ent = buf; ent < buf + length; ent += entsize)
+	    {
+	      unsigned st_shndx = ELF_FETCH_FIELD (type_functions, ei_class,
+						   Sym, ent,
+						   st_shndx, Elf_Half);
+	      unsigned char *st_info;
+	      unsigned char *st_other;
+	      if (ei_class == ELFCLASS32)
+		{
+		  st_info = &((Elf32_External_Sym *)ent)->st_info;
+		  st_other = &((Elf32_External_Sym *)ent)->st_other;
+		}
+	      else
+		{
+		  st_info = &((Elf64_External_Sym *)ent)->st_info;
+		  st_other = &((Elf64_External_Sym *)ent)->st_other;
+		}
+	      if (st_shndx == SHN_XINDEX)
+		st_shndx = type_functions->fetch_Elf_Word
+		    ((unsigned char *)(shndx_table + (ent - buf) / entsize));
+
+	      if (st_shndx != SHN_COMMON
+		  && !(st_shndx != SHN_UNDEF
+		       && st_shndx < shnum
+		       && pfnret[st_shndx - 1] == -1)
+		  && ELF_ST_BIND (*st_info) == STB_WEAK
+		  && *st_other == STV_HIDDEN)
+		prevailing_name_idx = ELF_FETCH_FIELD (type_functions, ei_class,
+						       Sym, ent,
+						       st_name, Elf_Addr);
+	    }
+
 	  for (ent = buf; ent < buf + length; ent += entsize)
 	    {
 	      unsigned st_shndx = ELF_FETCH_FIELD (type_functions, ei_class,
@@ -1426,9 +1448,10 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
 	      if (st_shndx == SHN_XINDEX)
 		st_shndx = type_functions->fetch_Elf_Word
 		    ((unsigned char *)(shndx_table + (ent - buf) / entsize));
-	      /* Eliminate all COMMONs - this includes __gnu_lto_v1
-		 and __gnu_lto_slim which otherwise cause endless
-		 LTO plugin invocation.  */
+	      /* Eliminate all COMMONs - this includes __gnu_lto_slim
+		 which otherwise cause endless LTO plugin invocation.
+		 FIXME: remove the condition once we remove emission
+		 of __gnu_lto_slim symbol.  */
 	      if (st_shndx == SHN_COMMON)
 		discard = 1;
 	      /* We also need to remove symbols refering to sections
@@ -1460,12 +1483,15 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
 		  else
 		    {
 		      /* Make discarded global symbols hidden weak
-			 undefined and sharing the gnu_lto_ name.  */
+			 undefined and sharing a name of a prevailing
+			 symbol.  */
 		      bind = STB_WEAK;
 		      other = STV_HIDDEN;
+
 		      ELF_SET_FIELD (type_functions, ei_class, Sym,
-				     ent, st_name, Elf_Word,
-				     gnu_lto - strings);
+				     ent, st_name, Elf_Addr,
+				     prevailing_name_idx);
+
 		      ELF_SET_FIELD (type_functions, ei_class, Sym,
 				     ent, st_shndx, Elf_Half, SHN_UNDEF);
 		    }
@@ -1482,7 +1508,6 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
 		ELF_SET_FIELD (type_functions, ei_class, Sym,
 			       ent, st_shndx, Elf_Half, sh_map[st_shndx]);
 	    }
-	  XDELETEVEC (strings);
 	  XDELETEVEC (shndx_table);
 	}
       else if (sh_type == SHT_GROUP)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Share a prevailing name for remove debug info symbols w/ LTO.
  2019-08-27  9:09 [PATCH] Share a prevailing name for remove debug info symbols w/ LTO Martin Liška
@ 2019-08-27 11:09 ` Richard Biener
  2019-08-27 12:28   ` Martin Liška
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2019-08-27 11:09 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches, Ian Lance Taylor

On Tue, Aug 27, 2019 at 9:28 AM Martin Liška <mliska@suse.cz> wrote:
>
> Hi.
>
> The patch is about better symbol table manipulation
> for debug info objects. The patch fixes reported issue
> on hppa64-hp-hpux11.11.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?

+               prevailing_name_idx = ELF_FETCH_FIELD (type_functions, ei_class,
+                                                      Sym, ent,
+                                                      st_name, Elf_Addr);

this should be Elf_Word.  Please add a break; after you found a symbol.
Please also amend the comment before this loop to say that we know
there's a prevailing weak hidden symbol at the start of the .debug_info section
so we'll always at least find that one.

-                        undefined and sharing the gnu_lto_ name.  */
+                        undefined and sharing a name of a prevailing
+                        symbol.  */
                      bind = STB_WEAK;
                      other = STV_HIDDEN;
+
                      ELF_SET_FIELD (type_functions, ei_class, Sym,
-                                    ent, st_name, Elf_Word,
-                                    gnu_lto - strings);
+                                    ent, st_name, Elf_Addr,
+                                    prevailing_name_idx);
+

Likewise Elf_Word, no need to add vertical spacing before and after
this stmt.

                      ELF_SET_FIELD (type_functions, ei_class, Sym,




> Thanks,
> Martin
>
> libiberty/ChangeLog:
>
> 2019-08-27  Martin Liska  <mliska@suse.cz>
>
>         PR lto/91478
>         * simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
>         First find a WEAK HIDDEN symbol in symbol table that will be
>         preserved.  Later, use the symbol name for all removed symbols.
> ---
>  libiberty/simple-object-elf.c | 71 +++++++++++++++++++++++------------
>  1 file changed, 48 insertions(+), 23 deletions(-)
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Share a prevailing name for remove debug info symbols w/ LTO.
  2019-08-27 11:09 ` Richard Biener
@ 2019-08-27 12:28   ` Martin Liška
  2019-08-27 13:28     ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Liška @ 2019-08-27 12:28 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches, Ian Lance Taylor

[-- Attachment #1: Type: text/plain, Size: 2205 bytes --]

On 8/27/19 12:40 PM, Richard Biener wrote:
> On Tue, Aug 27, 2019 at 9:28 AM Martin Liška <mliska@suse.cz> wrote:
>>
>> Hi.
>>
>> The patch is about better symbol table manipulation
>> for debug info objects. The patch fixes reported issue
>> on hppa64-hp-hpux11.11.
>>
>> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>>
>> Ready to be installed?
> 
> +               prevailing_name_idx = ELF_FETCH_FIELD (type_functions, ei_class,
> +                                                      Sym, ent,
> +                                                      st_name, Elf_Addr);
> 
> this should be Elf_Word.  Please add a break; after you found a symbol.
> Please also amend the comment before this loop to say that we know
> there's a prevailing weak hidden symbol at the start of the .debug_info section
> so we'll always at least find that one.
> 
> -                        undefined and sharing the gnu_lto_ name.  */
> +                        undefined and sharing a name of a prevailing
> +                        symbol.  */
>                       bind = STB_WEAK;
>                       other = STV_HIDDEN;
> +
>                       ELF_SET_FIELD (type_functions, ei_class, Sym,
> -                                    ent, st_name, Elf_Word,
> -                                    gnu_lto - strings);
> +                                    ent, st_name, Elf_Addr,
> +                                    prevailing_name_idx);
> +
> 
> Likewise Elf_Word, no need to add vertical spacing before and after
> this stmt.
> 
>                       ELF_SET_FIELD (type_functions, ei_class, Sym,

Thanks for review, all should be addresses in updated patch.

Martin

> 
> 
> 
> 
>> Thanks,
>> Martin
>>
>> libiberty/ChangeLog:
>>
>> 2019-08-27  Martin Liska  <mliska@suse.cz>
>>
>>         PR lto/91478
>>         * simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
>>         First find a WEAK HIDDEN symbol in symbol table that will be
>>         preserved.  Later, use the symbol name for all removed symbols.
>> ---
>>  libiberty/simple-object-elf.c | 71 +++++++++++++++++++++++------------
>>  1 file changed, 48 insertions(+), 23 deletions(-)
>>
>>


[-- Attachment #2: 0001-Share-a-prevailing-name-for-remove-debug-info-symbol-v2.patch --]
[-- Type: text/x-patch, Size: 5394 bytes --]

From 44cd8d309922464697847e1c70f2bd37e748e7bd Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Mon, 26 Aug 2019 16:11:34 +0200
Subject: [PATCH] Share a prevailing name for remove debug info symbols w/ LTO.

libiberty/ChangeLog:

2019-08-27  Martin Liska  <mliska@suse.cz>

	PR lto/91478
	* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
	First find a WEAK HIDDEN symbol in symbol table that will be
	preserved.  Later, use the symbol name for all removed symbols.
---
 libiberty/simple-object-elf.c | 71 ++++++++++++++++++++++++-----------
 1 file changed, 49 insertions(+), 22 deletions(-)

diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c
index 75159266596..03ca42498f3 100644
--- a/libiberty/simple-object-elf.c
+++ b/libiberty/simple-object-elf.c
@@ -1366,30 +1366,17 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
 	  return errmsg;
 	}
 
-      /* If we are processing .symtab purge __gnu_lto_slim symbol
-	 from it and any symbols in discarded sections.  */
+      /* If we are processing .symtab purge any symbols
+	 in discarded sections.  */
       if (sh_type == SHT_SYMTAB)
 	{
 	  unsigned entsize = ELF_FETCH_FIELD (type_functions, ei_class, Shdr,
 					      shdr, sh_entsize, Elf_Addr);
 	  unsigned strtab = ELF_FETCH_FIELD (type_functions, ei_class, Shdr,
 					     shdr, sh_link, Elf_Word);
-	  unsigned char *strshdr = shdrs + (strtab - 1) * shdr_size;
-	  off_t stroff = ELF_FETCH_FIELD (type_functions, ei_class, Shdr,
-					  strshdr, sh_offset, Elf_Addr);
-	  size_t strsz = ELF_FETCH_FIELD (type_functions, ei_class, Shdr,
-					  strshdr, sh_size, Elf_Addr);
-	  char *strings = XNEWVEC (char, strsz);
-	  char *gnu_lto = strings;
+	  size_t prevailing_name_idx = 0;
 	  unsigned char *ent;
 	  unsigned *shndx_table = NULL;
-	  simple_object_internal_read (sobj->descriptor,
-				       sobj->offset + stroff,
-				       (unsigned char *)strings,
-				       strsz, &errmsg, err);
-	  /* Find first '\0' in strings.  */
-	  gnu_lto = (char *) memchr (gnu_lto + 1, '\0',
-				     strings + strsz - gnu_lto);
 	  /* Read the section index table if present.  */
 	  if (symtab_indices_shndx[i - 1] != 0)
 	    {
@@ -1404,6 +1391,45 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
 					   (unsigned char *)shndx_table,
 					   sidxsz, &errmsg, err);
 	    }
+
+	  /* Find a WEAK HIDDEN symbol which name we will use for removed
+	     symbols.  We know there's a prevailing weak hidden symbol
+	     at the start of the .debug_info section.  */
+	  for (ent = buf; ent < buf + length; ent += entsize)
+	    {
+	      unsigned st_shndx = ELF_FETCH_FIELD (type_functions, ei_class,
+						   Sym, ent,
+						   st_shndx, Elf_Half);
+	      unsigned char *st_info;
+	      unsigned char *st_other;
+	      if (ei_class == ELFCLASS32)
+		{
+		  st_info = &((Elf32_External_Sym *)ent)->st_info;
+		  st_other = &((Elf32_External_Sym *)ent)->st_other;
+		}
+	      else
+		{
+		  st_info = &((Elf64_External_Sym *)ent)->st_info;
+		  st_other = &((Elf64_External_Sym *)ent)->st_other;
+		}
+	      if (st_shndx == SHN_XINDEX)
+		st_shndx = type_functions->fetch_Elf_Word
+		    ((unsigned char *)(shndx_table + (ent - buf) / entsize));
+
+	      if (st_shndx != SHN_COMMON
+		  && !(st_shndx != SHN_UNDEF
+		       && st_shndx < shnum
+		       && pfnret[st_shndx - 1] == -1)
+		  && ELF_ST_BIND (*st_info) == STB_WEAK
+		  && *st_other == STV_HIDDEN)
+		{
+		  prevailing_name_idx = ELF_FETCH_FIELD (type_functions,
+							 ei_class, Sym, ent,
+							 st_name, Elf_Word);
+		  break;
+		}
+	    }
+
 	  for (ent = buf; ent < buf + length; ent += entsize)
 	    {
 	      unsigned st_shndx = ELF_FETCH_FIELD (type_functions, ei_class,
@@ -1426,9 +1452,10 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
 	      if (st_shndx == SHN_XINDEX)
 		st_shndx = type_functions->fetch_Elf_Word
 		    ((unsigned char *)(shndx_table + (ent - buf) / entsize));
-	      /* Eliminate all COMMONs - this includes __gnu_lto_v1
-		 and __gnu_lto_slim which otherwise cause endless
-		 LTO plugin invocation.  */
+	      /* Eliminate all COMMONs - this includes __gnu_lto_slim
+		 which otherwise cause endless LTO plugin invocation.
+		 FIXME: remove the condition once we remove emission
+		 of __gnu_lto_slim symbol.  */
 	      if (st_shndx == SHN_COMMON)
 		discard = 1;
 	      /* We also need to remove symbols refering to sections
@@ -1460,12 +1487,13 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
 		  else
 		    {
 		      /* Make discarded global symbols hidden weak
-			 undefined and sharing the gnu_lto_ name.  */
+			 undefined and sharing a name of a prevailing
+			 symbol.  */
 		      bind = STB_WEAK;
 		      other = STV_HIDDEN;
 		      ELF_SET_FIELD (type_functions, ei_class, Sym,
 				     ent, st_name, Elf_Word,
-				     gnu_lto - strings);
+				     prevailing_name_idx);
 		      ELF_SET_FIELD (type_functions, ei_class, Sym,
 				     ent, st_shndx, Elf_Half, SHN_UNDEF);
 		    }
@@ -1482,7 +1510,6 @@ simple_object_elf_copy_lto_debug_sections (simple_object_read *sobj,
 		ELF_SET_FIELD (type_functions, ei_class, Sym,
 			       ent, st_shndx, Elf_Half, sh_map[st_shndx]);
 	    }
-	  XDELETEVEC (strings);
 	  XDELETEVEC (shndx_table);
 	}
       else if (sh_type == SHT_GROUP)
-- 
2.22.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Share a prevailing name for remove debug info symbols w/ LTO.
  2019-08-27 12:28   ` Martin Liška
@ 2019-08-27 13:28     ` Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2019-08-27 13:28 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches, Ian Lance Taylor

On Tue, Aug 27, 2019 at 1:31 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 8/27/19 12:40 PM, Richard Biener wrote:
> > On Tue, Aug 27, 2019 at 9:28 AM Martin Liška <mliska@suse.cz> wrote:
> >>
> >> Hi.
> >>
> >> The patch is about better symbol table manipulation
> >> for debug info objects. The patch fixes reported issue
> >> on hppa64-hp-hpux11.11.
> >>
> >> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
> >>
> >> Ready to be installed?
> >
> > +               prevailing_name_idx = ELF_FETCH_FIELD (type_functions, ei_class,
> > +                                                      Sym, ent,
> > +                                                      st_name, Elf_Addr);
> >
> > this should be Elf_Word.  Please add a break; after you found a symbol.
> > Please also amend the comment before this loop to say that we know
> > there's a prevailing weak hidden symbol at the start of the .debug_info section
> > so we'll always at least find that one.
> >
> > -                        undefined and sharing the gnu_lto_ name.  */
> > +                        undefined and sharing a name of a prevailing
> > +                        symbol.  */
> >                       bind = STB_WEAK;
> >                       other = STV_HIDDEN;
> > +
> >                       ELF_SET_FIELD (type_functions, ei_class, Sym,
> > -                                    ent, st_name, Elf_Word,
> > -                                    gnu_lto - strings);
> > +                                    ent, st_name, Elf_Addr,
> > +                                    prevailing_name_idx);
> > +
> >
> > Likewise Elf_Word, no need to add vertical spacing before and after
> > this stmt.
> >
> >                       ELF_SET_FIELD (type_functions, ei_class, Sym,
>
> Thanks for review, all should be addresses in updated patch.

OK.

Richard.

> Martin
>
> >
> >
> >
> >
> >> Thanks,
> >> Martin
> >>
> >> libiberty/ChangeLog:
> >>
> >> 2019-08-27  Martin Liska  <mliska@suse.cz>
> >>
> >>         PR lto/91478
> >>         * simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
> >>         First find a WEAK HIDDEN symbol in symbol table that will be
> >>         preserved.  Later, use the symbol name for all removed symbols.
> >> ---
> >>  libiberty/simple-object-elf.c | 71 +++++++++++++++++++++++------------
> >>  1 file changed, 48 insertions(+), 23 deletions(-)
> >>
> >>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-27 12:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-27  9:09 [PATCH] Share a prevailing name for remove debug info symbols w/ LTO Martin Liška
2019-08-27 11:09 ` Richard Biener
2019-08-27 12:28   ` Martin Liška
2019-08-27 13:28     ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).