public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* testsuite results with MALLOC_PERTURB_=1
@ 2014-06-14  0:48 Alan Modra
  2014-06-16  3:37 ` Fix uninitialised CRIS insn Alan Modra
                   ` (8 more replies)
  0 siblings, 9 replies; 16+ messages in thread
From: Alan Modra @ 2014-06-14  0:48 UTC (permalink / raw)
  To: binutils

These extra fails show up..  So far I've only looked at the x86 ones,
which are due to write_object_file() not being called after errors.
If write_object_file() isn't called, fixups aren't applied, so frags
have parts that are uninitialized.

arm-vxworks  +FAIL: PIC
cris-elf  +FAIL: gas/cris/rd-bkw4v32
i386-darwin  +FAIL: i386 mpx-inval-1
i386-darwin  +FAIL: i386 x86-64-mpx-inval-1
i386-linuxaout  +FAIL: i386 mpx-inval-1
i386-lynxos  +FAIL: i386 mpx-inval-1
i386-netware  +FAIL: i386 mpx-inval-1
i586-aout  +FAIL: i386 mpx-inval-1
i586-coff  +FAIL: i386 mpx-inval-1
i586-linux  +FAIL: i386 mpx-inval-1
i586-linux  +FAIL: i386 inval-equ-1
i586-linux  +FAIL: i386 x86-64-mpx-inval-1
i686-nacl  +FAIL: i386 mpx-inval-1
i686-nacl  +FAIL: i386 inval-equ-1
i686-nacl  +FAIL: i386 x86-64-mpx-inval-1
i686-pc-beos  +FAIL: i386 mpx-inval-1
i686-pc-elf  +FAIL: i386 mpx-inval-1
i686-pc-elf  +FAIL: i386 inval-equ-1
i686-pe  +FAIL: i386 mpx-inval-1
tic54x-coff  +FAIL: c54x macros
tic6x-elf  +FAIL: C6X unwinding directives 1 (little endian)
tic6x-elf  +FAIL: C6X unwinding directives 2 (big endian)
tic6x-elf  +FAIL: C6X unwinding directives 3 (segment change)
tic6x-elf  +FAIL: ld-tic6x/unwind-1
tic6x-elf  +FAIL: ld-tic6x/unwind-2
tic6x-elf  +FAIL: ld-tic6x/unwind-3
tic6x-elf  +FAIL: ld-tic6x/unwind-4
tic6x-elf  +FAIL: ld-tic6x/unwind-6
vax-netbsdelf  +FAIL: VAX ELF relocations
vax-netbsdelf  +FAIL: GOT test (executable)
vax-netbsdelf  +FAIL: GOT test (shared library)
vax-netbsdelf  +FAIL: VAX export class call relocation test
vax-netbsdelf  +FAIL: VAX export class data relocation test
x86_64-linux  +FAIL: i386 mpx-inval-1
x86_64-linux  +FAIL: i386 inval-equ-1
x86_64-linux  +FAIL: i386 x86-64-mpx-inval-1
x86_64-mingw32  +FAIL: i386 mpx-inval-1
x86_64-mingw32  +FAIL: i386 x86-64-mpx-inval-1
x86_64-nacl  +FAIL: i386 mpx-inval-1
x86_64-nacl  +FAIL: i386 inval-equ-1
x86_64-nacl  +FAIL: i386 x86-64-mpx-inval-1

-- 
Alan Modra
Australia Development Lab, IBM

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

* Fix uninitialised CRIS insn
  2014-06-14  0:48 testsuite results with MALLOC_PERTURB_=1 Alan Modra
@ 2014-06-16  3:37 ` Alan Modra
  2014-06-16  5:12   ` Hans-Peter Nilsson
  2014-06-16  3:39 ` Fix uninitialised ARM data Alan Modra
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Alan Modra @ 2014-06-16  3:37 UTC (permalink / raw)
  To: binutils

Fixes "FAIL: gas/cris/rd-bkw4v32" with MALLOC_PERTURB_=1

gas/
	* config/tc-cris.c (md_create_long_jump): Follow "short" jump
	with a nop rather than leaving uninitialised.
gas/testsuite/
	* gas/cris/rd-bkw4v32.d: Update.

diff --git a/gas/config/tc-cris.c b/gas/config/tc-cris.c
index 86d8062..aba4ef7 100644
--- a/gas/config/tc-cris.c
+++ b/gas/config/tc-cris.c
@@ -1124,9 +1124,15 @@ md_create_long_jump (char *storep, addressT from_addr, addressT to_addr,
 
   if (max_short_minus_distance <= distance
       && distance <= max_short_plus_distance)
-    /* Then make it a "short" long jump.  */
-    md_create_short_jump (storep, from_addr, to_addr, fragP,
+    {
+      /* Then make it a "short" long jump.  */
+      md_create_short_jump (storep, from_addr, to_addr, fragP,
 			    to_symbol);
+      if (cris_arch == arch_crisv32)
+	md_number_to_chars (storep + 6, NOP_OPCODE_V32, 2);
+      else
+	md_number_to_chars (storep + 6, NOP_OPCODE, 2);
+    }
   else
     {
       /* We have a "long" long jump: "JUMP [PC+]".  If CRISv32, always
diff --git a/gas/testsuite/gas/cris/rd-bkw4v32.d b/gas/testsuite/gas/cris/rd-bkw4v32.d
index 210746c..35fa5b2 100644
--- a/gas/testsuite/gas/cris/rd-bkw4v32.d
+++ b/gas/testsuite/gas/cris/rd-bkw4v32.d
@@ -43,7 +43,7 @@ Disassembly of section \.text:
     4acc:	b005                	nop 
     4ace:	ffed 4635           	ba 8014 <x\+0x8014>
     4ad2:	b005                	nop 
-    4ad4:	0000                	bcc \.
+    4ad4:	b005                	nop 
     4ad6:	6f9e 0000 0000      	move.d 0 <x>,r9
 			4ad8: R_CRIS_32	x336
     4adc:	bfbd 0000 0000      	jsr 0 <x>

-- 
Alan Modra
Australia Development Lab, IBM

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

* Fix uninitialised ARM data
  2014-06-14  0:48 testsuite results with MALLOC_PERTURB_=1 Alan Modra
  2014-06-16  3:37 ` Fix uninitialised CRIS insn Alan Modra
@ 2014-06-16  3:39 ` Alan Modra
  2014-06-16  3:40 ` Fix uninitialised VAX .got and .got.plt section Alan Modra
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Alan Modra @ 2014-06-16  3:39 UTC (permalink / raw)
  To: binutils

MALLOC_PERTURB_=1 results in "FAIL: PIC" on arm-vxworks, due to garbage
in words with got relocs.

	* config/tc-arm.c (s_arm_elf_cons): Initialise after frag_more.
	(md_apply_fix): Delete now unnecessary zeroing for BFD_RELOC_ARM_GOT*
	and BFD_RELOC_ARM_TLS* relocs.  Simplify BFD_RELOC_8 case.

diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c
index 590855c..fc86db4 100644
--- a/gas/config/tc-arm.c
+++ b/gas/config/tc-arm.c
@@ -3453,7 +3453,8 @@ s_arm_elf_cons (int nbytes)
 		  memcpy (base, save_buf, p - base);
 
 		  offset = nbytes - size;
-		  p = frag_more ((int) nbytes);
+		  p = frag_more (nbytes);
+		  memset (p, 0, nbytes);
 		  fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
 			       size, &exp, 0, (enum bfd_reloc_code_real) reloc);
 		}
