This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

[patch] ld: optimize vfinfo output slightly


ld atm ends up calling the write() syscall on every char when displaying an 
error message.  for example:
$ echo 'main(){foo();}' | strace -f -ewrite gcc -x c -o /dev/null -
...
[pid 13035] write(2, ":", 1)            = 1
[pid 13035] write(2, " ", 1)            = 1
[pid 13035] write(2, "I", 1)            = 1
[pid 13035] write(2, "n", 1)            = 1
[pid 13035] write(2, " ", 1)            = 1
[pid 13035] write(2, "f", 1)            = 1
[pid 13035] write(2, "u", 1)            = 1
[pid 13035] write(2, "n", 1)            = 1
[pid 13035] write(2, "c", 1)            = 1
[pid 13035] write(2, "t", 1)            = 1
[pid 13035] write(2, "i", 1)            = 1
[pid 13035] write(2, "o", 1)            = 1
[pid 13035] write(2, "n", 1)            = 1
[pid 13035] write(2, " ", 1)            = 1
[pid 13035] write(2, "`", 1)            = 1
...

that's just to write ": In function `main':".  a slight optimization in the 
vfinfo() func gives a much more reasonable syscall footprint:
...
write(2, ": In function `", 15)         = 15
...

it's been a while since i've hacked in these layers, so i'm not sure if 
there's something better than just calling abort() here ...
-mike

2012-03-24  Mike Frysinger  <vapier@gentoo.org>

	* ldmisc.c (vfinfo): Assign new local str to fmt.  Delete
	putc call.  If str and fmt are different, call fwrite on
	the difference.

--- ldmisc.c	18 Feb 2012 11:55:45 -0000	1.42
+++ ldmisc.c	24 Mar 2012 05:13:24 -0000
@@ -72,10 +72,15 @@ vfinfo (FILE *fp, const char *fmt, va_li
 
   while (*fmt != '\0')
     {
+      const char *str = fmt;
       while (*fmt != '%' && *fmt != '\0')
+	fmt++;
+      if (fmt != str)
 	{
-	  putc (*fmt, fp);
-	  fmt++;
+	  size_t len = fmt - str;
+
+	  if (fwrite (str, 1, len, fp) != len)
+	    abort ();
 	}
 
       if (*fmt == '%')

Attachment: signature.asc
Description: This is a digitally signed message part.


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