From d8f2efa708a027132d443f45a8c98a0c7c1b2d77 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 17 Oct 2018 23:57:28 -0400 Subject: bypass indirection through pointer objects to access stdin/out/err by ABI, the public stdin/out/err macros use extern pointer objects, and this is necessary to avoid copy relocations that would be expensive and make the size of the FILE structure part of the ABI. however, internally it makes sense to access the underlying FILE objects directly. this avoids both an indirection through the GOT to find the address of the stdin/out/err pointer objects (which can't be computed PC-relative because they may have been moved to the main program by copy relocations) and an indirection through the resulting pointer object. in most places this is just a minor optimization, but in the case of getchar and putchar (and the unlocked versions thereof), ipa constant propagation makes all accesses to members of stdin/out PC-relative or GOT-relative, possibly reducing register pressure as well. --- src/include/stdio.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/include/stdio.h (limited to 'src/include/stdio.h') diff --git a/src/include/stdio.h b/src/include/stdio.h new file mode 100644 index 00000000..534c6907 --- /dev/null +++ b/src/include/stdio.h @@ -0,0 +1,18 @@ +#ifndef STDIO_H +#define STDIO_H + +#include "../../include/stdio.h" + +#undef stdin +#undef stdout +#undef stderr + +extern hidden FILE __stdin_FILE; +extern hidden FILE __stdout_FILE; +extern hidden FILE __stderr_FILE; + +#define stdin (&__stdin_FILE) +#define stdout (&__stdout_FILE) +#define stderr (&__stderr_FILE) + +#endif -- cgit v1.2.1