Subject: toolchain/17312: Gas in the new toolchain won't build for the pc532
To: None <gnats-bugs@gnats.netbsd.org>
From: Ian Dall <Ian.Dall@dsto.defence.gov.au>
List: netbsd-bugs
Date: 06/19/2002 16:10:26
>Number:         17312
>Category:       toolchain
>Synopsis:       Gas in the new toolchain won't build for the pc532
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 18 23:51:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Ian Dall
>Release:        NetBSD 1.5ZC
>Organization:
private
>Environment:
	
	
System: NetBSD gateway.beware.dropbear.id.au 1.5ZC NetBSD 1.5ZC (SIBYL) #2: Sat Jun 15 00:22:45 CST 2002 ian@sibyl.beware.dropbear.id.au:/usr1/local/src/netbsd/src/sys/arch/pc532/compile/SIBYL pc532
Architecture: ns32k
Machine: pc532
>Description:
	
If USE_NEW_TOOLCHAIN is set, gas won't build for the pc532. Also there are
many compile-time warnings.
>How-To-Repeat:
	

USE_NEW_TOOLCHAIN=yes ./build.sh -m pc532

>Fix:
	
The following patch allows gas to build, at least without PIC support. Further
support is required to get PIC to work.

Index: netbsd/src/gnu/dist/toolchain/gas/config/tc-ns32k.c
diff -c netbsd/src/gnu/dist/toolchain/gas/config/tc-ns32k.c:1.1.1.1 netbsd/src/gnu/dist/toolchain/gas/config/tc-ns32k.c:1.2
*** netbsd/src/gnu/dist/toolchain/gas/config/tc-ns32k.c:1.1.1.1	Sun Nov 25 23:56:58 2001
--- netbsd/src/gnu/dist/toolchain/gas/config/tc-ns32k.c	Fri Jun  7 16:31:16 2002
***************
*** 72,79 ****
  
  struct addr_mode
    {
!     char mode;			/* addressing mode of operand (0-31) */
!     char scaled_mode;		/* mode combined with scaled mode */
      char scaled_reg;		/* register used in scaled+1 (1-8) */
      char float_flag;		/* set if R0..R7 was F0..F7 ie a
  				   floating-point-register */
--- 72,79 ----
  
  struct addr_mode
    {
!     signed char mode;		/* addressing mode of operand (0-31) */
!     signed char scaled_mode;	/* mode combined with scaled mode */
      char scaled_reg;		/* register used in scaled+1 (1-8) */
      char float_flag;		/* set if R0..R7 was F0..F7 ie a
  				   floating-point-register */
***************
*** 391,397 ****
  
     Out: data in addr_mode struct.  */
  
! int
  addr_mode (operand, addr_modeP, recursive_level)
       char *operand;
       register addr_modeS *addr_modeP;
--- 391,397 ----
  
     Out: data in addr_mode struct.  */
  
! static int
  addr_mode (operand, addr_modeP, recursive_level)
       char *operand;
       register addr_modeS *addr_modeP;
***************
*** 671,677 ****
     specifying suffixes and determines size of immediate mode via
     ns32k-opcode.  Also builds index bytes if needed.  */
  
! int
  get_addr_mode (ptr, addr_modeP)
       char *ptr;
       addr_modeS *addr_modeP;
--- 671,677 ----
     specifying suffixes and determines size of immediate mode via
     ns32k-opcode.  Also builds index bytes if needed.  */
  
! static int
  get_addr_mode (ptr, addr_modeP)
       char *ptr;
       addr_modeS *addr_modeP;
***************
*** 712,718 ****
       case.  Think it does so with local labels too, not optimum, pcrel
       is better.  When I have time I will make gas check this and
       select pcrel when possible Actually that is trivial.  */
!   if (tmp = addr_modeP->scaled_reg)
      {				/* Build indexbyte.  */
        tmp--;			/* Remember regnumber comes incremented for
  				   flagpurpose.  */
--- 712,718 ----
       case.  Think it does so with local labels too, not optimum, pcrel
       is better.  When I have time I will make gas check this and
       select pcrel when possible Actually that is trivial.  */
!   if ((tmp = addr_modeP->scaled_reg))
      {				/* Build indexbyte.  */
        tmp--;			/* Remember regnumber comes incremented for
  				   flagpurpose.  */
***************
*** 721,727 ****
        addr_modeP->am_size += 1;
      }
  
!   if (disp_test[addr_modeP->mode])
      {
        register char c;
        register char suffix;
--- 721,728 ----
        addr_modeP->am_size += 1;
      }
  
!   assert (addr_modeP->mode >= 0); 
!   if (disp_test[(unsigned int) addr_modeP->mode])
      {
        register char c;
        register char suffix;
***************
*** 733,739 ****
        /* There was a displacement, probe for length  specifying suffix.  */
        addr_modeP->pcrel = 0;
  
!       if (disp_test[addr_modeP->mode])
  	{
  	  /* There is a displacement.  */
  	  if (addr_modeP->mode == 27 || addr_modeP->scaled_mode == 27)
--- 734,741 ----
        /* There was a displacement, probe for length  specifying suffix.  */
        addr_modeP->pcrel = 0;
  
!       assert(addr_modeP->mode >= 0);
!       if (disp_test[(unsigned int) addr_modeP->mode])
  	{
  	  /* There is a displacement.  */
  	  if (addr_modeP->mode == 27 || addr_modeP->scaled_mode == 27)
***************
*** 746,757 ****
  	    {
  	      suffix_sub = suffix = 0;
  
! 	      if (toP = addr_modeP->disp[i])
  		{
  		  /* Suffix of expression, the largest size rules.  */
  		  fromP = toP;
  
! 		  while (c = *fromP++)
  		    {
  		      *toP++ = c;
  		      if (c == ':')
--- 748,759 ----
  	    {
  	      suffix_sub = suffix = 0;
  
! 	      if ((toP = addr_modeP->disp[i]))
  		{
  		  /* Suffix of expression, the largest size rules.  */
  		  fromP = toP;
  
! 		  while ((c = *fromP++))
  		    {
  		      *toP++ = c;
  		      if (c == ':')
***************
*** 806,812 ****
  
  /* Read an optionlist.  */
  
! void
  optlist (str, optionP, default_map)
       char *str;			/* The string to extract options from.  */
       struct ns32k_option *optionP;	/* How to search the string.  */
--- 808,814 ----
  
  /* Read an optionlist.  */
  
! static void
  optlist (str, optionP, default_map)
       char *str;			/* The string to extract options from.  */
       struct ns32k_option *optionP;	/* How to search the string.  */
***************
*** 849,855 ****
     the instructions lmr, smr, lpr, spr return true if str is found in
     list.  */
  
! int
  list_search (str, optionP, default_map)
       char *str;				/* The string to match.  */
       struct ns32k_option *optionP;	/* List to search.  */
--- 851,857 ----
     the instructions lmr, smr, lpr, spr return true if str is found in
     list.  */
  
! static int
  list_search (str, optionP, default_map)
       char *str;				/* The string to match.  */
       struct ns32k_option *optionP;	/* List to search.  */
***************
*** 882,888 ****
  
    tmp_line = input_line_pointer;
    input_line_pointer = ptr;
!   expression (&exprP);
    input_line_pointer = tmp_line;
  }
  
--- 884,890 ----
  
    tmp_line = input_line_pointer;
    input_line_pointer = ptr;
!   expression (resultP);
    input_line_pointer = tmp_line;
  }
  
***************
*** 892,898 ****
     opcode.
     Be carefull not to put to objects in the same iif-slot.  */
  
! void
  encode_operand (argc, argv, operandsP, suffixP, im_size, opcode_bit_ptr)
       int argc;
       char **argv;
--- 894,900 ----
     opcode.
     Be carefull not to put to objects in the same iif-slot.  */
  
! static void
  encode_operand (argc, argv, operandsP, suffixP, im_size, opcode_bit_ptr)
       int argc;
       char **argv;
***************
*** 975,981 ****
  
  	case 'b':		/* multiple instruction disp */
  	  freeptr++;		/* OVE:this is an useful hack */
! 	  sprintf (freeptr, "((%s-1)*%d)\000", argv[i], desc->im_size);
  	  argv[i] = freeptr;
  	  pcrel -= 1;		/* make pcrel 0 inspite of what case 'p':
  				   wants */
--- 977,983 ----
  
  	case 'b':		/* multiple instruction disp */
  	  freeptr++;		/* OVE:this is an useful hack */
! 	  sprintf (freeptr, "((%s-1)*%d)", argv[i], desc->im_size);
  	  argv[i] = freeptr;
  	  pcrel -= 1;		/* make pcrel 0 inspite of what case 'p':
  				   wants */
***************
*** 1077,1090 ****
     Return-value = recursive_level.    */
  /* Build iif of one assembly text line.  */
  
! int
  parse (line, recursive_level)
       char *line;
       int recursive_level;
  {
    register char *lineptr, c, suffix_separator;
    register int i;
!   int argc, arg_type;
    char sqr, sep;
    char suffix[MAX_ARGS], *argv[MAX_ARGS];	/* No more than 4 operands.  */
  
--- 1079,1093 ----
     Return-value = recursive_level.    */
  /* Build iif of one assembly text line.  */
  
! static int
  parse (line, recursive_level)
       char *line;
       int recursive_level;
  {
    register char *lineptr, c, suffix_separator;
    register int i;
!   unsigned int argc;
!   int arg_type;
    char sqr, sep;
    char suffix[MAX_ARGS], *argv[MAX_ARGS];	/* No more than 4 operands.  */
  
***************
*** 1269,1275 ****
     objects not part of an instruction, the pointer to the opcode frag
     is always zero.  */
  
! void
  convert_iif ()
  {
    int i;
--- 1272,1278 ----
     objects not part of an instruction, the pointer to the opcode frag
     is always zero.  */
  
! static void
  convert_iif ()
  {
    int i;
***************
*** 1282,1288 ****
    int k;
    char type;
    char size = 0;
-   int size_so_far;
  
    memP = frag_more (0);
    inst_opcode = memP;
--- 1285,1290 ----
***************
*** 1291,1304 ****
  
    for (i = 0; i < IIF_ENTRIES; i++)
      {
!       if (type = iif.iifP[i].type)
  	{
  	  /* The object exist, so handle it.  */
! 	  unsigned int reloc_mode;
  	  if ((i == 4 || i == 6)
  	      && aout_pic_flag
  	      && (iif.iifP[i].addr_mode == 18 || iif.iifP[i].addr_mode == 26))
! 	     reloc_mode = BFD_RELOC_NS32K_GLOB_DAT;
  	  else
  	     reloc_mode = NO_RELOC;
  
--- 1293,1312 ----
  
    for (i = 0; i < IIF_ENTRIES; i++)
      {
!       if ((type = iif.iifP[i].type))
  	{
  	  /* The object exist, so handle it.  */
! 	  unsigned int reloc_mode = 0;
  	  if ((i == 4 || i == 6)
  	      && aout_pic_flag
  	      && (iif.iifP[i].addr_mode == 18 || iif.iifP[i].addr_mode == 26))
! 	    {
! #ifdef BFD_RELOC_NS32K_GLOB_DAT
! 	      reloc_mode = BFD_RELOC_NS32K_GLOB_DAT;
! #else
! 	      as_fatal(_("PIC not yet supported."));
! #endif
! 	    }
  	  else
  	     reloc_mode = NO_RELOC;
  
***************
*** 1465,1470 ****
--- 1473,1479 ----
  		if ((exprP.X_add_symbol || exprP.X_op_symbol) &&
  		    !iif.iifP[i].pcrel)
  		  {
+ #ifdef BFD_RELOC_NS32K_GLOB_DAT
  		    if (reloc_mode == BFD_RELOC_NS32K_GLOB_DAT
  		    	&& got_offset_size == 2)
  		      {
***************
*** 1472,1477 ****
--- 1481,1487 ----
  		        size = 2;
  		      }
  		    else
+ #endif
  		      {
  			/* Size is unknown until link time so have to
  			   allow 4 bytes.  */
***************
*** 1614,1620 ****
  
    index = length + 3 * pcrel + 6 * type;
  
!   if (index >= 0 && index < sizeof (relocs) / sizeof (relocs[0]))
      return relocs[index];
  
    if (pcrel)
--- 1624,1630 ----
  
    index = length + 3 * pcrel + 6 * type;
  
!   if (index >= 0 && (unsigned int) index < sizeof (relocs) / sizeof (relocs[0]))
      return relocs[index];
  
    if (pcrel)
***************
*** 1784,1790 ****
        *buf++ = val;
        break;
      default:
!       as_fatal (_("Internal logic error.  line %s, file \"%s\""),
  		__LINE__, __FILE__);
      }
  }
--- 1794,1800 ----
        *buf++ = val;
        break;
      default:
!       as_fatal (_("Internal logic error.  line %d, file \"%s\""),
  		__LINE__, __FILE__);
      }
  }
***************
*** 1832,1838 ****
        *buf++ = val;
        break;
      default:
!       as_fatal (_("Internal logic error. line %s, file \"%s\""),
  		__LINE__, __FILE__);
      }
  }
--- 1842,1848 ----
        *buf++ = val;
        break;
      default:
!       as_fatal (_("Internal logic error. line %d, file \"%s\""),
  		__LINE__, __FILE__);
      }
  }
***************
*** 1958,1968 ****
    return fragP->fr_address + fragP->fr_fix - opcode_address;
  }
  
! int
  md_fix_pcrel_adjust (fixP)
       fixS *fixP;
  {
-   fragS *fragP = fixP->fx_frag;
    fragS *opcode_frag;
    addressT opcode_address;
    unsigned int offset;
--- 1968,1977 ----
    return fragP->fr_address + fragP->fr_fix - opcode_address;
  }
  
! static int
  md_fix_pcrel_adjust (fixP)
       fixS *fixP;
  {
    fragS *opcode_frag;
    addressT opcode_address;
    unsigned int offset;
***************
*** 1999,2005 ****
  #ifdef BFD_ASSEMBLER
    long val = *valp;
  #endif
-   fragS *fragP = fixP->fx_frag;
  
    char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
  
--- 2008,2013 ----
***************
*** 2027,2033 ****
  	md_number_to_chars (buf, val, fixP->fx_size);
  	break;
        }
! #ifdef BSD_ASSEMBLER
    return 1;
  #endif
  }
--- 2035,2041 ----
  	md_number_to_chars (buf, val, fixP->fx_size);
  	break;
        }
! #ifdef BFD_ASSEMBLER
    return 1;
  #endif
  }
***************
*** 2055,2062 ****
    register char *buffer_address = fragP->fr_fix + fragP->fr_literal;
    /* Address in object code of the displacement.  */
    int object_address;
- 
-   fragS *opcode_frag;
  
    switch (fragP->fr_subtype)
      {
--- 2063,2068 ----
Index: netbsd/src/gnu/dist/toolchain/gas/config/tc-ns32k.h
diff -c netbsd/src/gnu/dist/toolchain/gas/config/tc-ns32k.h:1.1.1.1 netbsd/src/gnu/dist/toolchain/gas/config/tc-ns32k.h:1.2
*** netbsd/src/gnu/dist/toolchain/gas/config/tc-ns32k.h:1.1.1.1	Sun Nov 25 23:56:58 2001
--- netbsd/src/gnu/dist/toolchain/gas/config/tc-ns32k.h	Fri Jun  7 16:31:16 2002
***************
*** 24,29 ****
--- 24,31 ----
  #define TARGET_BYTES_BIG_ENDIAN	0
  
  #define TC_PCREL_ADJUST(F) md_pcrel_adjust(F)
+ extern int md_pcrel_adjust PARAMS((fragS *fragP));
+ 
  
  #ifdef BFD_ASSEMBLER
  #define NO_RELOC BFD_RELOC_NONE
Index: netbsd/src/gnu/dist/toolchain/gas/config/te-nbsd532.h
diff -c netbsd/src/gnu/dist/toolchain/gas/config/te-nbsd532.h:1.1.1.1 netbsd/src/gnu/dist/toolchain/gas/config/te-nbsd532.h:1.2
*** netbsd/src/gnu/dist/toolchain/gas/config/te-nbsd532.h:1.1.1.1	Sun Nov 25 23:56:58 2001
--- netbsd/src/gnu/dist/toolchain/gas/config/te-nbsd532.h	Fri Jun  7 16:49:10 2002
***************
*** 2,13 ****
     Written by Ian Dall <idall@eleceng.adelaide.edu.au>
     19-Jun-94.  */
  
- #define TARGET_FORMAT		"a.out-ns32k-netbsd"
- 
- #include "obj-format.h"
- 
  /* Maybe these should be more like TC_NS32532 and TC_NS32381 in case
     of conflicts. NS32381 is used in opcode/ns32k.h and that is also
     used by GDB. Need to check.  */
  #define NS32532
  #define NS32381
--- 2,11 ----
     Written by Ian Dall <idall@eleceng.adelaide.edu.au>
     19-Jun-94.  */
  
  /* Maybe these should be more like TC_NS32532 and TC_NS32381 in case
     of conflicts. NS32381 is used in opcode/ns32k.h and that is also
     used by GDB. Need to check.  */
  #define NS32532
  #define NS32381
+ 
+ #include "te-nbsd.h"
Index: netbsd/src/gnu/usr.bin/Makefile
diff -c netbsd/src/gnu/usr.bin/Makefile:1.1.1.3 netbsd/src/gnu/usr.bin/Makefile:1.2
>Release-Note:
>Audit-Trail:
>Unformatted: