public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [RFC] Fix PR 16910: Relocate symbol correctly if it is wrapped
@ 2014-05-08  9:33 Yao Qi
  2014-05-09  4:05 ` Alan Modra
  0 siblings, 1 reply; 8+ messages in thread
From: Yao Qi @ 2014-05-08  9:33 UTC (permalink / raw)
  To: binutils

ld relocate symbol in .debug_info incorrectly if it is wrapped.
In the example I gave in PR 16910, the attribute of DIE for function
main is updated incorrectly, that DW_AT_low_pc is __wrap_main, which
is wrong.

In order to fix it, RELOC_FOR_GLOBAL_SYMBOL should take care.  If a
symbol SYM is from .debug_info section (and other debug sections?), and
the SYM is wrapped, linker should look for SYM or __real_SYM instead
of __wrap_SYM.  This is what this patch does.  It is hacky to me that
it checks whether the section name is ".debug_info".  What do you
think?

I configured binutils with --disable-gdb  --enable-targets=all
--enable-64-bit-bfd on x86_64-linux and run testsuite via 'make
check'.  Test results are unchanged in binutils.sum, gas.sum and
ld.sum.

bfd:

2014-05-08  Yao Qi  <yao@codesourcery.com>

	PR ld/16910
	* elf-bfd.h (RELOC_FOR_GLOBAL_SYMBOL): If the symbol is from a
	debug section and is wrapped, look for it instead of the wrapped
	one.
---
 bfd/elf-bfd.h | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 2c02135..aa43101 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -2429,7 +2429,28 @@ extern asection _bfd_elf_large_com_section;
       if (sym_hashes == NULL)						\
 	return FALSE;							\
 									\
-      h = sym_hashes[r_symndx - symtab_hdr->sh_info];			\
+      if (strcmp (input_section->name, ".debug_info") == 0)		\
+	{								\
+	  char *name1							\
+	    =  bfd_elf_string_from_elf_section (input_bfd,		\
+						symtab_hdr->sh_link,	\
+						symtab_hdr->sh_name);	\
+	  /* If the symbol SYM is wrapped, the attributes of debug	\
+	     information is about __real_SYM instead of __wrap_SYM.  */ \
+	  if (info->wrap_hash != NULL					\
+	      && bfd_hash_lookup (info->wrap_hash, name1, FALSE,	\
+				  FALSE) != NULL)			\
+	    {								\
+	      /* Look for SYM instead of __wrap_SYM.  */		\
+	      h = ((struct elf_link_hash_entry *)			\
+		   bfd_link_hash_lookup (info->hash, name1, FALSE,	\
+					 TRUE, FALSE));		\
+	    }								\
+	  else								\
+	    h = sym_hashes[r_symndx - symtab_hdr->sh_info];		\
+	}								\
+      else								\
+	h = sym_hashes[r_symndx - symtab_hdr->sh_info];		\
 									\
       while (h->root.type == bfd_link_hash_indirect			\
 	     || h->root.type == bfd_link_hash_warning)			\
-- 
1.9.0

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

* Re: [RFC] Fix PR 16910: Relocate symbol correctly if it is wrapped
  2014-05-08  9:33 [RFC] Fix PR 16910: Relocate symbol correctly if it is wrapped Yao Qi
@ 2014-05-09  4:05 ` Alan Modra
  2014-05-09  7:53   ` Yao Qi
  0 siblings, 1 reply; 8+ messages in thread
From: Alan Modra @ 2014-05-09  4:05 UTC (permalink / raw)
  To: Yao Qi; +Cc: binutils

On Thu, May 08, 2014 at 05:30:08PM +0800, Yao Qi wrote:
> --- a/bfd/elf-bfd.h
> +++ b/bfd/elf-bfd.h
> @@ -2429,7 +2429,28 @@ extern asection _bfd_elf_large_com_section;
>        if (sym_hashes == NULL)						\
>  	return FALSE;							\
>  									\
> -      h = sym_hashes[r_symndx - symtab_hdr->sh_info];			\
> +      if (strcmp (input_section->name, ".debug_info") == 0)		\
> +	{								\
> +	  char *name1							\
> +	    =  bfd_elf_string_from_elf_section (input_bfd,		\
> +						symtab_hdr->sh_link,	\
> +						symtab_hdr->sh_name);	\

The above function call is looking up the name of the .symtab section,
but using .strtab rather than the correct string table for section
names, .shstrtab.  I'm sure that's not what you intended, and it says
that this patch hasn't been tested very well, if at all..

I suspect that the right approach is

      h = sym_hashes[r_symndx - symtab_hdr->sh_info];
      if (info->wrap_hash != NULL
	  && (input_section->flags & SEC_DEBUGGING) != 0)
	{
	  retrieve name from h->root.root.string, strip off possible
	  prefix (see bfd_wrapped_link_hash_lookup)
	  if we now have a string starting with "__wrap_", look up
	  the remainder in wrap_hash, and if that matches, look up
	  the remainder in the main hash.
	}

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: [RFC] Fix PR 16910: Relocate symbol correctly if it is wrapped
  2014-05-09  4:05 ` Alan Modra
