summaryrefslogtreecommitdiff
path: root/src/internal/vis.h
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2015-04-19 22:05:29 -0400
committerRich Felker <dalias@aerifal.cx>2015-04-19 22:05:29 -0400
commitde2b67f8d41e08caa56bf6540277f6561edb647f (patch)
treec0117710aa8a092a7ead36770811d430fca0b477 /src/internal/vis.h
parent51fc77c7c03fa0b300e9a609b18f11f0e4db065a (diff)
downloadmusl-de2b67f8d41e08caa56bf6540277f6561edb647f.tar.gz
musl-de2b67f8d41e08caa56bf6540277f6561edb647f.tar.bz2
musl-de2b67f8d41e08caa56bf6540277f6561edb647f.tar.xz
musl-de2b67f8d41e08caa56bf6540277f6561edb647f.zip
add optional global visibility override
this is implemented via the build system and does not affect source files. the idea is to use protected or hidden visibility to prevent the compiler from pessimizing function calls within a shared (or position-independent static) libc in the form of overhead setting up for a call through the PLT. the ld-time symbol binding via the -Bsymbolic-functions option already optimized out the PLT itself, but not the code in the caller needed to support a call through the PLT. on some archs this overhead can be substantial; on others it's trivial.
Diffstat (limited to 'src/internal/vis.h')
-rw-r--r--src/internal/vis.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/internal/vis.h b/src/internal/vis.h
new file mode 100644
index 00000000..bf7a5b20
--- /dev/null
+++ b/src/internal/vis.h
@@ -0,0 +1,40 @@
+/* This file is only used if enabled in the build system, in which case it is
+ * included automatically via command line options. It is not included
+ * explicitly by any source files or other headers. Its purpose is to
+ * override default visibilities to reduce the size and performance costs
+ * of position-independent code. */
+
+#ifndef CRT
+#ifdef SHARED
+
+/* For shared libc.so, all symbols should be protected, but some toolchains
+ * fail to support copy relocations for protected data, so exclude all
+ * exported data symbols. */
+
+__attribute__((__visibility__("default")))
+extern struct _IO_FILE *const stdin, *const stdout, *const stderr;
+
+__attribute__((__visibility__("default")))
+extern int optind, opterr, optopt, optreset, __optreset, getdate_err, h_errno, daylight, __daylight, signgam, __signgam;
+
+__attribute__((__visibility__("default")))
+extern long timezone, __timezone;
+
+__attribute__((__visibility__("default")))
+extern char *optarg, **environ, **__environ, *tzname[2], *__tzname[2], *__progname, *__progname_full;
+
+#pragma GCC visibility push(protected)
+
+#elif defined(__PIC__)
+
+/* If building static libc.a as position-independent code, try to make
+ * everything hidden except possibly-undefined weak references. */
+
+__attribute__((__visibility__("default")))
+extern void (*const __init_array_start)(), (*const __init_array_end)(),
+ (*const __fini_array_start)(), (*const __fini_array_end)();
+
+#pragma GCC visibility push(hidden)
+
+#endif
+#endif