public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Committed: fix PR ld/20125, MMIX weak symbols
@ 2017-08-21  2:25 Hans-Peter Nilsson
  2017-09-14  3:11 ` Hans-Peter Nilsson
  0 siblings, 1 reply; 2+ messages in thread
From: Hans-Peter Nilsson @ 2017-08-21  2:25 UTC (permalink / raw)
  To: binutils

Reloc-management for weak undefined symbols with PUSHJ relocs (jump
stubs for an out-of-range call operand) "lost" the reloc, causing
internal inconsistencies and an abort.  Fixed thusly, finally.

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 79dfa1d..6badc5d 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2017-08-21  Hans-Peter Nilsson  <hp@bitrange.com>
+
+	PR ld/20125
+	* elf64-mmix.c (mmix_elf_relax_section): Correct handling of
+	undefined weak symbols.
+
 2017-08-18  Nick Clifton  <nickc@redhat.com>

 	PR binutils/21962
diff --git a/bfd/elf64-mmix.c b/bfd/elf64-mmix.c
index 8c8e06d..8d79d39 100644
--- a/bfd/elf64-mmix.c
+++ b/bfd/elf64-mmix.c
@@ -2710,8 +2710,21 @@ mmix_elf_relax_section (bfd *abfd,
 	  indx = ELF64_R_SYM (irel->r_info) - symtab_hdr->sh_info;
 	  h = elf_sym_hashes (abfd)[indx];
 	  BFD_ASSERT (h != NULL);
-	  if (h->root.type != bfd_link_hash_defined
-	      && h->root.type != bfd_link_hash_defweak)
+	  if (h->root.type == bfd_link_hash_undefweak)
+	    /* FIXME: for R_MMIX_PUSHJ_STUBBABLE, there are alternatives to
+	       the canonical value 0 for an unresolved weak symbol to
+	       consider: as the debug-friendly approach, resolve to "abort"
+	       (or a port-specific function), or as the space-friendly
+	       approach resolve to the next instruction (like some other
+	       ports, notably ARM and AArch64).  These alternatives require
+	       matching code in mmix_elf_perform_relocation or its caller.  */
+	    symval = 0;
+	  else if (h->root.type == bfd_link_hash_defined
+		   || h->root.type == bfd_link_hash_defweak)
+	    symval = (h->root.u.def.value
+		      + h->root.u.def.section->output_section->vma
+		      + h->root.u.def.section->output_offset);
+	  else
 	    {
 	      /* This appears to be a reference to an undefined symbol.  Just
 		 ignore it--it will be caught by the regular reloc processing.
@@ -2725,10 +2738,6 @@ mmix_elf_relax_section (bfd *abfd,
 		}
 	      continue;
 	    }
-
-	  symval = (h->root.u.def.value
-		    + h->root.u.def.section->output_section->vma
-		    + h->root.u.def.section->output_offset);
 	}

       if (ELF64_R_TYPE (irel->r_info) == (int) R_MMIX_PUSHJ_STUBBABLE)
@@ -2866,6 +2875,8 @@ mmix_elf_relax_section (bfd *abfd,
 	}
     }

+  BFD_ASSERT(pjsno == mmix_elf_section_data (sec)->pjs.n_pushj_relocs);
+
   if (internal_relocs != NULL
       && elf_section_data (sec)->relocs != internal_relocs)
     free (internal_relocs);
diff --git a/ld/ChangeLog b/ld/ChangeLog
index ba576c2..a150256 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,9 @@
+2017-08-21  Hans-Peter Nilsson  <hp@bitrange.com>
+
+	PR ld/20125
+	* testsuite/ld-mmix/pr20125.d, testsuite/ld-mmix/pr20125.s: New
+	test.
+
 2017-08-20  A. Wilcox  <awilfox@adelielinux.org>

 	PR ld/21976
diff --git a/ld/testsuite/ld-mmix/pr20125.d b/ld/testsuite/ld-mmix/pr20125.d
new file mode 100644
index 0000000..7c09c04
--- /dev/null
+++ b/ld/testsuite/ld-mmix/pr20125.d
@@ -0,0 +1,21 @@
+#as: -no-predefined-syms -x -I$srcdir/$subdir
+#ld: -m mmo --defsym __.MMIX.start..text=0x80000
+#objdump: -dr
+
+# PUSHJ reloc handling was wrong for weak undefined symbols, causing
+# internal inconsistencies, leading to a call to abort.
+# Note that we don't keep track of which symbols have pushj-stubs, so
+# we get one stub each for the two calls to "foo".
+
+.*:     file format mmo
+
+Disassembly of section \.text:
+
+0+80000 <(_start|Main)>:
+   80000:	fe000004 	get \$0,rJ
+   80004:	f2010004 	pushj \$1,80014 <Main\+0x14>
+   80008:	f2010004 	pushj \$1,80018 <Main\+0x18>
+   8000c:	f6040000 	put rJ,\$0
+   80010:	f8010000 	pop 1,0
+   80014:	f1fdfffb 	jmp 0 <Main-0x80000>
+   80018:	f1fdfffa 	jmp 0 <Main-0x80000>
diff --git a/ld/testsuite/ld-mmix/pr20125.s b/ld/testsuite/ld-mmix/pr20125.s
new file mode 100644
index 0000000..e528d9d
--- /dev/null
+++ b/ld/testsuite/ld-mmix/pr20125.s
@@ -0,0 +1,2 @@
+	.weak bar
+	.include "pr12815-2.s"

brgds, H-P

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

* Re: Committed: fix PR ld/20125, MMIX weak symbols
  2017-08-21  2:25 Committed: fix PR ld/20125, MMIX weak symbols Hans-Peter Nilsson
@ 2017-09-14  3:11 ` Hans-Peter Nilsson
  0 siblings, 0 replies; 2+ messages in thread