@ 2014-05-09  7:53   ` Yao Qi
  2014-05-19  8:11     ` Yao Qi
  2014-06-10  0:13     ` Qi, Yao
  0 siblings, 2 replies; 8+ messages in thread
From: Yao Qi @ 2014-05-09  7:53 UTC (permalink / raw)
  To: binutils; +Cc: amodra

On 05/09/2014 12:05 PM, Alan Modra wrote:
> The above function call is looking up the name of the .symtab section,
> but using .strtab rather than the correct string table for section
> names, .shstrtab.  I'm sure that's not what you intended, and it says

Ur, I must do something wrong in the cleanup and the this mistake isn't
found by running the example in PR 16910 on x86-linux and arm-linux.

> that this patch hasn't been tested very well, if at all..
> 
> I suspect that the right approach is
> 
>       h = sym_hashes[r_symndx - symtab_hdr->sh_info];
>       if (info->wrap_hash != NULL
> 	  && (input_section->flags & SEC_DEBUGGING) != 0)
> 	{
> 	  retrieve name from h->root.root.string, strip off possible
> 	  prefix (see bfd_wrapped_link_hash_lookup)
> 	  if we now have a string starting with "__wrap_", look up
> 	  the remainder in wrap_hash, and if that matches, look up
> 	  the remainder in the main hash.
> 	}

Patch below is updated per your advice here.  I configured binutils as
"--disable-gdb  --enable-targets=all --enable-64-bit-bfd" on
x86_64-linux and run 'make check'.  There is no change in binutils.sum,
gas.sum and ld.sum.  Let me know if testing in other ways is needed.

-- 
Yao (齐尧)

bfd:

2014-05-09  Yao Qi  <yao@codesourcery.com>

	PR ld/16910
	* elf-bfd.h (RELOC_FOR_GLOBAL_SYMBOL): If the symbol is from a
	debug section and is wrapped, look for it instead of the wrapped
	one.
---
 bfd/elf-bfd.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 2c02135..791ece9 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -2431,6 +2431,33 @@ extern asection _bfd_elf_large_com_section;
 									\
       h = sym_hashes[r_symndx - symtab_hdr->sh_info];			\
 									\
+      if (info->wrap_hash != NULL					\
+	  && (input_section->flags & SEC_DEBUGGING) != 0)		\
+	{								\
+	  const char *l;						\
+									\
+	  l = h->root.root.string;					\
+	  if (*l == bfd_get_symbol_leading_char (input_bfd)		\
+	      || *l == info->wrap_char)				\
+	    ++l; /* Strip off possible prefix.  */			\
+									\
+	  if (CONST_STRNEQ (l, "__wrap_")				\
+	      && bfd_hash_lookup (info->wrap_hash,			\
+				  l + sizeof "__wrap_" - 1, FALSE,	\
+				  FALSE) != NULL)			\
+	    {								\
+	      /* If the string L starts with "__wrap_" and the		\
+		 remainder is found in wrap_hash, the symbol is	\
+		 wrapped.  The attributes of debugging information	\
+		 are about the original symbol instead of the wrapped	\
+		 one.  Look up the remainder in the main hash.  */	\
+	      h = ((struct elf_link_hash_entry *)			\
+		   bfd_link_hash_lookup (info->hash,			\
+					 l + sizeof "__wrap_" - 1,	\
+					 FALSE, TRUE, FALSE));		\
+	    }								\
+	}								\
+									\
       while (h->root.type == bfd_link_hash_indirect			\
 	     || h->root.type == bfd_link_hash_warning)			\
 	h = (struct elf_link_hash_entry *) h->root.u.i.link;		\
-- 
1.9.0

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

* Re: [RFC] Fix PR 16910: Relocate symbol correctly if it is wrapped
  2014-05-09  7:53   ` Yao Qi
