We only call printf on stdout from one thread, so we don't need internal stdio locking for stdout.
On my machine eu-readelf -N --debug-dump=info libxul.so > /dev/null goes from 65 seconds to 63 seconds. Signed-off-by: Mark Wielaard <m...@klomp.org> --- src/ChangeLog | 4 ++++ src/readelf.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/ChangeLog b/src/ChangeLog index cc12d83..19f4210 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2018-06-04 Mark Wielaard <m...@klomp.org> + + * readelf.c (main): Call __fsetlocking (stdout, FSETLOCKING_BYCALLER). + 2018-05-31 Mark Wielaard <m...@klomp.org> * readelf.c (print_debug_units): Print the dwo name and id when diff --git a/src/readelf.c b/src/readelf.c index 0725313..a578b27 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -35,6 +35,8 @@ #include <locale.h> #include <stdarg.h> #include <stdbool.h> +#include <stdio.h> +#include <stdio_ext.h> #include <stdlib.h> #include <string.h> #include <strings.h> @@ -310,6 +312,9 @@ static void dump_archive_index (Elf *, const char *); int main (int argc, char *argv[]) { + /* We use no threads here which can interfere with handling a stream. */ + (void) __fsetlocking (stdout, FSETLOCKING_BYCALLER); + /* Set locale. */ setlocale (LC_ALL, ""); -- 1.8.3.1