@@ -22384,7 +22385,7 @@ md_apply_fix (fixS *	fixP,
 
     case BFD_RELOC_8:
       if (fixP->fx_done || !seg->use_rela_p)
-	md_number_to_chars (buf, value, 1);
+	*buf = value;
       break;
 
     case BFD_RELOC_16:
@@ -22397,9 +22398,6 @@ md_apply_fix (fixS *	fixP,
     case BFD_RELOC_ARM_THM_TLS_CALL:
     case BFD_RELOC_ARM_TLS_DESCSEQ:
     case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
-      S_SET_THREAD_LOCAL (fixP->fx_addsy);
-      break;
-
     case BFD_RELOC_ARM_TLS_GOTDESC:
     case BFD_RELOC_ARM_TLS_GD32:
     case BFD_RELOC_ARM_TLS_LE32:
@@ -22407,12 +22405,10 @@ md_apply_fix (fixS *	fixP,
     case BFD_RELOC_ARM_TLS_LDM32:
     case BFD_RELOC_ARM_TLS_LDO32:
       S_SET_THREAD_LOCAL (fixP->fx_addsy);
-      /* fall through */
+      break;
 
     case BFD_RELOC_ARM_GOT32:
     case BFD_RELOC_ARM_GOTOFF:
-      if (fixP->fx_done || !seg->use_rela_p)
-	md_number_to_chars (buf, 0, 4);
       break;
 
     case BFD_RELOC_ARM_GOT_PREL:

-- 
Alan Modra
Australia Development Lab, IBM

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

* Fix uninitialised VAX .got and .got.plt section
  2014-06-14  0:48 testsuite results with MALLOC_PERTURB_=1 Alan Modra
  2014-06-16  3:37 ` Fix uninitialised CRIS insn Alan Modra
  2014-06-16  3:39 ` Fix uninitialised ARM data Alan Modra
@ 2014-06-16  3:40 ` Alan Modra
  2014-06-16  3:42 ` Fix uninitialised VAX insn Alan Modra
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Alan Modra @ 2014-06-16  3:40 UTC (permalink / raw)
  To: binutils

Cures these failures with MALLOC_PERTURB_=1
FAIL: GOT test (executable)
FAIL: GOT test (shared library)
FAIL: VAX export class call relocation test
FAIL: VAX export class data relocation test

	* elf32-vax.c (elf_vax_size_dynamic_sections): Clear linker
	created sections.

diff --git a/bfd/elf32-vax.c b/bfd/elf32-vax.c
index c28caca..1f41867 100644
--- a/bfd/elf32-vax.c
+++ b/bfd/elf32-vax.c
@@ -1221,7 +1221,7 @@ elf_vax_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 	continue;
 
       /* Allocate memory for the section contents.  */
-      s->contents = (bfd_byte *) bfd_alloc (dynobj, s->size);
+      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
       if (s->contents == NULL)
 	return FALSE;
     }

-- 
Alan Modra
Australia Development Lab, IBM

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

* Fix uninitialised VAX insn
  2014-06-14  0:48 testsuite results with MALLOC_PERTURB_=1 Alan Modra
                   ` (2 preceding siblings ...)
  2014-06-16  3:40 ` Fix uninitialised VAX .got and .got.plt section Alan Modra
@ 2014-06-16  3:42 ` Alan Modra
  2014-06-16  3:43 ` Fix TIC54X buffer overruns Alan Modra
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Alan Modra @ 2014-06-16  3:42 UTC (permalink / raw)
  To: binutils

MALLOC_PERTURB_=1 results in "FAIL: VAX ELF relocations", due to object
file being emitted with uninitialised fields.  Since these fields had
RELA relocs the field value won't be used at final link time, so the
problem is only seen in relocatable object files.

This rewrite of md_apply_fix clears all fields with relocs, whereas
before some fields had non-zero values.

gas/
	* config/tc-vax.c (md_apply_fix): Rewrite.
	(tc_gen_reloc, vax_cons, vax_cons_fix_new): Style: Use NO_RELOC
	define rather than the equivalent BFD_RELOC_NONE.
gas/testsuite/
	* gas/vax/elf-rel.d: Update.

diff --git a/gas/config/tc-vax.c b/gas/config/tc-vax.c
index 0740a9b..bccf596 100644
--- a/gas/config/tc-vax.c
+++ b/gas/config/tc-vax.c
@@ -278,15 +278,21 @@ md_apply_fix (fixS *fixP, valueT *valueP, segT seg ATTRIBUTE_UNUSED)
 {
   valueT value = * valueP;
 
-  if (((fixP->fx_addsy == NULL && fixP->fx_subsy == NULL)
-       && fixP->fx_r_type != BFD_RELOC_32_PLT_PCREL
-       && fixP->fx_r_type != BFD_RELOC_32_GOT_PCREL)
-      || fixP->fx_r_type == NO_RELOC)
-    number_to_chars_littleendian (fixP->fx_where + fixP->fx_frag->fr_literal,
-				  value, fixP->fx_size);
+  if (fixP->fx_subsy != (symbolS *) NULL)
+    as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
 
-  if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
+  if (fixP->fx_addsy == NULL)
     fixP->fx_done = 1;
+
+  if (fixP->fx_done)
+    number_to_chars_littleendian (fixP->fx_where + fixP->fx_frag->fr_literal,
+				  value, fixP->fx_size);
+  else
+    /* Initialise the part of an instruction frag covered by the
+       relocation.  (Many occurrences of frag_more followed by fix_new
+       lack any init of the frag.)  Since VAX uses RELA relocs the
+       value we write into this field doesn't really matter.  */
+    memset (fixP->fx_where + fixP->fx_frag->fr_literal, 0, fixP->fx_size);
 }
 
 /* Convert a number from VAX byte order (little endian)
@@ -2336,7 +2342,7 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
   if (fixp->fx_tcbit)
     abort ();
 
-  if (fixp->fx_r_type != BFD_RELOC_NONE)
+  if (fixp->fx_r_type != NO_RELOC)
     {
       code = fixp->fx_r_type;
 
@@ -3379,7 +3385,7 @@ vax_cons (expressionS *exp, int size)
       case 2: return BFD_RELOC_16_PCREL;
       case 4: return BFD_RELOC_32_PCREL;
       }
-  return BFD_RELOC_NONE;
+  return NO_RELOC;
 }
 
 /* This is called by emit_expr via TC_CONS_FIX_NEW when creating a
@@ -3389,7 +3395,7 @@ void
 vax_cons_fix_new (fragS *frag, int where, unsigned int nbytes, expressionS *exp,
 		  bfd_reloc_code_real_type r)
 {
-  if (r == BFD_RELOC_NONE)
+  if (r == NO_RELOC)
     r = (nbytes == 1 ? BFD_RELOC_8
 	 : nbytes == 2 ? BFD_RELOC_16
 	 : BFD_RELOC_32);
diff --git a/gas/testsuite/gas/vax/elf-rel.d b/gas/testsuite/gas/vax/elf-rel.d
index 7e2df40..d4b26c6 100644
--- a/gas/testsuite/gas/vax/elf-rel.d
+++ b/gas/testsuite/gas/vax/elf-rel.d
@@ -33,10 +33,10 @@ OFFSET [ ]+ TYPE              VALUE
 
 
 Contents of section \.text:
- 0000 0000fb00 affafb00 cff5fffb 00efeeff  .*
- 0010 fffffb00 ef000000 00d5afe4 d5cfe0ff  .*
- 0020 d5efdaff ffffd5ef 00000000 d5afd9d5  .*
- 0030 cfddffd5 efe7ffff ffd5ef00 00000004  .*
+ 0000 0000fb00 af00fb00 cf0000fb 00ef0000  .*
+ 0010 0000fb00 ef000000 00d5af00 d5cf0000  .*
+ 0020 d5ef0000 0000d5ef 00000000 d5af00d5  .*
+ 0030 cf0000d5 ef000000 00d5ef00 00000004  .*
 Contents of section \.data:
  0000 00000000 00000000 00000000 0000      .*
 #pass

-- 
Alan Modra
Australia Development Lab, IBM

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

* Fix TIC54X buffer overruns
  2014-06-14  0:48 testsuite results with MALLOC_PERTURB_=1 Alan Modra
                   ` (3 preceding siblings ...)
  2014-06-16  3:42 ` Fix uninitialised VAX insn Alan Modra
@ 2014-06-16  3:43 ` Alan Modra
  2014-06-16  3:44 ` Fix unintitialised TIC6X data Alan Modra
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Alan Modra @ 2014-06-16  3:43 UTC (permalink / raw)
  To: binutils

MALLOC_PERTURB_=1 results in "FAIL: c54x macros".

	* config/tc-tic54x.c (tic54x_mlib): Don't write garbage past
	end of archive to temp file.
	(tic54x_start_line_hook): Start scan for parallel on next line,
	not one char into next line (which may overrun the buffer).

diff --git a/gas/config/tc-tic54x.c b/gas/config/tc-tic54x.c
index bba743c..c997297 100644
--- a/gas/config/tc-tic54x.c
+++ b/gas/config/tc-tic54x.c
@@ -2368,13 +2368,13 @@ tic54x_mlib (int ignore ATTRIBUTE_UNUSED)
       FILE *ftmp;
 
       /* We're not sure how big it is, but it will be smaller than "size".  */
-      bfd_bread (buf, size, mbfd);
+      size = bfd_bread (buf, size, mbfd);
 
       /* Write to a temporary file, then use s_include to include it
 	 a bit of a hack.  */
       ftmp = fopen (fname, "w+b");
       fwrite ((void *) buf, size, 1, ftmp);
-      if (buf[size - 1] != '\n')
+      if (size == 0 || buf[size - 1] != '\n')
 	fwrite ("\n", 1, 1, ftmp);
       fclose (ftmp);
       free (buf);
@@ -4777,7 +4777,7 @@ tic54x_start_line_hook (void)
   line[endp - input_line_pointer] = 0;
 
   /* Scan ahead for parallel insns.  */
-  parallel_on_next_line_hint = next_line_shows_parallel (endp + 1);
+  parallel_on_next_line_hint = next_line_shows_parallel (endp);
 
   /* If within a macro, first process forced replacements.  */
   if (macro_level > 0)

-- 
Alan Modra
Australia Development Lab, IBM

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

* Fix unintitialised TIC6X data
  2014-06-14  0:48 testsuite results with MALLOC_PERTURB_=1 Alan Modra
                   ` (4 preceding siblings ...)
  2014-06-16  3:43 ` Fix TIC54X buffer overruns Alan Modra
@ 2014-06-16  3:44 ` Alan Modra
  2014-06-16  3:45 ` Report an error on x86 pcrel BFD_RELOC_SIZE64 Alan Modra
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Alan Modra @ 2014-06-16  3:44 UTC (permalink / raw)
  To: binutils

MALLOC_PERTURB_=1 results in the following fails due to uninitialised
exindx data:

FAIL: C6X unwinding directives 1 (little endian)
FAIL: C6X unwinding directives 2 (big endian)
FAIL: C6X unwinding directives 3 (segment change)
FAIL: ld-tic6x/unwind-1
FAIL: ld-tic6x/unwind-2
FAIL: ld-tic6x/unwind-3
FAIL: ld-tic6x/unwind-4
FAIL: ld-tic6x/unwind-6

	* config/tc-tic6x.c (s_tic6x_ehtype): Clear after frag_more.
	(tic6x_output_exidx_entry): Likewise.
	(md_apply_fix): Simplify 1 byte md_number_to_chars.

 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/gas/config/tc-tic6x.c b/gas/config/tc-tic6x.c
index aca07d3..3f2912a 100644
--- a/gas/config/tc-tic6x.c
+++ b/gas/config/tc-tic6x.c
@@ -536,6 +536,7 @@ s_tic6x_ehtype (int ignored ATTRIBUTE_UNUSED)
     }
 
   p = frag_more (4);
+  memset (p, 0, 4);
   fix_new_exp (frag_now, p - frag_now->fr_literal, 4,
 	       &exp, 0, BFD_RELOC_C6000_EHTYPE);
 
@@ -3823,7 +3824,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
 	  if (value < -0x80 || value > 0xff)
 	    as_bad_where (fixP->fx_file, fixP->fx_line,
 			  _("value too large for 1-byte field"));
-	  md_number_to_chars (buf, value, 1);
+	  *buf = value;
 	}
       break;
 