@ 2014-05-19  8:11     ` Yao Qi
  2014-06-10  0:13     ` Qi, Yao
  1 sibling, 0 replies; 8+ messages in thread
From: Yao Qi @ 2014-05-19  8:11 UTC (permalink / raw)
  To: binutils; +Cc: amodra

On 05/09/2014 03:50 PM, Yao Qi wrote:
> Patch below is updated per your advice here.  I configured binutils as
> "--disable-gdb  --enable-targets=all --enable-64-bit-bfd" on
> x86_64-linux and run 'make check'.  There is no change in binutils.sum,
> gas.sum and ld.sum.  Let me know if testing in other ways is needed.
> 
> bfd:
>
> 2014-05-09  Yao Qi  <yao@codesourcery.com>
>
> 	PR ld/16910
> 	* elf-bfd.h (RELOC_FOR_GLOBAL_SYMBOL): If the symbol is from a
> 	debug section and is wrapped, look for it instead of the wrapped
> 	one.

Ping.  https://sourceware.org/ml/binutils/2014-05/msg00087.html

-- 
Yao (齐尧)

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

* Re: [RFC] Fix PR 16910: Relocate symbol correctly if it is wrapped
  2014-05-09  7:53   ` Yao Qi
  2014-05-19  8:11     ` Yao Qi
@ 2014-06-10  0:13     ` Qi, Yao
  2014-06-10 13:36       ` Alan Modra
  1 sibling, 1 reply; 8+ messages in thread
From: Qi, Yao @ 2014-06-10  0:13 UTC (permalink / raw)
  To: binutils; +Cc: amodra

On 05/09/2014 03:50 PM, Yao Qi wrote:
> Patch below is updated per your advice here.  I configured binutils as
> "--disable-gdb  --enable-targets=all --enable-64-bit-bfd" on
> x86_64-linux and run 'make check'.  There is no change in binutils.sum,
> gas.sum and ld.sum.  Let me know if testing in other ways is needed.

