This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Fixes to dlltool


Hi Guys,

  I have applied the patch below to dlltool.  It fixes a bug whereby
  if the --machine command line switch was used to select a target
  other than the default target, the tool would still create output
  files in the default target format.

  The patch also adds an extra field to the mac structure to allow
  target machine formats to specify default switches to be passed to
  the assembler when creating files for that format.  This is then
  used by the little endian mcore target to pass the -EL switch on to
  the asembler and by the thumb target to pass on
  -mthumb-interworking.  These switches can still be overridden by the
  --as-flags command line switch, if necessary.

Cheers
	Nick


1999-10-22  Nick Clifton  <nickc@cygnus.com>

	* dlltool.c (struct mac): Add new field 'how_default_as_switches'.
	(mtable): Initialise new field.  Some machines have a non empty
	string for this field.
	(HOW_BFD_TARGET): Undefine and replace with...
	(HOW_BFD_READ_TARGET): New macro: bfd target to use when opening a
	file for reading.  This is set to 0 so that any recognisable bfd
	format can be read.
	(HOW_BFD_WRITE_TARGET): New macro: bfd target to use when opening
	a file for writing.  This is set to the target machine type.
	(ASM_SWITCHES): New macro: default switches to use when assembling
	a file.
	(assemble_file): New function: Assemble a source file into a
	destination object file.
	(gen_exp_file): Use assemble_file to create the exp file.
	(make_one_lib_file): Use assemble_file to create the lib file.
	Open output file use HOW_BFD_WRITE_TARGET and input files using
	HOW_BFD_READ_TARGET.
	(make_head): Use assemble_file to create the head file.
	(make_tail): Use assemble_file to create the tail file.
	(gen_lib_file): Open output file use HOW_BFD_WRITE_TARGET.

Index: dlltool.c
===================================================================
RCS file: /cvs/binutils/binutils/binutils/dlltool.c,v
retrieving revision 1.12
diff -p -r1.12 dlltool.c
*** dlltool.c	1999/09/28 20:08:37	1.12
--- dlltool.c	1999/10/22 15:42:07
*************** struct mac
*** 497,502 ****
--- 497,503 ----
      const char *how_space;
      const char *how_align_short;
      const char *how_align_long;
+     const char *how_default_as_switches;
      const char *how_bfd_target;
      enum bfd_architecture how_bfd_arch;
      const unsigned char *how_jtab;
*************** mtable[] =
*** 511,537 ****
  #define MARM 0
      "arm", ".byte", ".short", ".long", ".asciz", "@",
      "ldr\tip,[pc]\n\tldr\tpc,[ip]\n\t.long",
!     ".global", ".space", ".align\t2",".align\t4","pe-arm-little", bfd_arch_arm,
      arm_jtab, sizeof (arm_jtab), 8
    }
    ,
    {
  #define M386 1
!     "i386", ".byte", ".short", ".long", ".asciz", "#", "jmp *", ".global", ".space", ".align\t2",".align\t4","pe-i386",bfd_arch_i386,
!    i386_jtab, sizeof (i386_jtab), 2
    }
    ,
    {
  #define MPPC 2
!     "ppc", ".byte", ".short", ".long", ".asciz", "#", "jmp *", ".global", ".space", ".align\t2",".align\t4","pe-powerpcle",bfd_arch_powerpc,
!    ppc_jtab, sizeof (ppc_jtab), 0
    }
    ,
    {
  #define MTHUMB 3
      "thumb", ".byte", ".short", ".long", ".asciz", "@",
      "push\t{r6}\n\tldr\tr6, [pc, #8]\n\tldr\tr6, [r6]\n\tmov\tip, r6\n\tpop\t{r6}\n\tbx\tip",
!     ".global", ".space", ".align\t2",".align\t4","pe-arm-little", bfd_arch_arm,
      thumb_jtab, sizeof (thumb_jtab), 12
    }
    ,
--- 512,544 ----
  #define MARM 0
      "arm", ".byte", ".short", ".long", ".asciz", "@",
      "ldr\tip,[pc]\n\tldr\tpc,[ip]\n\t.long",