@@ -4835,6 +4836,7 @@ tic6x_output_exidx_entry (void)
   record_alignment (now_seg, 2);
 
   ptr = frag_more (8);
+  memset (ptr, 0, 8);
   where = frag_now_fix () - 8;
 
   /* Self relative offset of the function start.  */

-- 
Alan Modra
Australia Development Lab, IBM

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

* Report an error on x86 pcrel BFD_RELOC_SIZE64
  2014-06-14  0:48 testsuite results with MALLOC_PERTURB_=1 Alan Modra
                   ` (5 preceding siblings ...)
  2014-06-16  3:44 ` Fix unintitialised TIC6X data Alan Modra
@ 2014-06-16  3:45 ` Alan Modra
  2014-06-16  3:46 ` Don't leave DLX the_insn uninitialised Alan Modra
  2014-06-16  3:50 ` Run write_object_file after errors Alan Modra
  8 siblings, 0 replies; 16+ messages in thread
From: Alan Modra @ 2014-06-16  3:45 UTC (permalink / raw)
  To: binutils

	* config/tc-i386.c (reloc): Don't avoid pcrel check for
	BFD_RELOC_SIZE64.  Return NO_RELOC on failing pcrel check.

diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 341d100..d0d4d6c 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -2846,9 +2846,12 @@ reloc (unsigned int size,
       if (other == BFD_RELOC_SIZE32)
 	{
 	  if (size == 8)
-	    return BFD_RELOC_SIZE64;
+	    other = BFD_RELOC_SIZE64;
 	  if (pcrel)
-	    as_bad (_("there are no pc-relative size relocations"));
+	    {
+	      as_bad (_("there are no pc-relative size relocations"));
+	      return NO_RELOC;
+	    }
 	}
 #endif
 

-- 
Alan Modra
Australia Development Lab, IBM

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

* Don't leave DLX the_insn uninitialised
  2014-06-14  0:48 testsuite results with MALLOC_PERTURB_=1 Alan Modra
                   ` (6 preceding siblings ...)
  2014-06-16  3:45 ` Report an error on x86 pcrel BFD_RELOC_SIZE64 Alan Modra
@ 2014-06-16  3:46 ` Alan Modra
  2014-06-16  3:50 ` Run write_object_file after errors Alan Modra
  8 siblings, 0 replies; 16+ messages in thread
From: Alan Modra @ 2014-06-16  3:46 UTC (permalink / raw)
  To: binutils

In particular the_insn.reloc must be initialised, otherwise the early
exit cases for bad opcodes will result in cascading errors if
write_object_file is called after an error.

	* config/tc-dlx.c (machine_ip): Move initialisation of the_insn
	earlier.

diff --git a/gas/config/tc-dlx.c b/gas/config/tc-dlx.c
index 4cbc5c0..3c487f2 100644
--- a/gas/config/tc-dlx.c
+++ b/gas/config/tc-dlx.c
@@ -666,6 +666,9 @@ machine_ip (char *str)
   expressionS *operand = &the_operand;
   unsigned int reg, reg_shift = 0;
 
+  memset (&the_insn, '\0', sizeof (the_insn));
+  the_insn.reloc = NO_RELOC;
+
   /* Fixup the opcode string to all lower cases, and also
      allow numerical digits.  */
   s = str;
@@ -690,19 +693,12 @@ machine_ip (char *str)
       return;
     }
 
-  /* Hash the opcode, insn will have the string from opcode table.
-     also initialized the_insn struct.  */
+  /* Hash the opcode, insn will have the string from opcode table.  */
   if ((insn = (struct machine_opcode *) hash_find (op_hash, str)) == NULL)
     {
       /* Handle the ret and return macro here.  */
       if ((strcmp (str, "ret") == 0) || (strcmp (str, "return") == 0))
-	{
-	  memset (&the_insn, '\0', sizeof (the_insn));
-	  the_insn.reloc = NO_RELOC;
-	  the_insn.pcrel = 0;
-	  the_insn.opcode =
-	    (unsigned long)(JROP | 0x03e00000);    /* 0x03e00000 = r31 << 21 */
-	}
+	the_insn.opcode = JROP | 0x03e00000;    /* 0x03e00000 = r31 << 21 */
       else
 	as_bad (_("Unknown opcode `%s'."), str);
 
@@ -710,9 +706,6 @@ machine_ip (char *str)
     }
 
   opcode = insn->opcode;