> bfd:
> 
> 2014-05-09  Yao Qi  <yao@codesourcery.com>
> 
> 	PR ld/16910
> 	* elf-bfd.h (RELOC_FOR_GLOBAL_SYMBOL): If the symbol is from a
> 	debug section and is wrapped, look for it instead of the wrapped
> 	one.
> ---
>  bfd/elf-bfd.h | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
> 
> diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
> index 2c02135..791ece9 100644
> --- a/bfd/elf-bfd.h
> +++ b/bfd/elf-bfd.h
> @@ -2431,6 +2431,33 @@ extern asection _bfd_elf_large_com_section;
>  									\
>        h = sym_hashes[r_symndx - symtab_hdr->sh_info];			\
>  									\
> +      if (info->wrap_hash != NULL					\
> +	  && (input_section->flags & SEC_DEBUGGING) != 0)		\
> +	{								\
> +	  const char *l;						\
> +									\
> +	  l = h->root.root.string;					\
> +	  if (*l == bfd_get_symbol_leading_char (input_bfd)		\
> +	      || *l == info->wrap_char)				\
> +	    ++l; /* Strip off possible prefix.  */			\
> +									\
> +	  if (CONST_STRNEQ (l, "__wrap_")				\
> +	      && bfd_hash_lookup (info->wrap_hash,			\
> +				  l + sizeof "__wrap_" - 1, FALSE,	\
> +				  FALSE) != NULL)			\
> +	    {								\
> +	      /* If the string L starts with "__wrap_" and the		\
> +		 remainder is found in wrap_hash, the symbol is	\
> +		 wrapped.  The attributes of debugging information	\
> +		 are about the original symbol instead of the wrapped	\
> +		 one.  Look up the remainder in the main hash.  */	\
> +	      h = ((struct elf_link_hash_entry *)			\
> +		   bfd_link_hash_lookup (info->hash,			\
> +					 l + sizeof "__wrap_" - 1,	\
> +					 FALSE, TRUE, FALSE));		\
> +	    }								\
> +	}								\
> +									\
>        while (h->root.type == bfd_link_hash_indirect			\
>  	     || h->root.type == bfd_link_hash_warning)			\
>  	h = (struct elf_link_hash_entry *) h->root.u.i.link;		\

Ping.  Could you take a look at this patch?

-- 
Yao Qi

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