!     ".global", ".space", ".align\t2",".align\t4", "",
!     "pe-arm-little", bfd_arch_arm,
      arm_jtab, sizeof (arm_jtab), 8
    }
    ,
    {
  #define M386 1
!     "i386", ".byte", ".short", ".long", ".asciz", "#",
!     "jmp *", ".global", ".space", ".align\t2",".align\t4", "",
!     "pe-i386",bfd_arch_i386,
!     i386_jtab, sizeof (i386_jtab), 2
    }
    ,
    {
  #define MPPC 2
!     "ppc", ".byte", ".short", ".long", ".asciz", "#",
!     "jmp *", ".global", ".space", ".align\t2",".align\t4", "",
!     "pe-powerpcle",bfd_arch_powerpc,
!     ppc_jtab, sizeof (ppc_jtab), 0
    }
    ,
    {
  #define MTHUMB 3
      "thumb", ".byte", ".short", ".long", ".asciz", "@",
      "push\t{r6}\n\tldr\tr6, [pc, #8]\n\tldr\tr6, [r6]\n\tmov\tip, r6\n\tpop\t{r6}\n\tbx\tip",
!     ".global", ".space", ".align\t2",".align\t4", "=mthumb-interwork",
!     "pe-arm-little", bfd_arch_arm,
      thumb_jtab, sizeof (thumb_jtab), 12
    }
    ,
*************** mtable[] =
*** 539,545 ****
    {
      "arm_interwork", ".byte", ".short", ".long", ".asciz", "@",
      "ldr\tip,[pc]\n\tldr\tip,[ip]\n\tbx\tip\n\t.long",
!     ".global", ".space", ".align\t2",".align\t4","pe-arm-little", bfd_arch_arm,
      arm_interwork_jtab, sizeof (arm_interwork_jtab), 12
    }
    ,
--- 546,553 ----
    {
      "arm_interwork", ".byte", ".short", ".long", ".asciz", "@",
      "ldr\tip,[pc]\n\tldr\tip,[ip]\n\tbx\tip\n\t.long",
!     ".global", ".space", ".align\t2",".align\t4", "-mthumb-interwork",
!     "pe-arm-little", bfd_arch_arm,
      arm_interwork_jtab, sizeof (arm_interwork_jtab), 12
    }
    ,
*************** mtable[] =
*** 547,553 ****
  #define MMCORE_BE 5
      "mcore", ".byte", ".short", ".long", ".asciz", "//",
      "jmpi\t1\n\tnop\n\t.long",
!     ".global", ".space", ".align\t2",".align\t4","pe-mcore-big", bfd_arch_mcore,
      mcore_be_jtab, sizeof (mcore_be_jtab), 8
    }
    ,
--- 555,562 ----
  #define MMCORE_BE 5
      "mcore", ".byte", ".short", ".long", ".asciz", "//",
      "jmpi\t1\n\tnop\n\t.long",
!     ".global", ".space", ".align\t2",".align\t4", "",
!     "pe-mcore-big", bfd_arch_mcore,
      mcore_be_jtab, sizeof (mcore_be_jtab), 8
    }
    ,
*************** mtable[] =
*** 555,561 ****
  #define MMCORE_LE 6
      "mcore-le", ".byte", ".short", ".long", ".asciz", "//",
      "jmpi\t1\n\tnop\n\t.long",
!     ".global", ".space", ".align\t2",".align\t4","pe-mcore-little", bfd_arch_mcore,
      mcore_le_jtab, sizeof (mcore_le_jtab), 8
    }
    ,
--- 564,571 ----
  #define MMCORE_LE 6
      "mcore-le", ".byte", ".short", ".long", ".asciz", "//",
      "jmpi\t1\n\tnop\n\t.long",
!     ".global", ".space", ".align\t2",".align\t4", "-EL",
!     "pe-mcore-little", bfd_arch_mcore,
      mcore_le_jtab, sizeof (mcore_le_jtab), 8
    }
    ,
*************** mtable[] =
*** 563,569 ****
  #define MMCORE_ELF 7
      "mcore-elf", ".byte", ".short", ".long", ".asciz", "//",
      "jmpi\t1\n\tnop\n\t.long",
!     ".global", ".space", ".align\t2",".align\t4","elf32-mcore-big", bfd_arch_mcore,
      mcore_be_jtab, sizeof (mcore_be_jtab), 8
    }
    ,
--- 573,580 ----
  #define MMCORE_ELF 7
      "mcore-elf", ".byte", ".short", ".long", ".asciz", "//",
      "jmpi\t1\n\tnop\n\t.long",
!     ".global", ".space", ".align\t2",".align\t4", "",
!     "elf32-mcore-big", bfd_arch_mcore,
      mcore_be_jtab, sizeof (mcore_be_jtab), 8
    }
    ,
*************** mtable[] =
*** 571,581 ****
  #define MMCORE_ELF_LE 8
      "mcore-elf-le", ".byte", ".short", ".long", ".asciz", "//",
      "jmpi\t1\n\tnop\n\t.long",
!     ".global", ".space", ".align\t2",".align\t4","elf32-mcore-little", bfd_arch_mcore,
      mcore_le_jtab, sizeof (mcore_le_jtab), 8
    }
    ,
!  {    0}
  };
  
  typedef struct dlist
