How to change config.make_executable to FALSE from bfd?

H. J. Lu hjl@lucon.org
Fri Apr 18 04:31:00 GMT 2003


On Fri, Apr 11, 2003 at 04:34:08PM -0700, Ian Lance Taylor wrote:
> "H. J. Lu" <hjl@lucon.org> writes:
> 
> > In some cases, when bfd encounters an error, I'd like to issue a
> > message and continue without generating any output file at the end.
> > Right now, I can only issue one error message and stop. It will be
> > nice for bfd to change config.make_executable to FALSE so that no
> > output file will be created. How do I do that?
> 
> Do you have a bfd_link_info structure?  If so, use a callback in
> bfd_link_callbacks.  Add a new callback if necessary.
> 

How about this patch? It made vfinfo available to bfd.


H.J.
-------------- next part --------------
include/

2003-04-17  H.J. Lu <hjl@gnu.org>

	* bfdlink.h (bfd_link_callbacks): Add error_handler.

ld/

2003-04-17  H.J. Lu <hjl@gnu.org>

	* ldmain.c (link_callbacks): Initialize error_handler.

	* ldmisc.c (vfinfo): Support "%x" and "%l[dux]".
	(error_handler): New function.

	* ldmisc.h (error_handler): New prototype.

--- binutils/include/bfdlink.h.cb	2003-01-02 09:57:40.000000000 -0800
+++ binutils/include/bfdlink.h	2003-04-17 15:40:47.000000000 -0700
@@ -481,6 +481,11 @@ struct bfd_link_callbacks
   bfd_boolean (*notice)
     PARAMS ((struct bfd_link_info *, const char *name,
 	     bfd *abfd, asection *section, bfd_vma address));
+  /* A function which is called for reporting a linker error. ID is the
+     error identifier. The remaining input is the same as einfo () in
+     ld.  */
+  bfd_boolean (*error_handler)
+    PARAMS ((int id, const char * fmt, ...));
 };
 
 /* The linker builds link_order structures which tell the code how to
--- binutils/ld/ldmain.c.cb	2003-04-01 14:29:10.000000000 -0800
+++ binutils/ld/ldmain.c	2003-04-17 15:53:06.000000000 -0700
@@ -155,7 +155,8 @@ static struct bfd_link_callbacks link_ca
   reloc_overflow,
   reloc_dangerous,
   unattached_reloc,
-  notice
+  notice,
+  error_handler
 };
 
 struct bfd_link_info link_info;
--- binutils/ld/ldmisc.c.cb	2003-04-01 14:29:10.000000000 -0800
+++ binutils/ld/ldmisc.c	2003-04-17 21:23:39.000000000 -0700
@@ -72,6 +72,7 @@ vfinfo (fp, fmt, arg)
      va_list arg;
 {
   bfd_boolean fatal = FALSE;
+  bfd_boolean is_long;
 
   while (*fmt != '\0')
     {
@@ -84,6 +85,8 @@ vfinfo (fp, fmt, arg)
       if (*fmt == '%')
 	{
 	  fmt++;
+	  is_long = FALSE;
+again:
 	  switch (*fmt++)
 	    {
 	    default:
@@ -353,14 +356,34 @@ vfinfo (fp, fmt, arg)
 	      fprintf (fp, "%s", va_arg (arg, char *));
 	      break;
 
+	    case 'l':
+	      /* long, like printf */
+	      is_long = TRUE;
+	      goto again;
+	      break;
+
 	    case 'd':
 	      /* integer, like printf */
-	      fprintf (fp, "%d", va_arg (arg, int));
+	      if (is_long)
+		fprintf (fp, "%ld", va_arg (arg, long));
+	      else
+		fprintf (fp, "%d", va_arg (arg, int));
 	      break;
 
 	    case 'u':
 	      /* unsigned integer, like printf */
-	      fprintf (fp, "%u", va_arg (arg, unsigned int));
+	      if (is_long)
+		fprintf (fp, "%lu", va_arg (arg, unsigned long));
+	      else
+		fprintf (fp, "%u", va_arg (arg, unsigned int));
+	      break;
+
+	    case 'x':
+	      /* unsigned integer in hex, like printf */
+	      if (is_long)
+		fprintf (fp, "%lx", va_arg (arg, unsigned long));
+	      else
+		fprintf (fp, "%x", va_arg (arg, unsigned int));
 	      break;
 	    }
 	}
@@ -506,3 +529,14 @@ ld_abort (file, line, fn)
   einfo (_("%P%F: please report this bug\n"));
   xexit (1);
 }
+
+bfd_boolean
+error_handler VPARAMS ((int id ATTRIBUTE_UNUSED, const char *fmt, ...))
+{
+  VA_OPEN (arg, fmt);
+  VA_FIXEDARG (arg, const char *, fmt);
+
+  vfinfo (stderr, fmt, arg);
+  VA_CLOSE (arg);
+  return TRUE;
+}
--- binutils/ld/ldmisc.h.cb	2001-09-27 10:28:34.000000000 -0700
+++ binutils/ld/ldmisc.h	2003-04-17 15:54:30.000000000 -0700
@@ -22,6 +22,7 @@
 #ifndef LDMISC_H
 #define LDMISC_H
 
+extern bfd_boolean error_handler PARAMS ((int, const char *, ...));
 extern void einfo PARAMS ((const char *, ...));
 extern void minfo PARAMS ((const char *, ...));
 extern void info_msg PARAMS ((const char *, ...));


More information about the Binutils mailing list