* Re: [RFC] Fix PR 16910: Relocate symbol correctly if it is wrapped
  2014-06-10  0:13     ` Qi, Yao
@ 2014-06-10 13:36       ` Alan Modra
  2014-06-11  6:59         ` Yao Qi
  0 siblings, 1 reply; 8+ messages in thread
From: Alan Modra @ 2014-06-10 13:36 UTC (permalink / raw)
  To: Qi, Yao; +Cc: binutils

On Tue, Jun 10, 2014 at 08:11:15AM +0800, Qi, Yao wrote:
> On 05/09/2014 03:50 PM, Yao Qi wrote:
> > Patch below is updated per your advice here.  I configured binutils as
> 
> Ping.  Could you take a look at this patch?

Sorry for the appallingly slow response.  This is what I committed:

Fixes issues with dwz multi-file (-m) and ld's -wrap option.
Symbols referenced from DWARF debug info in a separate file, eg. to
specify low and high pc, must use the real symbol.  The DWARF info
is specifying attributes of the real function, not one interposed
with --wrap.
    
include/
	* bfdlink.h (unwrap_hash_lookup): Declare.
bfd/
	* linker.c (unwrap_hash_lookup): New function.
	* elf-bfd (RELOC_FOR_GLOBAL_SYMBOL): Call unwrap_hash_lookup.
	* elf32-i370.c (i370_elf_relocate_section): Likewise.
	* elf32-m32c.c (m32c_elf_relocate_section): Likewise.
	* elf32-m32r.c (m32r_elf_relocate_section): Likewise.
	* elf32-score.c (s3_bfd_score_elf_relocate_section): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_relocate_section): Likewise.
	* elf32-spu.c (spu_elf_relocate_section): Likewise.
	* elf64-hppa.c (elf64_hppa_relocate_section): Likewise.

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 2c02135..1bbe771 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -2431,6 +2431,11 @@ extern asection _bfd_elf_large_com_section;
 									\
       h = sym_hashes[r_symndx - symtab_hdr->sh_info];			\
 									\
+      if (info->wrap_hash != NULL					\
+	  && (input_section->flags & SEC_DEBUGGING) != 0)		\
+	h = ((struct elf_link_hash_entry *)				\
+	     unwrap_hash_lookup (info, input_bfd, &h->root));		\
+									\
       while (h->root.type == bfd_link_hash_indirect			\
 	     || h->root.type == bfd_link_hash_warning)			\
 	h = (struct elf_link_hash_entry *) h->root.u.i.link;		\
diff --git a/bfd/elf32-i370.c b/bfd/elf32-i370.c
index 0508aeb..c9ed6e0 100644
--- a/bfd/elf32-i370.c
+++ b/bfd/elf32-i370.c
@@ -1090,6 +1090,12 @@ i370_elf_relocate_section (bfd *output_bfd,
       else
 	{
 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+
+	  if (info->wrap_hash != NULL
+	      && (input_section->flags & SEC_DEBUGGING) != 0)
+	    h = ((struct elf_link_hash_entry *)
+		 unwrap_hash_lookup (info, input_bfd, &h->root));
+
 	  while (h->root.type == bfd_link_hash_indirect
 		 || h->root.type == bfd_link_hash_warning)
 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
diff --git a/bfd/elf32-m32c.c b/bfd/elf32-m32c.c
index 82152dc..ed7df9a 100644
--- a/bfd/elf32-m32c.c
+++ b/bfd/elf32-m32c.c
@@ -408,6 +408,11 @@ m32c_elf_relocate_section
 	{
 	  h = sym_hashes [r_symndx - symtab_hdr->sh_info];
 
+	  if (info->wrap_hash != NULL
+	      && (input_section->flags & SEC_DEBUGGING) != 0)
+	    h = ((struct elf_link_hash_entry *)
+		 unwrap_hash_lookup (info, input_bfd, &h->root));
+
 	  while (h->root.type == bfd_link_hash_indirect
 		 || h->root.type == bfd_link_hash_warning)
 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c
index 0adeb97..9c59c02 100644
--- a/bfd/elf32-m32r.c
+++ b/bfd/elf32-m32r.c
@@ -2490,6 +2490,12 @@ m32r_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
 	  relocation = 0;
 
 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+
+	  if (info->wrap_hash != NULL
+	      && (input_section->flags & SEC_DEBUGGING) != 0)
+	    h = ((struct elf_link_hash_entry *)
+		 unwrap_hash_lookup (info, input_bfd, &h->root));
+
 	  while (h->root.type == bfd_link_hash_indirect
 		 || h->root.type == bfd_link_hash_warning)
 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
diff --git a/bfd/elf32-score.c b/bfd/elf32-score.c
index 677f000..3223d46 100644
--- a/bfd/elf32-score.c
+++ b/bfd/elf32-score.c
@@ -2604,6 +2604,12 @@ s3_bfd_score_elf_relocate_section (bfd *output_bfd,
           /* For global symbols we look up the symbol in the hash-table.  */
           h = ((struct score_elf_link_hash_entry *)
                elf_sym_hashes (input_bfd) [r_symndx - extsymoff]);
+
+	  if (info->wrap_hash != NULL
+	      && (input_section->flags & SEC_DEBUGGING) != 0)
+	    h = ((struct score_elf_link_hash_entry *)
+		 unwrap_hash_lookup (info, input_bfd, &h->root.root));
+
           /* Find the real hash-table entry for this symbol.  */
           while (h->root.root.type == bfd_link_hash_indirect
                  || h->root.root.type == bfd_link_hash_warning)
diff --git a/bfd/elf32-score7.c b/bfd/elf32-score7.c
index 06ded9a..c241077 100644
--- a/bfd/elf32-score7.c
+++ b/bfd/elf32-score7.c
@@ -2376,6 +2376,12 @@ s7_bfd_score_elf_relocate_section (bfd *output_bfd,
           /* For global symbols we look up the symbol in the hash-table.  */
           h = ((struct score_elf_link_hash_entry *)
                elf_sym_hashes (input_bfd) [r_symndx - extsymoff]);
+
+	  if (info->wrap_hash != NULL
+	      && (input_section->flags & SEC_DEBUGGING) != 0)
+	    h = ((struct score_elf_link_hash_entry *)
+		  unwrap_hash_lookup (info, input_bfd, &h->root.root));
+
           /* Find the real hash-table entry for this symbol.  */
           while (h->root.root.type == bfd_link_hash_indirect
                  || h->root.root.type == bfd_link_hash_warning)
diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c
index d111277..ac9c184 100644
--- a/bfd/elf32-spu.c
+++ b/bfd/elf32-spu.c
@@ -4850,6 +4850,11 @@ spu_elf_relocate_section (bfd *output_bfd,
 
 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
 
+	  if (info->wrap_hash != NULL
+	      && (input_section->flags & SEC_DEBUGGING) != 0)
+	    h = ((struct elf_link_hash_entry *)
+		 unwrap_hash_lookup (info, input_bfd, &h->root));
+
 	  while (h->root.type == bfd_link_hash_indirect
 		 || h->root.type == bfd_link_hash_warning)
 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c
index 49473e7..b57497d 100644
--- a/bfd/elf64-hppa.c
+++ b/bfd/elf64-hppa.c
@@ -3868,6 +3868,11 @@ elf64_hppa_relocate_section (bfd *output_bfd,
 
 	  eh = sym_hashes[r_symndx - symtab_hdr->sh_info];
 
+	  if (info->wrap_hash != NULL
+	      && (input_section->flags & SEC_DEBUGGING) != 0)
+	    eh = ((struct elf_link_hash_entry *)
+		  unwrap_hash_lookup (info, input_bfd, &eh->root));
+
 	  while (eh->root.type == bfd_link_hash_indirect
 		 || eh->root.type == bfd_link_hash_warning)
 	    eh = (struct elf_link_hash_entry *) eh->root.u.i.link;
diff --git a/bfd/linker.c b/bfd/linker.c
index a20a276..d00238c 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -566,8 +566,6 @@ bfd_wrapped_link_hash_lookup (bfd *abfd,
 	  return h;
 	}
 
-#undef WRAP
-
 #undef  REAL
 #define REAL "__real_"
 
@@ -602,6 +600,42 @@ bfd_wrapped_link_hash_lookup (bfd *abfd,
   return bfd_link_hash_lookup (info->hash, string, create, copy, follow);
 }
 
+/* If H is a wrapped symbol, ie. the symbol name starts with "__wrap_"
+   and the remainder is found in wrap_hash, return the real symbol.  */
+
+struct bfd_link_hash_entry *
+unwrap_hash_lookup (struct bfd_link_info *info,
+		    bfd *input_bfd,
+		    struct bfd_link_hash_entry *h)
+{
+  const char *l = h->root.string;
+
+  if (*l == bfd_get_symbol_leading_char (input_bfd)
+      || *l == info->wrap_char)
+    ++l;
+
+  if (CONST_STRNEQ (l, WRAP))
+    {
+      l += sizeof WRAP - 1;
+
+      if (bfd_hash_lookup (info->wrap_hash, l, FALSE, FALSE) != NULL)
+	{
+	  char save = 0;
+	  if (l - sizeof WRAP - 1 != h->root.string)
+	    {
+	      --l;
+	      save = *l;
+	      *(char *) l = *h->root.string;
+	    }
+	  h = bfd_link_hash_lookup (info->hash, l, FALSE, FALSE, FALSE);
+	  if (save)
+	    *(char *) l = save;
+	}
+    }
+  return h;
+}
+#undef WRAP
+
 /* Traverse a generic link hash table.  Differs from bfd_hash_traverse
    in the treatment of warning symbols.  When warning symbols are
    created they replace the real symbol, so you don't get to see the
diff --git a/include/bfdlink.h b/include/bfdlink.h
index 9f1b50b..509d626 100644
--- a/include/bfdlink.h
+++ b/include/bfdlink.h
@@ -186,6 +186,12 @@ extern struct bfd_link_hash_entry *bfd_wrapped_link_hash_lookup
   (bfd *, struct bfd_link_info *, const char *, bfd_boolean,
    bfd_boolean, bfd_boolean);
 
+/* If H is a wrapped symbol, ie. the symbol name starts with "__wrap_"
+   and the remainder is found in wrap_hash, return the real symbol.  */
+
+extern struct bfd_link_hash_entry *unwrap_hash_lookup
+  (struct bfd_link_info *, bfd *, struct bfd_link_hash_entry *);
+
 /* Traverse a link hash table.  */
 extern void bfd_link_hash_traverse
   (struct bfd_link_hash_table *,


-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: [RFC] Fix PR 16910: Relocate symbol correctly if it is wrapped
  2014-06-10 13:36       ` Alan Modra