--- 582,593 ----
  #define MMCORE_ELF_LE 8
      "mcore-elf-le", ".byte", ".short", ".long", ".asciz", "//",
      "jmpi\t1\n\tnop\n\t.long",
!     ".global", ".space", ".align\t2",".align\t4", "-EL",
!     "elf32-mcore-little", bfd_arch_mcore,
      mcore_le_jtab, sizeof (mcore_le_jtab), 8
    }
    ,
!   { 0 }
  };
  
  typedef struct dlist
*************** asm_prefix (machine)
*** 798,808 ****
  #define ASM_RVA_AFTER  	rvaafter(machine)
  #define ASM_PREFIX	asm_prefix(machine)
  #define ASM_ALIGN_LONG  mtable[machine].how_align_long
! #define HOW_BFD_TARGET  0  /* always default*/
  #define HOW_BFD_ARCH    mtable[machine].how_bfd_arch
  #define HOW_JTAB        mtable[machine].how_jtab
  #define HOW_JTAB_SIZE   mtable[machine].how_jtab_size
  #define HOW_JTAB_ROFF   mtable[machine].how_jtab_roff
  static char **oav;
  
  void
--- 810,823 ----
  #define ASM_RVA_AFTER  	rvaafter(machine)
  #define ASM_PREFIX	asm_prefix(machine)
  #define ASM_ALIGN_LONG  mtable[machine].how_align_long
! #define HOW_BFD_READ_TARGET  0  /* always default*/
! #define HOW_BFD_WRITE_TARGET mtable[machine].how_bfd_target
  #define HOW_BFD_ARCH    mtable[machine].how_bfd_arch
  #define HOW_JTAB        mtable[machine].how_jtab
  #define HOW_JTAB_SIZE   mtable[machine].how_jtab_size
  #define HOW_JTAB_ROFF   mtable[machine].how_jtab_roff
+ #define ASM_SWITCHES    mtable[machine].how_default_as_switches
+ 
  static char **oav;
  
  void
*************** generate_idata_ofile (filvar)
*** 1716,1729 ****
      }
  }
  
  static void
  gen_exp_file ()
  {
    FILE *f;
    int i;
    export_type *exp;
    dlist_type *dl;
-   char *cmd;
  
    /* xgettext:c-format */
    inform (_("Generating export file: %s\n"), exp_name);
--- 1731,1760 ----
      }
  }
  
+ /* Assemble the specified file. */
  static void
+ assemble_file (source, dest)
+      const char * source;
+      const char * dest;
+ {
+   char * cmd;
+   
+   cmd = (char *) alloca (strlen (ASM_SWITCHES) + strlen (as_flags)
+ 			 + strlen (exp_name) + strlen (source)
+ 			 + strlen (dest) + 50);
+ 
+   sprintf (cmd, "%s %s -o %s %s", ASM_SWITCHES, as_flags, dest, source);
+ 
+   run (as_name, cmd);
+ }
+ 
+ static void
  gen_exp_file ()
  {
    FILE *f;
    int i;
    export_type *exp;
    dlist_type *dl;
  
    /* xgettext:c-format */
    inform (_("Generating export file: %s\n"), exp_name);
*************** gen_exp_file ()
*** 1941,1957 ****
    fclose (f);
  
    /* assemble the file */
!   cmd = (char *) alloca (strlen (as_flags) + strlen (exp_name)
! 			 + sizeof TMP_ASM + 50);
!   sprintf (cmd, "%s -o %s %s", as_flags, exp_name, TMP_ASM);
! 
! #ifdef DLLTOOL_ARM
!   if (machine == MARM_INTERWORK || machine == MTHUMB)
!     strcat (cmd, " -mthumb-interwork");
! #endif
  
-   run (as_name, cmd);
- 
    if (dontdeltemps == 0)
      unlink (TMP_ASM);
    
--- 1972,1979 ----
    fclose (f);
  
    /* assemble the file */
!   assemble_file (TMP_ASM, exp_name);
  
    if (dontdeltemps == 0)
      unlink (TMP_ASM);
    
*************** make_one_lib_file (exp, i)
*** 2134,2140 ****
        char *name;
        FILE *f;
        const char *prefix = "d";
!       char *cmd;
  
        name = (char *) alloca (strlen (prefix) + 10);
        sprintf (name, "%ss%05d.s", prefix, i);
--- 2156,2162 ----
        char *name;
        FILE *f;
        const char *prefix = "d";
!       char *dest;
  
        name = (char *) alloca (strlen (prefix) + 10);
        sprintf (name, "%ss%05d.s", prefix, i);
*************** make_one_lib_file (exp, i)
*** 2172,2188 ****
  	}
  
        fclose (f);
- 
-       cmd = (char *) alloca (strlen (as_flags) + 2 * strlen (prefix) + 50);
-       sprintf (cmd, "%s -o %ss%05d.o %ss%d.s",
- 	       as_flags, prefix, i, prefix, i);
  
