summaryrefslogtreecommitdiff
path: root/src/stdio/stdin.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2018-10-17 23:57:28 -0400
committerRich Felker <dalias@aerifal.cx>2018-10-18 00:32:20 -0400
commitd8f2efa708a027132d443f45a8c98a0c7c1b2d77 (patch)
tree887db37b661d946d28aa5f542e5401318bd75ff1 /src/stdio/stdin.c
parentd664061adb4d7f6647ab2059bc351daa394bf5da (diff)
downloadmusl-d8f2efa708a027132d443f45a8c98a0c7c1b2d77.tar.gz
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.
Diffstat (limited to 'src/stdio/stdin.c')
-rw-r--r--src/stdio/stdin.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/stdio/stdin.c b/src/stdio/stdin.c
index 171ff22a..5aa5262c 100644
--- a/src/stdio/stdin.c
+++ b/src/stdio/stdin.c
@@ -1,7 +1,9 @@
#include "stdio_impl.h"
+#undef stdin
+
static unsigned char buf[BUFSIZ+UNGET];
-static FILE f = {
+hidden FILE __stdin_FILE = {
.buf = buf+UNGET,
.buf_size = sizeof buf-UNGET,
.fd = 0,
@@ -11,5 +13,5 @@ static FILE f = {
.close = __stdio_close,
.lock = -1,
};
-FILE *const stdin = &f;
-FILE *volatile __stdin_used = &f;
+FILE *const stdin = &__stdin_FILE;
+FILE *volatile __stdin_used = &__stdin_FILE;