-  memset (&the_insn, '\0', sizeof (the_insn));
-  the_insn.reloc = NO_RELOC;
-  the_insn.pcrel = 0;
 
   /* Set the sip reloc HI16 flag.  */
   if (!set_dlx_skip_hi16_flag (1))

-- 
Alan Modra
Australia Development Lab, IBM

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

* Run write_object_file after errors
  2014-06-14  0:48 testsuite results with MALLOC_PERTURB_=1 Alan Modra
                   ` (7 preceding siblings ...)
  2014-06-16  3:46 ` Don't leave DLX the_insn uninitialised Alan Modra
@ 2014-06-16  3:50 ` Alan Modra
  2014-06-27  3:21   ` Alan Modra
  8 siblings, 1 reply; 16+ messages in thread
From: Alan Modra @ 2014-06-16  3:50 UTC (permalink / raw)
  To: binutils

This is to fix unitialised memory access when printing listings.
Many targets don't initialise parts of insn frags or data frags that
have fixups, relying on md_apply_fix to finalise the frag.  Which is
fine normally, but means we need to run write_object_file after
errors, for listings.  Otherwise MALLOC_PERTURB_=1 causes errors like:
x86_64-linux  +FAIL: i386 mpx-inval-1
x86_64-linux  +FAIL: i386 inval-equ-1
x86_64-linux  +FAIL: i386 x86-64-mpx-inval-1

Running write_object_file after errors requires some tweaking to the
testsuite, since we then get extra errors reported from md_apply_fix.

I haven't yet fixed the following:
aarch64-linux  +FAIL: Illegal Instructions
cris-elf  +FAIL: gas/cris/range-err-1.s (test for excess errors)
cris-elf  +FAIL: gas/cris/v32-err-10.s (test for excess errors)
i386-darwin  +FAIL: gas/mach-o/err-syms-3.s (test for excess errors)
mmix  +FAIL: gas/mmix/err-fb-2.s (test for excess errors)


gas/
	* write.h (subsegs_finish): Delete declaration.
	* write.c (subsegs_finish): Make static.
	(write_object_file): Call subsegs_finish from here.  Don't print
	warning and error count here..
	* as.c (main): ..do so here instead.  Remove dead code for "no
	object file generated".  Split out count strings to better support
	internationalisation.  Don't call subsegs_finish. Tidy setting of
	"keep_it".  Run write_object_file even after errors.
	(keep_it): Make static.
	* config/obj-elf.c (elf_frob_symbol): Remove assert.
	(elf_frob_file_before_adjust): Likewise.
gas/testsuite/
	* gas/elf/bad-group.s: Use %function.
	* gas/elf/bad-group.err: Expect correct line number.  Allow
	other errors.
	* gas/elf/bad-size.err: Allow other errors.  Match expected
	error somewhat more rigorously.
	* gas/i386/reloc32.l: Allow other errors.
	* gas/i386/mpx-inval-1.l: Match applied relocs.
	* gas/i386/x86-64-mpx-inval-1.l: Likewise, and nop padding.
	* gas/i386/x86-64-mpx-inval-2.l: Match nop padding, and allow
	other errors.
	* gas/macros/dot.s: Use .balign.
	* gas/macros/dot.l: Update alignment output.
	* gas/symver/symver6.l: Allow other errors.

diff --git a/gas/write.c b/gas/write.c
index 4ab275d..d1918e6 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -1692,7 +1692,7 @@ set_symtab (void)
 #endif
 #endif
 
