ld: optimize vfinfo output slightly
authorMike Frysinger <vapier@gentoo.org>
Tue, 3 Apr 2012 03:37:26 +0000 (03:37 +0000)
committerMike Frysinger <vapier@gentoo.org>
Tue, 3 Apr 2012 03:37:26 +0000 (03:37 +0000)
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
...

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
ld/ChangeLog
ld/ldmisc.c

index 9801bda53932061ce1cf45c4603febd57e95b8ce..203f98615922b6c146b36bd1aec476c85a89b3ea 100644 (file)
@@ -1,3 +1,9 @@
+2012-04-02  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.
+
 2012-03-30  Nick Clifton  <nickc@redhat.com>
 
        * po/vi.po: Updated Vietnamese translation.
index 5112c716a45a5566801ad5c469038f26e9854c56..ca1896ff1c04ed80fe1ca5bf7706b22e81e7a98f 100644 (file)
@@ -72,11 +72,14 @@ vfinfo (FILE *fp, const char *fmt, va_list arg, bfd_boolean is_warning)
 
   while (*fmt != '\0')
     {
+      const char *str = fmt;
       while (*fmt != '%' && *fmt != '\0')
-       {
-         putc (*fmt, fp);
-         fmt++;
-       }
+       fmt++;
+      if (fmt != str)
+       if (fwrite (str, 1, fmt - str, fp))
+         {
+           /* Ignore.  */
+         }
 
       if (*fmt == '%')
        {
This page took 0.025384 seconds and 4 git commands to generate.