@ 2014-06-11  6:59         ` Yao Qi
  2014-06-11 10:02           ` Alan Modra
  0 siblings, 1 reply; 8+ messages in thread
From: Yao Qi @ 2014-06-11  6:59 UTC (permalink / raw)
  To: binutils; +Cc: amodra

Alan,
Thanks for your patch.  A question below,

On 06/10/2014 09:36 PM, Alan Modra wrote:
> +  if (*l == bfd_get_symbol_leading_char (input_bfd)
> +      || *l == info->wrap_char)
> +    ++l;  <-------- [1]

> +
> +  if (CONST_STRNEQ (l, WRAP))
> +    {
> +      l += sizeof WRAP - 1;
> +
> +      if (bfd_hash_lookup (info->wrap_hash, l, FALSE, FALSE) != NULL)
> +	{
> +	  char save = 0;
> +	  if (l - sizeof WRAP - 1 != h->root.string)

This is always true, because 'l' is incremented by either
'sizeof WRAP - 1' or 'sizeof WRAP'.  This causes 'l' set incorrectly,
and 'h' is NULL afterwards.  It causes a segmentation
fault in the caller of this function.

What you meant probably is "l - sizeof WRAP + 1 != h->root.string",
in order to check whether 'l' is incremented in [1] or not.

-- 
Yao (齐尧)

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

* Re: [RFC] Fix PR 16910: Relocate symbol correctly if it is wrapped
  2014-06-11  6:59         ` Yao Qi
@ 2014-06-11 10:02           ` Alan Modra
  0 siblings, 0 replies; 8+ messages in thread
From: Alan Modra @ 2014-06-11 10:02 UTC (permalink / raw)
  To: Yao Qi; +Cc: binutils

On Wed, Jun 11, 2014 at 02:57:11PM +0800, Yao Qi wrote:
> What you meant probably is "l - sizeof WRAP + 1 != h->root.string",
> in order to check whether 'l' is incremented in [1] or not.

Oops, yes.  Caught out by last minute changes.

	* linker.c (unwrap_hash_lookup): Add missing parens.

diff --git a/bfd/linker.c b/bfd/linker.c
index d00238c..2e21054 100644
--- a/bfd/linker.c
+++ b/bfd/linker.c
@@ -621,7 +621,7 @@ unwrap_hash_lookup (struct bfd_link_info *info,
       if (bfd_hash_lookup (info->wrap_hash, l, FALSE, FALSE) != NULL)
 	{
 	  char save = 0;
-	  if (l - sizeof WRAP - 1 != h->root.string)
+	  if (l - (sizeof WRAP - 1) != h->root.string)
 	    {
 	      --l;
 	      save = *l;

-- 
Alan Modra
Australia Development Lab, IBM

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

end of thread, other threads:[~2014-06-11 10:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-08  9:33 [RFC] Fix PR 16910: Relocate symbol correctly if it is wrapped Yao Qi
2014-05-09  4:05 ` Alan Modra
2014-05-09  7:53   ` Yao Qi
2014-05-19  8:11     ` Yao Qi
2014-06-10  0:13     ` Qi, Yao
2014-06-10 13:36       ` Alan Modra
2014-06-11  6:59         ` Yao Qi
2014-06-11 10:02           ` Alan Modra

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).