! #ifdef DLLTOOL_ARM
!       if (machine == MARM_INTERWORK || machine == MTHUMB)
! 	strcat (cmd, " -mthumb-interwork");
! #endif
!   
!       run (as_name, cmd);
      }
  #else /* if 0 */
      {
--- 2194,2203 ----
  	}
  
        fclose (f);
  
!       dest = (char *) alloca (strlen (prefix) + 10);
!       sprintf (dest, "%ss%05d.o", prefix, i);
!       assemble_file (name, dest);
      }
  #else /* if 0 */
      {
*************** make_one_lib_file (exp, i)
*** 2209,2215 ****
        
        sprintf (outname, "%s%05d.o", TMP_STUB, i);
        
!       abfd = bfd_openw (outname, HOW_BFD_TARGET);
        
        if (!abfd)
  	/* xgettext:c-format */
--- 2224,2230 ----
        
        sprintf (outname, "%s%05d.o", TMP_STUB, i);
        
!       abfd = bfd_openw (outname, HOW_BFD_WRITE_TARGET);
        
        if (!abfd)
  	/* xgettext:c-format */
*************** make_one_lib_file (exp, i)
*** 2586,2592 ****
  
        bfd_set_symtab (abfd, ptrs, oidx);
        bfd_close (abfd);
!       abfd = bfd_openr (outname, HOW_BFD_TARGET);
        return abfd;
      }
  #endif
--- 2601,2607 ----
  
        bfd_set_symtab (abfd, ptrs, oidx);
        bfd_close (abfd);
!       abfd = bfd_openr (outname, HOW_BFD_READ_TARGET);
        return abfd;
      }
  #endif
*************** static bfd *
*** 2596,2602 ****
  make_head ()
  {
    FILE *f = fopen (TMP_HEAD_S, FOPEN_WT);
-   char *cmd;
  
    if (f == NULL)
      {
--- 2611,2616 ----
*************** make_head ()
*** 2647,2671 ****
    
    fclose (f);
  
!   cmd = (char *) alloca (strlen (as_flags) + sizeof TMP_HEAD_O
! 			 + sizeof TMP_HEAD_S + 50);
!   sprintf (cmd, "%s -o %s %s", as_flags, TMP_HEAD_O, TMP_HEAD_S);
!   
! #ifdef DLLTOOL_ARM
!   if (machine == MARM_INTERWORK || machine == MTHUMB)
!     strcat (cmd, " -mthumb-interwork");
! #endif
!   
!   run (as_name, cmd);
  
!   return bfd_openr (TMP_HEAD_O, HOW_BFD_TARGET);
  }
  
  static bfd *
  make_tail ()
  {
    FILE *f = fopen (TMP_TAIL_S, FOPEN_WT);
-   char *cmd;
  
    if (f == NULL)
      {
--- 2661,2675 ----
    
    fclose (f);
  
!   assemble_file (TMP_HEAD_S, TMP_HEAD_O);
  
!   return bfd_openr (TMP_HEAD_O, HOW_BFD_READ_TARGET);
  }
  
  static bfd *
  make_tail ()
  {
    FILE *f = fopen (TMP_TAIL_S, FOPEN_WT);
  
    if (f == NULL)
      {
*************** make_tail ()
*** 2716,2733 ****
  
    fclose (f);
  
!   cmd = (char *) alloca (strlen (as_flags) + sizeof TMP_TAIL_O
! 			 + sizeof TMP_TAIL_S + 50);
!   sprintf (cmd, "%s -o %s %s", as_flags, TMP_TAIL_O, TMP_TAIL_S);
!   
! #ifdef DLLTOOL_ARM
!   if (machine == MARM_INTERWORK || machine == MTHUMB)
!     strcat (cmd, " -mthumb-interwork");
! #endif
!   
!   run (as_name, cmd);
    
!   return  bfd_openr (TMP_TAIL_O, HOW_BFD_TARGET);
  }
  
  static void
--- 2720,2728 ----
  
    fclose (f);
  
!   assemble_file (TMP_TAIL_S, TMP_TAIL_O);
    
!   return  bfd_openr (TMP_TAIL_O, HOW_BFD_READ_TARGET);
  }
  
  static void
*************** gen_lib_file ()
*** 2742,2748 ****
  
    unlink (imp_name);
  
!   outarch = bfd_openw (imp_name, HOW_BFD_TARGET);
  
    if (!outarch)
      /* xgettext:c-format */
--- 2737,2743 ----
  
    unlink (imp_name);
  
!   outarch = bfd_openw (imp_name, HOW_BFD_WRITE_TARGET);
  
    if (!outarch)
      /* xgettext:c-format */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]