From: Hans-Peter Nilsson @ 2017-09-14  3:11 UTC (permalink / raw)
  To: binutils

Now also imported onto the 2.29 branch.  I found that 0a79bef4
was a prerequisite to build, so imported and pushed too.
binutils:
 * dwarf.c (display_debug_names): Initialize hash_prev.

On Sun, 20 Aug 2017, Hans-Peter Nilsson wrote:
> Reloc-management for weak undefined symbols with PUSHJ relocs (jump
> stubs for an out-of-range call operand) "lost" the reloc, causing
> internal inconsistencies and an abort.  Fixed thusly, finally.
>
> diff --git a/bfd/ChangeLog b/bfd/ChangeLog
> index 79dfa1d..6badc5d 100644
> --- a/bfd/ChangeLog
> +++ b/bfd/ChangeLog
> @@ -1,3 +1,9 @@
> +2017-08-21  Hans-Peter Nilsson  <hp@bitrange.com>
> +
> +	PR ld/20125
> +	* elf64-mmix.c (mmix_elf_relax_section): Correct handling of
> +	undefined weak symbols.
> +
>  2017-08-18  Nick Clifton  <nickc@redhat.com>
>
>  	PR binutils/21962
> diff --git a/bfd/elf64-mmix.c b/bfd/elf64-mmix.c
> index 8c8e06d..8d79d39 100644
> --- a/bfd/elf64-mmix.c
> +++ b/bfd/elf64-mmix.c
> @@ -2710,8 +2710,21 @@ mmix_elf_relax_section (bfd *abfd,
>  	  indx = ELF64_R_SYM (irel->r_info) - symtab_hdr->sh_info;
>  	  h = elf_sym_hashes (abfd)[indx];
>  	  BFD_ASSERT (h != NULL);
> -	  if (h->root.type != bfd_link_hash_defined
> -	      && h->root.type != bfd_link_hash_defweak)
> +	  if (h->root.type == bfd_link_hash_undefweak)
> +	    /* FIXME: for R_MMIX_PUSHJ_STUBBABLE, there are alternatives to
> +	       the canonical value 0 for an unresolved weak symbol to
> +	       consider: as the debug-friendly approach, resolve to "abort"
> +	       (or a port-specific function), or as the space-friendly
> +	       approach resolve to the next instruction (like some other
> +	       ports, notably ARM and AArch64).  These alternatives require
> +	       matching code in mmix_elf_perform_relocation or its caller.  */
> +	    symval = 0;
> +	  else if (h->root.type == bfd_link_hash_defined
> +		   || h->root.type == bfd_link_hash_defweak)
> +	    symval = (h->root.u.def.value
> +		      + h->root.u.def.section->output_section->vma
> +		      + h->root.u.def.section->output_offset);
> +	  else
>  	    {
>  	      /* This appears to be a reference to an undefined symbol.  Just
>  		 ignore it--it will be caught by the regular reloc processing.
> @@ -2725,10 +2738,6 @@ mmix_elf_relax_section (bfd *abfd,
>  		}
>  	      continue;
>  	    }
> -
> -	  symval = (h->root.u.def.value
> -		    + h->root.u.def.section->output_section->vma
> -		    + h->root.u.def.section->output_offset);
>  	}
>
>        if (ELF64_R_TYPE (irel->r_info) == (int) R_MMIX_PUSHJ_STUBBABLE)
> @@ -2866,6 +2875,8 @@ mmix_elf_relax_section (bfd *abfd,
>  	}
>      }
>
> +  BFD_ASSERT(pjsno == mmix_elf_section_data (sec)->pjs.n_pushj_relocs);
> +
>    if (internal_relocs != NULL
>        && elf_section_data (sec)->relocs != internal_relocs)
>      free (internal_relocs);
> diff --git a/ld/ChangeLog b/ld/ChangeLog
> index ba576c2..a150256 100644
> --- a/ld/ChangeLog
> +++ b/ld/ChangeLog
> @@ -1,3 +1,9 @@
> +2017-08-21  Hans-Peter Nilsson  <hp@bitrange.com>
> +
> +	PR ld/20125
> +	* testsuite/ld-mmix/pr20125.d, testsuite/ld-mmix/pr20125.s: New
> +	test.
> +
>  2017-08-20  A. Wilcox  <awilfox@adelielinux.org>
>
>  	PR ld/21976
> diff --git a/ld/testsuite/ld-mmix/pr20125.d b/ld/testsuite/ld-mmix/pr20125.d
> new file mode 100644
> index 0000000..7c09c04
> --- /dev/null
> +++ b/ld/testsuite/ld-mmix/pr20125.d
> @@ -0,0 +1,21 @@
> +#as: -no-predefined-syms -x -I$srcdir/$subdir
> +#ld: -m mmo --defsym __.MMIX.start..text=0x80000
> +#objdump: -dr
> +
> +# PUSHJ reloc handling was wrong for weak undefined symbols, causing
> +# internal inconsistencies, leading to a call to abort.
> +# Note that we don't keep track of which symbols have pushj-stubs, so
> +# we get one stub each for the two calls to "foo".
> +
> +.*:     file format mmo
> +
> +Disassembly of section \.text:
> +
> +0+80000 <(_start|Main)>:
> +   80000:	fe000004 	get \$0,rJ
> +   80004:	f2010004 	pushj \$1,80014 <Main\+0x14>
> +   80008:	f2010004 	pushj \$1,80018 <Main\+0x18>
> +   8000c:	f6040000 	put rJ,\$0
> +   80010:	f8010000 	pop 1,0
> +   80014:	f1fdfffb 	jmp 0 <Main-0x80000>
> +   80018:	f1fdfffa 	jmp 0 <Main-0x80000>
> diff --git a/ld/testsuite/ld-mmix/pr20125.s b/ld/testsuite/ld-mmix/pr20125.s
> new file mode 100644
> index 0000000..e528d9d
> --- /dev/null
> +++ b/ld/testsuite/ld-mmix/pr20125.s
> @@ -0,0 +1,2 @@
> +	.weak bar
> +	.include "pr12815-2.s"
>
> brgds, H-P
>

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

end of thread, other threads:[~2017-09-14  3:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-21  2:25 Committed: fix PR ld/20125, MMIX weak symbols Hans-Peter Nilsson
2017-09-14  3:11 ` Hans-Peter Nilsson

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