summaryrefslogtreecommitdiff
path: root/src/internal
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2018-09-05 12:43:34 -0400
committerRich Felker <dalias@aerifal.cx>2018-09-05 14:05:14 -0400
commit9b95fd0944e4206949e90633c3fed088202810ec (patch)
tree4af9c66139abfef78854aca3200f836153727c23 /src/internal
parent2de29bc994029b903a366b8a4a9f8c3c3ee2be90 (diff)
downloadmusl-9b95fd0944e4206949e90633c3fed088202810ec.tar.gz
define and use internal macros for hidden visibility, weak refs
this cleans up what had become widespread direct inline use of "GNU C" style attributes directly in the source, and lowers the barrier to increased use of hidden visibility, which will be useful to recovering some of the efficiency lost when the protected visibility hack was dropped in commit dc2f368e565c37728b0d620380b849c3a1ddd78f, especially on archs where the PLT ABI is costly.
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/fdpic_crt.h4
-rw-r--r--src/internal/libc.h23
-rw-r--r--src/internal/malloc_impl.h8
-rw-r--r--src/internal/sh/__shcall.c5
-rw-r--r--src/internal/syscall.h4
-rw-r--r--src/internal/version.c4
6 files changed, 23 insertions, 25 deletions
diff --git a/src/internal/fdpic_crt.h b/src/internal/fdpic_crt.h
index 7eb50c6b..3c3f077d 100644
--- a/src/internal/fdpic_crt.h
+++ b/src/internal/fdpic_crt.h
@@ -1,7 +1,7 @@
#include <stdint.h>
+#include "libc.h"
-__attribute__((__visibility__("hidden")))
-void *__fdpic_fixup(void *map, uintptr_t *a, uintptr_t *z)
+hidden void *__fdpic_fixup(void *map, uintptr_t *a, uintptr_t *z)
{
/* If map is a null pointer, the program was loaded by a
* non-FDPIC-aware ELF loader, and fixups are not needed,
diff --git a/src/internal/libc.h b/src/internal/libc.h
index 5e145183..7307a738 100644
--- a/src/internal/libc.h
+++ b/src/internal/libc.h
@@ -33,24 +33,21 @@ struct __libc {
#define PAGE_SIZE libc.page_size
#endif
-#ifdef __PIC__
-#define ATTR_LIBC_VISIBILITY __attribute__((visibility("hidden")))
-#else
-#define ATTR_LIBC_VISIBILITY
-#endif
+#define weak __attribute__((__weak__))
+#define hidden __attribute__((__visibility__("hidden")))
-extern struct __libc __libc ATTR_LIBC_VISIBILITY;
+extern hidden struct __libc __libc;
#define libc __libc
-extern size_t __hwcap ATTR_LIBC_VISIBILITY;
-extern size_t __sysinfo ATTR_LIBC_VISIBILITY;
+extern hidden size_t __hwcap;
+extern hidden size_t __sysinfo;
extern char *__progname, *__progname_full;
/* Designed to avoid any overhead in non-threaded processes */
-void __lock(volatile int *) ATTR_LIBC_VISIBILITY;
-void __unlock(volatile int *) ATTR_LIBC_VISIBILITY;
-int __lockfile(FILE *) ATTR_LIBC_VISIBILITY;
-void __unlockfile(FILE *) ATTR_LIBC_VISIBILITY;
+hidden void __lock(volatile int *);
+hidden void __unlock(volatile int *);
+hidden int __lockfile(FILE *);
+hidden void __unlockfile(FILE *);
#define LOCK(x) __lock(x)
#define UNLOCK(x) __unlock(x)
@@ -61,7 +58,7 @@ extern char **__environ;
#undef weak_alias
#define weak_alias(old, new) \
- extern __typeof(old) new __attribute__((weak, alias(#old)))
+ extern __typeof(old) new __attribute__((__weak__, __alias__(#old)))
#undef LFS64_2
#define LFS64_2(x, y) weak_alias(x, y)
diff --git a/src/internal/malloc_impl.h b/src/internal/malloc_impl.h
index 5d025b06..4355d84c 100644
--- a/src/internal/malloc_impl.h
+++ b/src/internal/malloc_impl.h
@@ -1,6 +1,8 @@
#ifndef MALLOC_IMPL_H
#define MALLOC_IMPL_H
+#include "libc.h"
+
void *__mmap(void *, size_t, int, int, int, off_t);
int __munmap(void *, size_t);
void *__mremap(void *, size_t, size_t, int, ...);
@@ -36,10 +38,8 @@ struct bin {
#define IS_MMAPPED(c) !((c)->csize & (C_INUSE))
-__attribute__((__visibility__("hidden")))
-void __bin_chunk(struct chunk *);
+hidden void __bin_chunk(struct chunk *);
-__attribute__((__visibility__("hidden")))
-extern int __malloc_replaced;
+hidden extern int __malloc_replaced;
#endif
diff --git a/src/internal/sh/__shcall.c b/src/internal/sh/__shcall.c
index dfe80a7f..23655904 100644
--- a/src/internal/sh/__shcall.c
+++ b/src/internal/sh/__shcall.c
@@ -1,5 +1,6 @@
-__attribute__((__visibility__("hidden")))
-int __shcall(void *arg, int (*func)(void *))
+#include "libc.h"
+
+hidden int __shcall(void *arg, int (*func)(void *))
{
return func(arg);
}
diff --git a/src/internal/syscall.h b/src/internal/syscall.h
index 6d378a81..c12a46cd 100644
--- a/src/internal/syscall.h
+++ b/src/internal/syscall.h
@@ -2,6 +2,7 @@
#define _INTERNAL_SYSCALL_H
#include <sys/syscall.h>
+#include "libc.h"
#include "syscall_arch.h"
#ifndef SYSCALL_RLIM_INFINITY
@@ -21,8 +22,7 @@
typedef long syscall_arg_t;
#endif
-__attribute__((visibility("hidden")))
-long __syscall_ret(unsigned long), __syscall(syscall_arg_t, ...),
+hidden long __syscall_ret(unsigned long), __syscall(syscall_arg_t, ...),
__syscall_cp(syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t,
syscall_arg_t, syscall_arg_t, syscall_arg_t);
diff --git a/src/internal/version.c b/src/internal/version.c
index dc044ec4..0d6e1f82 100644
--- a/src/internal/version.c
+++ b/src/internal/version.c
@@ -1,9 +1,9 @@
#include "version.h"
+#include "libc.h"
static const char version[] = VERSION;
-__attribute__((__visibility__("hidden")))
-const char *__libc_get_version()
+hidden const char *__libc_get_version()
{
return version;
}