-void
+static void
 subsegs_finish (void)
 {
   struct frchain *frchainP;
@@ -1761,33 +1761,12 @@ write_object_file (void)
   fragS *fragP;			/* Track along all frags.  */
 #endif
 
+  subsegs_finish ();
+
 #ifdef md_pre_output_hook
   md_pre_output_hook;
 #endif
 
-  /* Do we really want to write it?  */
-  {
-    int n_warns, n_errs;
-    n_warns = had_warnings ();
-    n_errs = had_errors ();
-    /* The -Z flag indicates that an object file should be generated,
-       regardless of warnings and errors.  */
-    if (flag_always_generate_output)
-      {
-	if (n_warns || n_errs)
-	  as_warn (_("%d error%s, %d warning%s, generating bad object file"),
-		   n_errs, n_errs == 1 ? "" : "s",
-		   n_warns, n_warns == 1 ? "" : "s");
-      }
-    else
-      {
-	if (n_errs)
-	  as_fatal (_("%d error%s, %d warning%s, no object file generated"),
-		    n_errs, n_errs == 1 ? "" : "s",
-		    n_warns, n_warns == 1 ? "" : "s");
-      }
-  }
-
 #ifdef md_pre_relax_hook
   md_pre_relax_hook;
 #endif
diff --git a/gas/write.h b/gas/write.h
index c9b3da0..0389005 100644
--- a/gas/write.h
+++ b/gas/write.h
@@ -169,7 +169,6 @@ extern struct reloc_list* reloc_list;
 extern void append (char **charPP, char *fromP, unsigned long length);
 extern void record_alignment (segT seg, int align);
 extern int get_recorded_alignment (segT seg);
-extern void subsegs_finish (void);
 extern void write_object_file (void);
 extern long relax_frag (segT, fragS *, long);
 extern int relax_segment (struct frag *, segT, int);
diff --git a/gas/as.c b/gas/as.c
index 752af64..32459a8 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -97,7 +97,7 @@ int debug_memory = 0;
 int verbose = 0;
 
 /* Keep the output file.  */
-int keep_it = 0;
+static int keep_it = 0;
 
 segT reg_section;
 segT expr_section;
@@ -1283,20 +1283,45 @@ main (int argc, char ** argv)
      directives from the user or by the backend, emit it now.  */
   cfi_finish ();
 
-  if (seen_at_least_1_file ()
-      && (flag_always_generate_output || had_errors () == 0))
-    keep_it = 1;
-  else
-    keep_it = 0;
+  keep_it = 0;
+  if (seen_at_least_1_file ())
+    {
+      int n_warns, n_errs;
+      char warn_msg[50];
+      char err_msg[50];
+
+      write_object_file ();
+
+      n_warns = had_warnings ();
+      n_errs = had_errors ();
+
+      if (n_warns == 1)
+	sprintf (warn_msg, _("%d warning"), n_warns);
+      else
+	sprintf (warn_msg, _("%d warnings"), n_warns);
+      if (n_errs == 1)
+	sprintf (err_msg, _("%d error"), n_errs);
+      else
+	sprintf (err_msg, _("%d errors"), n_errs);
 
-  /* This used to be done at the start of write_object_file in
-     write.c, but that caused problems when doing listings when
-     keep_it was zero.  This could probably be moved above md_end, but
-     I didn't want to risk the change.  */
-  subsegs_finish ();
+      if (flag_fatal_warnings && n_warns != 0)
+	{
+	  if (n_errs == 0)
+	    as_bad (_("%s, treating warnings as errors"), warn_msg);
+	  n_errs += n_warns;
+	}
 
-  if (keep_it)
-    write_object_file ();
+      if (n_errs == 0)
+	keep_it = 1;
+      else if (flag_always_generate_output)
+	{
+	  /* The -Z flag indicates that an object file should be generated,
+	     regardless of warnings and errors.  */
+	  keep_it = 1;
+	  fprintf (stderr, _("%s, %s, generating bad object file\n"),
+		   err_msg, warn_msg);
+	}
+    }
 
   fflush (stderr);
 
@@ -1304,19 +1329,13 @@ main (int argc, char ** argv)
   listing_print (listing_filename, argv_orig);
 #endif
 
-  if (flag_fatal_warnings && had_warnings () > 0 && had_errors () == 0)
-    as_bad (_("%d warnings, treating warnings as errors"), had_warnings ());
-
-  if (had_errors () > 0 && ! flag_always_generate_output)
-    keep_it = 0;
-
   input_scrub_end ();
 
   END_PROGRESS (myname);
 
   /* Use xexit instead of return, because under VMS environments they
      may not place the same interpretation on the value given.  */
-  if (had_errors () > 0)
+  if (had_errors () != 0)
     xexit (EXIT_FAILURE);
 
   /* Only generate dependency file if assembler was successful.  */
diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index e406f7b..e59f27b 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -2120,7 +2120,9 @@ elf_frob_symbol (symbolS *symp, int *puntp)
       char *p;
 
       p = strchr (sy_obj->versioned_name, ELF_VER_CHR);
-      know (p != NULL);
+      if (p == NULL)
+	/* We will have already reported an error about a missing version.  */
+	*puntp = TRUE;
 
       /* This symbol was given a new name with the .symver directive.
 
@@ -2133,14 +2135,15 @@ elf_frob_symbol (symbolS *symp, int *puntp)
 	 symbol.  However, it's not clear whether it is the best
 	 approach.  */
 
-      if (! S_IS_DEFINED (symp))
+      else if (! S_IS_DEFINED (symp))
 	{
 	  /* Verify that the name isn't using the @@ syntax--this is
 	     reserved for definitions of the default version to link
 	     against.  */
 	  if (p[1] == ELF_VER_CHR)
 	    {
-	      as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
+	      as_bad (_("invalid attempt to declare external version name"
+			" as default in symbol `%s'"),
 		      sy_obj->versioned_name);
 	      *puntp = TRUE;
 	    }
@@ -2403,8 +2406,7 @@ elf_frob_file_before_adjust (void)
 
 		p = strchr (symbol_get_obj (symp)->versioned_name,
 			    ELF_VER_CHR);
-		know (p != NULL);
-		if (p[1] == ELF_VER_CHR && p[2] == ELF_VER_CHR)
+		if (p != NULL && p[1] == ELF_VER_CHR && p[2] == ELF_VER_CHR)
 		  {
 		    size_t l = strlen (&p[3]) + 1;
 		    memmove (&p[1], &p[3], l);
diff --git a/gas/testsuite/gas/elf/bad-group.err b/gas/testsuite/gas/elf/bad-group.err
index 4b650d4..db5db2f 100644
--- a/gas/testsuite/gas/elf/bad-group.err
+++ b/gas/testsuite/gas/elf/bad-group.err
@@ -1,2 +1,3 @@
 .*bad-group\.s: Assembler messages:
-.*bad-group\.s:.* Error: .*
+.*bad-group\.s:10: Error: .*
+#pass
diff --git a/gas/testsuite/gas/elf/bad-group.s b/gas/testsuite/gas/elf/bad-group.s
index dc927c6..7a7368f 100644
--- a/gas/testsuite/gas/elf/bad-group.s
+++ b/gas/testsuite/gas/elf/bad-group.s
@@ -1,7 +1,7 @@
 	.section	.text.startup,"ax",%progbits
 	.globl main
 main:
-	.type	main, @function
+	.type	main, %function
 .LFB0:
 	.section	.text.unlikely,"ax",%progbits
 .L5:
diff --git a/gas/testsuite/gas/elf/bad-size.err b/gas/testsuite/gas/elf/bad-size.err
index caa6bae..513d250 100644
--- a/gas/testsuite/gas/elf/bad-size.err
+++ b/gas/testsuite/gas/elf/bad-size.err
@@ -1,2 +1,3 @@
 .*bad-size\.s: Assembler messages:
-.*bad-size\.s:.* Error: .*
+#...
+.*bad-size\.s:.* Error: \.size expression .* does not evaluate to a constant
diff --git a/gas/testsuite/gas/i386/mpx-inval-1.l b/gas/testsuite/gas/i386/mpx-inval-1.l
index 121aad6..b356080 100644
--- a/gas/testsuite/gas/i386/mpx-inval-1.l
+++ b/gas/testsuite/gas/i386/mpx-inval-1.l
@@ -33,9 +33,9 @@ GAS LISTING .*
 .*  Error: expecting valid branch instruction after `bnd'
 .*  Warning: skipping prefixes on this instruction
 [ 	]*9[ 	]+003412
-[ 	]*10[ 	]+\?\?\?\? F2E200   		bnd loop foo
+[ 	]*10[ 	]+\?\?\?\? F2E2E9   		bnd loop foo
 .*  Error: expecting valid branch instruction after `bnd'
-[ 	]*11[ 	]+\?\?\?\? 67F2E300 		bnd jcxz foo
+[ 	]*11[ 	]+\?\?\?\? 67F2E3E5 		bnd jcxz foo
 .*  Error: expecting valid branch instruction after `bnd'
 [ 	]*12[ 	]+
 [ 	]*13[ 	]+\.intel_syntax noprefix
@@ -49,7 +49,8 @@ GAS LISTING .*
 [ 	]*17[ 	]+\?\?\?\? EA000000 		bnd ljmp 0x1234,xxx
 .*  Error: expecting valid branch instruction after `bnd'
 [ 	]*17[ 	]+003412
-[ 	]*18[ 	]+\?\?\?\? F2E200   		bnd loop foo
+[ 	]*18[ 	]+\?\?\?\? F2E2CE   		bnd loop foo
 .*  Error: expecting valid branch instruction after `bnd'
-[ 	]*19[ 	]+\?\?\?\? 67F2E300 		bnd jcxz foo
+[ 	]*19[ 	]+\?\?\?\? 67F2E3CA 		bnd jcxz foo
 .*  Error: expecting valid branch instruction after `bnd'
+#pass
diff --git a/gas/testsuite/gas/i386/reloc32.l b/gas/testsuite/gas/i386/reloc32.l
index 74e80df..9299445 100644
--- a/gas/testsuite/gas/i386/reloc32.l
+++ b/gas/testsuite/gas/i386/reloc32.l
@@ -65,3 +65,4 @@
 .*:159: Error: .*
 .*:160: Error: .*
 .*:161: Error: .*
+#pass
diff --git a/gas/testsuite/gas/i386/x86-64-mpx-inval-1.l b/gas/testsuite/gas/i386/x86-64-mpx-inval-1.l
index 16b3aff..361de10 100644
--- a/gas/testsuite/gas/i386/x86-64-mpx-inval-1.l
+++ b/gas/testsuite/gas/i386/x86-64-mpx-inval-1.l
@@ -17,9 +17,9 @@ GAS LISTING .*
 .*  Error: expecting valid branch instruction after `bnd'
 [ 	]*5[ 	]+\?\?\?\? 6766F2AB 		bnd stosw \(%edi\)    		\# Bad
 .*  Error: expecting valid branch instruction after `bnd'
-[ 	]*6[ 	]+\?\?\?\? F2E200   		bnd loop foo
+[ 	]*6[ 	]+\?\?\?\? F2E2(00|0A)   		bnd loop foo
 .*  Error: expecting valid branch instruction after `bnd'
-[ 	]*7[ 	]+\?\?\?\? F2E300   		bnd jrcxz foo
+[ 	]*7[ 	]+\?\?\?\? F2E3(00|0D)   		bnd jrcxz foo
 .*  Error: expecting valid branch instruction after `bnd'
 [ 	]*8[ 	]+
 [ 	]*9[ 	]+\.intel_syntax noprefix
@@ -27,7 +27,8 @@ GAS LISTING .*
 .*  Error: expecting valid branch instruction after `bnd'
 [ 	]*11[ 	]+\?\?\?\? 6766F2AB 		bnd stos WORD PTR \[edi]		\# Bad
 .*  Error: expecting valid branch instruction after `bnd'
-[ 	]*12[ 	]+\?\?\?\? F2E200   		bnd loop foo
+[ 	]*12[ 	]+\?\?\?\? F2E2(00|18)   		bnd loop foo
 .*  Error: expecting valid branch instruction after `bnd'
-[ 	]*13[ 	]+\?\?\?\? F2E300   		bnd jrcxz foo
+[ 	]*13[ 	]+\?\?\?\? F2E3(00|1B)(  |90) 		bnd jrcxz foo
 .*  Error: expecting valid branch instruction after `bnd'
+#pass
diff --git a/gas/testsuite/gas/i386/x86-64-mpx-inval-2.l b/gas/testsuite/gas/i386/x86-64-mpx-inval-2.l
index c7be066..d9a1b6e 100644
--- a/gas/testsuite/gas/i386/x86-64-mpx-inval-2.l
+++ b/gas/testsuite/gas/i386/x86-64-mpx-inval-2.l
@@ -170,4 +170,5 @@ GAS LISTING .*
 [ 	]*65[ 	]+\?\?\?\? 670F1A14 		bndldx bnd2, \[1\*ebx\+3\]
 .*  Error: 32-bit address isn't allowed in 64-bit MPX instructions\.
 [ 	]*65[ 	]+1D030000 
-[ 	]*65[ 	]+00
+[ 	]*65[ 	]+00(|909090 )
+#pass
diff --git a/gas/testsuite/gas/macros/dot.l b/gas/testsuite/gas/macros/dot.l
index 5c616b0..07334ce 100644
--- a/gas/testsuite/gas/macros/dot.l
+++ b/gas/testsuite/gas/macros/dot.l
@@ -6,11 +6,11 @@
 [ 	]*[1-9][0-9]*[ 	]+m 4, 2
 [ 	]*[1-9][0-9]*[ 	]+>  \.data
 [ 	]*[1-9][0-9]*[ 	]+> labelA:labelB:labelC:labelD:x\.y\.z 4\+2
-[ 	]*[1-9][0-9]*[ 	]+>>  \.align 4
+[ 	]*[1-9][0-9]*[ 	]+>>  \.balign 4
 [ 	]*[1-9][0-9]*[ 	]+\?+[ 	]+06 ?06[ 	]+>>  \.byte 4\+2,4\+2
 [ 	]*[1-9][0-9]*[ 	]+\?+[ 	]+00 ?00[ 	]+>  \.skip 2
 [ 	]*[1-9][0-9]*[ 	]+> labelZ:labelY:labelX:labelW:\.xyz 4-2
-[ 	]*[1-9][0-9]*[ 	]+>>  \.align 8
+[ 	]*[1-9][0-9]*[ 	]+\?+[ 	]+00 ?00 ?00 ?00[ 	]+>>  \.balign 8
 [ 	]*[1-9][0-9]*[ 	]+\?+[ 	]+02 ?02[ 	]+>>  \.byte 4-2,4-2
 [ 	]*[1-9][0-9]*[ 	]+\?+[ 	]+00 ?00 ?00 ?00[ 	]+>  \.skip 4\*2
 [ 	]*[1-9][0-9]*[ 	]+00 ?00 ?00 ?00[ 	]*
diff --git a/gas/testsuite/gas/macros/dot.s b/gas/testsuite/gas/macros/dot.s
index e9c326d..6916400 100644
--- a/gas/testsuite/gas/macros/dot.s
+++ b/gas/testsuite/gas/macros/dot.s
@@ -1,12 +1,12 @@
  .altmacro
 
  .macro x.y.z val
-  .align 4
+  .balign 4
   .byte val,val
  .endm
 
  .macro .xyz val
-  .align 8
+  .balign 8
   .byte val,val
  .endm
 
diff --git a/gas/testsuite/gas/symver/symver6.l b/gas/testsuite/gas/symver/symver6.l
index 69468b4..c2d12ae 100644
--- a/gas/testsuite/gas/symver/symver6.l
+++ b/gas/testsuite/gas/symver/symver6.l
@@ -1,2 +1,3 @@
 .*: Assembler messages:
 .*:7: Error: multiple versions \[`foo@version1'|`foo@@version1'\] for symbol `foo'
+#pass

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: Fix uninitialised CRIS insn
  2014-06-16  3:37 ` Fix uninitialised CRIS insn Alan Modra
@ 2014-06-16  5:12   ` Hans-Peter Nilsson
  2014-06-16  7:40     ` Alan Modra
  0 siblings, 1 reply; 16+ messages in thread
From: Hans-Peter Nilsson @ 2014-06-16  5:12 UTC (permalink / raw)
  To: amodra; +Cc: binutils

> From: Alan Modra <amodra@gmail.com>
> Sender: "binutils-owner@sourceware.org" <binutils-owner@sourceware.org>

> Fixes "FAIL: gas/cris/rd-bkw4v32" with MALLOC_PERTURB_=1
> 
> gas/
> 	* config/tc-cris.c (md_create_long_jump): Follow "short" jump
> 	with a nop rather than leaving uninitialised.
> gas/testsuite/
> 	* gas/cris/rd-bkw4v32.d: Update.

Thanks, though there are more.  For cris-elf, cris-linux and
mmix-knuth-mmixware, your changes has caused spurious extra
error messages.  (Please don't adjust the expected error
messsages to match; the bug is that the extra lines are
emitted.)

MMIX:
Running /tmp/hpautotest-binutils/bsrc/src/gas/testsuite/gas/mmix/mmix-err.exp ...
FAIL: gas/mmix/err-fb-2.s (test for excess errors)

i.e.
err-fb-2.s: Assembler messages:
err-fb-2.s:19: Error: LOC to section unknown or indeterminable at first pass
err-fb-2.s:10: Error: LOC to section unknown or indeterminable at first pass
err-fb-2.s:19: Error: attempt to move .org backwards

(The last line is spurious; the first two expected.)

CRIS:
Running /tmp/hpautotest-binutils/bsrc/src/gas/testsuite/gas/cris/cris.exp ...
FAIL: gas/cris/range-err-1.s (test for excess errors)
FAIL: gas/cris/v32-err-10.s (test for excess errors)

For v32-err-10.s, there are now two lines where there was one:
v32-err-10.s:17: Error: Immediate value not in 16 bit signed range: -32769
v32-err-10.s:17: Error: Value not in 16 bit range: -32769

Similarly range-err-1.s but many more.

brgds, H-P

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

* Re: Fix uninitialised CRIS insn
  2014-06-16  5:12   ` Hans-Peter Nilsson
@ 2014-06-16  7:40     ` Alan Modra
  2014-06-16 13:32       ` Hans-Peter Nilsson
  0 siblings, 1 reply; 16+ messages in thread
From: Alan Modra @ 2014-06-16  7:40 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: binutils

On Mon, Jun 16, 2014 at 07:11:54AM +0200, Hans-Peter Nilsson wrote:
> > From: Alan Modra <amodra@gmail.com>
> > Sender: "binutils-owner@sourceware.org" <binutils-owner@sourceware.org>
> 
> > Fixes "FAIL: gas/cris/rd-bkw4v32" with MALLOC_PERTURB_=1
> > 
> > gas/
> > 	* config/tc-cris.c (md_create_long_jump): Follow "short" jump
> > 	with a nop rather than leaving uninitialised.
> > gas/testsuite/
> > 	* gas/cris/rd-bkw4v32.d: Update.
> 
> Thanks, though there are more.  For cris-elf, cris-linux and
> mmix-knuth-mmixware, your changes has caused spurious extra
> error messages.  (Please don't adjust the expected error
> messsages to match; the bug is that the extra lines are
> emitted.)

Yes, I know.  I mentioned that in a later message.  The extra errors
are a result of calling write_object_file() after as_bad() occurred,
something that only happened before with the -Z option.

I was hoping you'd deal with the testcase errors, rather than have
me blundering around in your ports.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: Fix uninitialised CRIS insn
  2014-06-16  7:40     ` Alan Modra
@ 2014-06-16 13:32       ` Hans-Peter Nilsson
  2014-06-16 23:04         ` Hans-Peter Nilsson
  0 siblings, 1 reply; 16+ messages in thread
From: Hans-Peter Nilsson @ 2014-06-16 13:32 UTC (permalink / raw)
  To: amodra; +Cc: binutils

> From: Alan Modra <amodra@gmail.com>
> Date: Mon, 16 Jun 2014 09:40:34 +0200

> > Thanks, though there are more.  For cris-elf, cris-linux and
> > mmix-knuth-mmixware, your changes has caused spurious extra
> > error messages.  (Please don't adjust the expected error
> > messsages to match; the bug is that the extra lines are
> > emitted.)
> 
> Yes, I know.  I mentioned that in a later message.

Oops, I missed that.

> I was hoping you'd deal with the testcase errors, rather than have
> me blundering around in your ports.

Ok, let's do that, thanks for your work.

brgds, H-P

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

* Re: Fix uninitialised CRIS insn
  2014-06-16 13:32       ` Hans-Peter Nilsson
@ 2014-06-16 23:04         ` Hans-Peter Nilsson
  0 siblings, 0 replies; 16+ messages in thread
From: Hans-Peter Nilsson @ 2014-06-16 23:04 UTC (permalink / raw)
  To: binutils

> From: Hans-Peter Nilsson <hp@axis.com>
> Date: Mon, 16 Jun 2014 15:31:48 +0200

> > From: Alan Modra <amodra@gmail.com>
> > Date: Mon, 16 Jun 2014 09:40:34 +0200

> > I was hoping you'd deal with the testcase errors, rather than have
> > me blundering around in your ports.
> 
> Ok, let's do that, thanks for your work.

Here's the fix for CRIS.

There wasn't complete test-suite coverage for the possible
double-error situations, so I added some missing tests.  There
*still* isn't full coverage, but the missing cases are currently
impossible (as SIZE_FIELD_UNSIGNED is not fully implemented and
unused in the opcode table).  Some of the failures of the new
tests seems to have been caused by fall-through bugs; not the
recent changes.

(N.B. I did not fix the capitalization errors in the messages, I
just made sure the new test would not have to be adjusted
if/when that's done.  Also, it seems there's a language error
with hyphenation, unfixed.)

Committed.

gas:
	* config/tc-cris.c (cris_bad): New function.
	(cris_process_instruction): Where applicable, use it instead of
	as_bad.

gas/testsuite:
	* gas/cris/range-err-3.s: New test.

diff --git a/gas/config/tc-cris.c b/gas/config/tc-cris.c
index aba4ef7..2989f02 100644
--- a/gas/config/tc-cris.c
+++ b/gas/config/tc-cris.c
@@ -1492,6 +1492,19 @@ md_assemble (char *str)
     }
 }
 
+/* Helper error-reporting function: calls as_bad for a format string
+   for a single value and zeroes the offending value (zero assumed
+   being a valid value) to avoid repeated error reports in later value
+   checking.  */
+
+static void
+cris_bad (const char *format, offsetT *valp)
+{
+  /* We cast to long so the format string can assume that format.  */
+  as_bad (format, (long) *valp);
+  *valp = 0;
+}
+
 /* Low level text-to-bits assembly.  */
 
 static void
@@ -1646,8 +1659,8 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
 		  if (out_insnp->expr.X_op == O_constant
 		      && (out_insnp->expr.X_add_number < 0
 			  || out_insnp->expr.X_add_number > 31))
-		    as_bad (_("Immediate value not in 5 bit unsigned range: %ld"),
-			    out_insnp->expr.X_add_number);
+		    cris_bad (_("Immediate value not in 5 bit unsigned range: %ld"),
+			      &out_insnp->expr.X_add_number);
 
 		  out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_5;
 		  continue;
@@ -1662,8 +1675,8 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
 		  if (out_insnp->expr.X_op == O_constant
 		      && (out_insnp->expr.X_add_number < 0
 			  || out_insnp->expr.X_add_number > 15))
-		    as_bad (_("Immediate value not in 4 bit unsigned range: %ld"),
-			    out_insnp->expr.X_add_number);
+		    cris_bad (_("Immediate value not in 4 bit unsigned range: %ld"),
+			      &out_insnp->expr.X_add_number);
 
 		  out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_4;
 		  continue;
@@ -1714,8 +1727,9 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
 		  if (out_insnp->expr.X_op == O_constant
 		      && (out_insnp->expr.X_add_number < -32
 			  || out_insnp->expr.X_add_number > 31))
-		    as_bad (_("Immediate value not in 6 bit range: %ld"),
-			    out_insnp->expr.X_add_number);
+		    cris_bad (_("Immediate value not in 6 bit range: %ld"),
+			      &out_insnp->expr.X_add_number);
+
 		  out_insnp->reloc = BFD_RELOC_CRIS_SIGNED_6;
 		  continue;
 		}
@@ -1729,8 +1743,9 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
 		  if (out_insnp->expr.X_op == O_constant
 		      && (out_insnp->expr.X_add_number < 0
 			  || out_insnp->expr.X_add_number > 63))
-		    as_bad (_("Immediate value not in 6 bit unsigned range: %ld"),
-			    out_insnp->expr.X_add_number);
+		    cris_bad (_("Immediate value not in 6 bit unsigned range: %ld"),
+			      &out_insnp->expr.X_add_number);
+
 		  out_insnp->reloc = BFD_RELOC_CRIS_UNSIGNED_6;
 		  continue;
 		}
@@ -2122,8 +2137,8 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
 			if (out_insnp->expr.X_op == O_constant
 			    && (out_insnp->expr.X_add_number < -128
 				|| out_insnp->expr.X_add_number > 255))
-			  as_bad (_("Immediate value not in 8 bit range: %ld"),
-				  out_insnp->expr.X_add_number);
+			  cris_bad (_("Immediate value not in 8 bit range: %ld"),
+				    &out_insnp->expr.X_add_number);
 			/* Fall through.  */
 		      case 2:
 			/* FIXME:  We need an indicator in the instruction
@@ -2132,8 +2147,8 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
 			if (out_insnp->expr.X_op == O_constant
 			    && (out_insnp->expr.X_add_number < -32768
 				|| out_insnp->expr.X_add_number > 65535))
-			  as_bad (_("Immediate value not in 16 bit range: %ld"),
-				  out_insnp->expr.X_add_number);
+			  cris_bad (_("Immediate value not in 16 bit range: %ld"),
+				    &out_insnp->expr.X_add_number);
 			out_insnp->imm_oprnd_size = 2;
 			break;
 
@@ -2162,18 +2177,18 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
 			  if (instruction->imm_oprnd_size == SIZE_FIELD
 			      && (out_insnp->expr.X_add_number < -128
 				  || out_insnp->expr.X_add_number > 255))
-			    as_bad (_("Immediate value not in 8 bit range: %ld"),
-				    out_insnp->expr.X_add_number);
+			    cris_bad (_("Immediate value not in 8 bit range: %ld"),
+				      &out_insnp->expr.X_add_number);
 			  else if (instruction->imm_oprnd_size == SIZE_FIELD_SIGNED
 			      && (out_insnp->expr.X_add_number < -128
 				  || out_insnp->expr.X_add_number > 127))
-			    as_bad (_("Immediate value not in 8 bit signed range: %ld"),
-				    out_insnp->expr.X_add_number);
+			    cris_bad (_("Immediate value not in 8 bit signed range: %ld"),
+				      &out_insnp->expr.X_add_number);
 			  else if (instruction->imm_oprnd_size == SIZE_FIELD_UNSIGNED
 				   && (out_insnp->expr.X_add_number < 0
 				       || out_insnp->expr.X_add_number > 255))
-			    as_bad (_("Immediate value not in 8 bit unsigned range: %ld"),
-				    out_insnp->expr.X_add_number);
+			    cris_bad (_("Immediate value not in 8 bit unsigned range: %ld"),
+				      &out_insnp->expr.X_add_number);
 			}
 
 		      /* Fall through.  */
@@ -2183,18 +2198,18 @@ cris_process_instruction (char *insn_text, struct cris_instruction *out_insnp,
 			  if (instruction->imm_oprnd_size == SIZE_FIELD
 			      && (out_insnp->expr.X_add_number < -32768
 				  || out_insnp->expr.X_add_number > 65535))
-			    as_bad (_("Immediate value not in 16 bit range: %ld"),
-				    out_insnp->expr.X_add_number);
+			    cris_bad (_("Immediate value not in 16 bit range: %ld"),
+				      &out_insnp->expr.X_add_number);
 			  else if (instruction->imm_oprnd_size == SIZE_FIELD_SIGNED
 			      && (out_insnp->expr.X_add_number < -32768
 				  || out_insnp->expr.X_add_number > 32767))
-			    as_bad (_("Immediate value not in 16 bit signed range: %ld"),
-				    out_insnp->expr.X_add_number);
+			    cris_bad (_("Immediate value not in 16 bit signed range: %ld"),
+				      &out_insnp->expr.X_add_number);
 			  else if (instruction->imm_oprnd_size == SIZE_FIELD_UNSIGNED
 			      && (out_insnp->expr.X_add_number < 0
 				  || out_insnp->expr.X_add_number > 65535))
-			    as_bad (_("Immediate value not in 16 bit unsigned range: %ld"),
-				    out_insnp->expr.X_add_number);
+			    cris_bad (_("Immediate value not in 16 bit unsigned range: %ld"),
+				      &out_insnp->expr.X_add_number);
 			}
 		      out_insnp->imm_oprnd_size = 2;
 		      break;

diff --git a/gas/testsuite/gas/cris/range-err-3.s b/gas/testsuite/gas/cris/range-err-3.s
new file mode 100644
index 0000000..601b24f
--- /dev/null
+++ b/gas/testsuite/gas/cris/range-err-3.s
@@ -0,0 +1,10 @@
+; Test more error cases for constant ranges.
+
+;  { dg-do assemble { target cris-*-* } }
+
+ .text
+start:
+ asrq 63,$r0 ; { dg-error "mmediate value not in 5 bit unsigned range: 63" }
+ move 65536,$p0 ; { dg-error "mmediate value not in 8 bit range: 65536" }
+ move 65536,$p5 ; { dg-error "mmediate value not in 16 bit range: 65536" }
+ bdap.b 65536,$r0 ; { dg-error "mmediate value not in 8 bit signed range: 65536" }

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

* Re: Run write_object_file after errors
  2014-06-16  3:50 ` Run write_object_file after errors Alan Modra
@ 2014-06-27  3:21   ` Alan Modra
  2014-06-27  8:01     ` Tristan Gingold
  0 siblings, 1 reply; 16+ messages in thread
From: Alan Modra @ 2014-06-27  3:21 UTC (permalink / raw)
  To: binutils; +Cc: Tristan Gingold

On Mon, Jun 16, 2014 at 01:20:08PM +0930, Alan Modra wrote:
> i386-darwin  +FAIL: gas/mach-o/err-syms-3.s (test for excess errors)

This fixes the above.  OK Tristan?

    	* config/obj-macho.c (obj_mach_o_set_symbol_qualifier): Don't set
    	SYM_MACHO_FIELDS_NOT_VALIDATED after reporting an error.
    	(obj_mach_o_frob_label): Avoid cascading errors.
    	(obj_mach_o_frob_symbol): Don't set SYM_MACHO_FIELDS_NOT_VALIDATED.

diff --git a/gas/config/obj-macho.c b/gas/config/obj-macho.c
index ec29847..fcf1729 100644
--- a/gas/config/obj-macho.c
+++ b/gas/config/obj-macho.c
@@ -1013,7 +1013,6 @@ obj_mach_o_set_symbol_qualifier (symbolS *sym, int type)
   bfd_mach_o_asymbol *s = (bfd_mach_o_asymbol *) symbol_get_bfdsym (sym);
   bfd_mach_o_section *sec;
   int sectype = -1;
-  int err = 0;
 
   /* If the symbol is defined, then we can do more rigorous checking on
      the validity of the qualifiers.  Otherwise, we are stuck with waiting 
@@ -1041,7 +1040,8 @@ obj_mach_o_set_symbol_qualifier (symbolS *sym, int type)
 	    as_bad (_("'%s' previously declared as '%s'."), s->symbol.name,
 		      (s->n_type & BFD_MACH_O_N_PEXT) ? "private extern"
 						      : "global" );
-	    err = 1;
+	    s->symbol.udata.i = SYM_MACHO_FIELDS_UNSET;
+	    return 1;
 	  }
 	else
 	  {
@@ -1092,7 +1092,8 @@ obj_mach_o_set_symbol_qualifier (symbolS *sym, int type)
 	    as_bad (_("'%s' can't be a weak_definition (currently only"
 		      " supported in sections of type coalesced)"),
 		      s->symbol.name);
-	    err = 1;
+	    s->symbol.udata.i = SYM_MACHO_FIELDS_UNSET;
+	    return 1;
 	  }
 	else
 	  s->n_desc |= BFD_MACH_O_N_WEAK_DEF;
@@ -1111,7 +1112,7 @@ obj_mach_o_set_symbol_qualifier (symbolS *sym, int type)
     /* We've seen some kind of qualifier - check validity if or when the entity
      is defined.  */
   s->symbol.udata.i = SYM_MACHO_FIELDS_NOT_VALIDATED;
-  return err;
+  return 0;
 }
 
 /* Respond to symbol qualifiers.
@@ -1409,8 +1410,12 @@ void obj_mach_o_frob_label (struct symbol *sp)
     {
       if ((s->n_desc & BFD_MACH_O_N_WEAK_DEF)
 	  && sectype != BFD_MACH_O_S_COALESCED)
-	as_bad (_("'%s' can't be a weak_definition (currently only supported"
-		  " in sections of type coalesced)"), s->symbol.name);
+	{
+	  as_bad (_("'%s' can't be a weak_definition (currently only supported"
+		    " in sections of type coalesced)"), s->symbol.name);
+	  /* Don't cascade errors.  */
+	  s->symbol.udata.i = SYM_MACHO_FIELDS_UNSET;
+	}
 
       /* Have we changed from an undefined to defined ref? */
       s->n_desc &= ~(REFE | LAZY);
@@ -1480,7 +1485,6 @@ obj_mach_o_frob_symbol (struct symbol *sp)
     {
       /* Anything here that should be added that is non-standard.  */
       s->n_desc &= ~BFD_MACH_O_REFERENCE_MASK;
-      s->symbol.udata.i = SYM_MACHO_FIELDS_NOT_VALIDATED;
     }    
   else if (s->symbol.udata.i == SYM_MACHO_FIELDS_NOT_VALIDATED)
     {

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: Run write_object_file after errors
  2014-06-27  3:21   ` Alan Modra
@ 2014-06-27  8:01     ` Tristan Gingold
  0 siblings, 0 replies; 16+ messages in thread
From: Tristan Gingold @ 2014-06-27  8:01 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils


On 27 Jun 2014, at 05:21, Alan Modra <amodra@gmail.com> wrote:

> On Mon, Jun 16, 2014 at 01:20:08PM +0930, Alan Modra wrote:
>> i386-darwin  +FAIL: gas/mach-o/err-syms-3.s (test for excess errors)
> 
> This fixes the above.  OK Tristan?
> 
>    	* config/obj-macho.c (obj_mach_o_set_symbol_qualifier): Don't set
>    	SYM_MACHO_FIELDS_NOT_VALIDATED after reporting an error.
>    	(obj_mach_o_frob_label): Avoid cascading errors.
>    	(obj_mach_o_frob_symbol): Don't set SYM_MACHO_FIELDS_NOT_VALIDATED.

That's ok.

Tristan.

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

end of thread, other threads:[~2014-06-27  8:01 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-14  0:48 testsuite results with MALLOC_PERTURB_=1 Alan Modra
2014-06-16  3:37 ` Fix uninitialised CRIS insn Alan Modra
2014-06-16  5:12   ` Hans-Peter Nilsson
2014-06-16  7:40     ` Alan Modra
2014-06-16 13:32       ` Hans-Peter Nilsson
2014-06-16 23:04         ` Hans-Peter Nilsson
2014-06-16  3:39 ` Fix uninitialised ARM data Alan Modra
2014-06-16  3:40 ` Fix uninitialised VAX .got and .got.plt section Alan Modra
2014-06-16  3:42 ` Fix uninitialised VAX insn Alan Modra
2014-06-16  3:43 ` Fix TIC54X buffer overruns Alan Modra
2014-06-16  3:44 ` Fix unintitialised TIC6X data Alan Modra
2014-06-16  3:45 ` Report an error on x86 pcrel BFD_RELOC_SIZE64 Alan Modra
2014-06-16  3:46 ` Don't leave DLX the_insn uninitialised Alan Modra
2014-06-16  3:50 ` Run write_object_file after errors Alan Modra
2014-06-27  3:21   ` Alan Modra
2014-06-27  8:01     ` Tristan Gingold

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