mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Jens Gustedt <Jens.Gustedt@inria.fr>
To: musl@lists.openwall.com
Subject: [PATCH 5/5] Use the weak functions that do nothing as aliases for the default actions
Date: Sat, 16 Feb 2013 00:25:07 +0100	[thread overview]
Message-ID: <fef8bbf759787cabc4ffd61c4e3357bc11112f8b.1360968989.git.Jens.Gustedt@inria.fr> (raw)
In-Reply-To: <cover.1360968989.git.Jens.Gustedt@inria.fr>

 - this unifies the coding of such functions and clearly marks the intent
 - all such functions with a same type may be overlayed by the
   compiler. thereby only three such functions must be realized over all
   the musl C library
 - when compiled with -ffunction-sections and linked with
   -Wl,--gc-sections the gcc toolchain is in fact capable to rip
   superfluous copies from the final libc.so or from the statically
   linked executable.

2	5	src/aio/aio_readwrite.c
2	4	src/env/__init_security.c
4	7	src/exit/exit.c
2	2	src/exit/quick_exit.c
4	4	src/mman/mmap.c
4	4	src/mman/munmap.c
2	5	src/process/fork.c
3	5	src/process/posix_spawn.c
3	5	src/process/system.c
2	5	src/thread/cancel_dummy.c
6	3	src/thread/cancellation.c
4	6	src/thread/pthread_create.c
2	4	src/thread/pthread_join.c

diff --git a/src/aio/aio_readwrite.c b/src/aio/aio_readwrite.c
index e4c95aa..4862365 100644
--- a/src/aio/aio_readwrite.c
+++ b/src/aio/aio_readwrite.c
@@ -5,11 +5,8 @@
 #include <limits.h>
 #include "pthread_impl.h"
 
-static void dummy(void)
-{
-}
-
-weak_alias(dummy, __aio_wake);
+WEAK_PROVIDE_VOID;
+weak_alias(__weak_dummy_void, __aio_wake);
 
 static void notify_signal(struct sigevent *sev)
 {
diff --git a/src/env/__init_security.c b/src/env/__init_security.c
index 91b9b10..5b98623 100644
--- a/src/env/__init_security.c
+++ b/src/env/__init_security.c
@@ -6,10 +6,8 @@
 #include "libc.h"
 #include "atomic.h"
 
-static void dummy(void *ent)
-{
-}
-weak_alias(dummy, __init_ssp);
+WEAK_PROVIDE_VOIDP;
+weak_alias(__weak_dummy_voidp, __init_ssp);
 
 void __init_security(size_t *aux)
 {
diff --git a/src/exit/exit.c b/src/exit/exit.c
index e4932b5..a866e02 100644
--- a/src/exit/exit.c
+++ b/src/exit/exit.c
@@ -5,14 +5,11 @@
 #include "atomic.h"
 #include "syscall.h"
 
-static void dummy()
-{
-}
-
 /* __toread.c, __towrite.c, and atexit.c override these */
-weak_alias(dummy, __funcs_on_exit);
-weak_alias(dummy, __flush_on_exit);
-weak_alias(dummy, __seek_on_exit);
+WEAK_PROVIDE_VOID;
+weak_alias(__weak_dummy_void, __funcs_on_exit);
+weak_alias(__weak_dummy_void, __flush_on_exit);
+weak_alias(__weak_dummy_void, __seek_on_exit);
 
 _Noreturn void exit(int code)
 {
diff --git a/src/exit/quick_exit.c b/src/exit/quick_exit.c
index 1175d80..79c389f 100644
--- a/src/exit/quick_exit.c
+++ b/src/exit/quick_exit.c
@@ -3,8 +3,8 @@
 #include "atomic.h"
 #include "libc.h"
 
-static void dummy() { }
-weak_alias(dummy, __funcs_on_quick_exit);
+WEAK_PROVIDE_VOID;
+weak_alias(__weak_dummy_void, __funcs_on_quick_exit);
 
 _Noreturn void quick_exit(int code)
 {
diff --git a/src/mman/mmap.c b/src/mman/mmap.c
index e99271f..2391eb7 100644
--- a/src/mman/mmap.c
+++ b/src/mman/mmap.c
@@ -5,10 +5,10 @@
 #include "syscall.h"
 #include "libc.h"
 
-static void dummy1(int x) { }
-static void dummy0(void) { }
-weak_alias(dummy1, __vm_lock);
-weak_alias(dummy0, __vm_unlock);
+WEAK_PROVIDE_INT;
+WEAK_PROVIDE_VOID;
+weak_alias(__weak_dummy_int, __vm_lock);
+weak_alias(__weak_dummy_void, __vm_unlock);
 
 #define OFF_MASK ((-0x2000ULL << (8*sizeof(long)-1)) | 0xfff)
 
diff --git a/src/mman/munmap.c b/src/mman/munmap.c
index 91aefd4..2c18e7c 100644
--- a/src/mman/munmap.c
+++ b/src/mman/munmap.c
@@ -3,10 +3,10 @@
 #include "syscall.h"
 #include "libc.h"
 
-static void dummy1(int x) { }
-static void dummy0(void) { }
-weak_alias(dummy1, __vm_lock);
-weak_alias(dummy0, __vm_unlock);
+WEAK_PROVIDE_INT;
+WEAK_PROVIDE_VOID;
+weak_alias(__weak_dummy_int, __vm_lock);
+weak_alias(__weak_dummy_void, __vm_unlock);
 
 int __munmap(void *start, size_t len)
 {
diff --git a/src/process/fork.c b/src/process/fork.c
index fb8a430..4a83bc3 100644
--- a/src/process/fork.c
+++ b/src/process/fork.c
@@ -4,11 +4,8 @@
 #include "libc.h"
 #include "pthread_impl.h"
 
-static void dummy(int x)
-{
-}
-
-weak_alias(dummy, __fork_handler);
+WEAK_PROVIDE_INT;
+weak_alias(__weak_dummy_int,  __fork_handler);
 
 pid_t fork(void)
 {
diff --git a/src/process/posix_spawn.c b/src/process/posix_spawn.c
index dd45012..e1668b7 100644
--- a/src/process/posix_spawn.c
+++ b/src/process/posix_spawn.c
@@ -10,11 +10,9 @@
 #include "fdop.h"
 #include "libc.h"
 
-static void dummy_0()
-{
-}
-weak_alias(dummy_0, __acquire_ptc);
-weak_alias(dummy_0, __release_ptc);
+WEAK_PROVIDE_VOID;
+weak_alias(__weak_dummy_void, __acquire_ptc);
+weak_alias(__weak_dummy_void, __release_ptc);
 
 struct args {
 	int p[2];
diff --git a/src/process/system.c b/src/process/system.c
index 4232bef..6946b35 100644
--- a/src/process/system.c
+++ b/src/process/system.c
@@ -7,11 +7,9 @@
 #include "pthread_impl.h"
 #include "libc.h"
 
-static void dummy_0()
-{
-}
-weak_alias(dummy_0, __acquire_ptc);
-weak_alias(dummy_0, __release_ptc);
+WEAK_PROVIDE_VOID;
+weak_alias(__weak_dummy_void, __acquire_ptc);
+weak_alias(__weak_dummy_void, __release_ptc);
 
 extern char **__environ;
 
diff --git a/src/thread/cancel_dummy.c b/src/thread/cancel_dummy.c
index 7246970..655a222 100644
--- a/src/thread/cancel_dummy.c
+++ b/src/thread/cancel_dummy.c
@@ -6,8 +6,5 @@ long (__syscall_cp)(long nr, long u, long v, long w, long x, long y, long z)
 	return (__syscall)(nr, u, v, w, x, y, z);
 }
 
-static void dummy()
-{
-}
-
-weak_alias(dummy, __testcancel);
+WEAK_PROVIDE_VOID;
+weak_alias(__weak_dummy_void, __testcancel);
diff --git a/src/thread/cancellation.c b/src/thread/cancellation.c
index 9b21764..fa3208e 100644
--- a/src/thread/cancellation.c
+++ b/src/thread/cancellation.c
@@ -1,10 +1,13 @@
 #include "pthread_impl.h"
 
-static void dummy(struct __ptcb *cb)
+/* The following two are overwritten by pthread_create.c */
+_Weak
+void __weak_dummy_ptcb(struct __ptcb *cb)
 {
 }
-weak_alias(dummy, __do_cleanup_push);
-weak_alias(dummy, __do_cleanup_pop);
+
+weak_alias(__weak_dummy_ptcb, __do_cleanup_push);
+weak_alias(__weak_dummy_ptcb, __do_cleanup_pop);
 
 void _pthread_cleanup_push(struct __ptcb *cb, void (*f)(void *), void *x)
 {
diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c
index 3f30116..77ca0cf 100644
--- a/src/thread/pthread_create.c
+++ b/src/thread/pthread_create.c
@@ -2,12 +2,10 @@
 #include "stdio_impl.h"
 #include <sys/mman.h>
 
-static void dummy_0()
-{
-}
-weak_alias(dummy_0, __acquire_ptc);
-weak_alias(dummy_0, __release_ptc);
-weak_alias(dummy_0, __pthread_tsd_run_dtors);
+WEAK_PROVIDE_VOID;
+weak_alias(__weak_dummy_void, __acquire_ptc);
+weak_alias(__weak_dummy_void, __release_ptc);
+weak_alias(__weak_dummy_void, __pthread_tsd_run_dtors);
 
 _Noreturn void pthread_exit(void *result)
 {
diff --git a/src/thread/pthread_join.c b/src/thread/pthread_join.c
index 719c91c..87eed62 100644
--- a/src/thread/pthread_join.c
+++ b/src/thread/pthread_join.c
@@ -1,14 +1,12 @@
 #include "pthread_impl.h"
 #include <sys/mman.h>
 
-static void dummy(void *p)
-{
-}
+WEAK_PROVIDE_VOIDP;
 
 int pthread_join(pthread_t t, void **res)
 {
 	int tmp;
-	while ((tmp = t->tid)) __timedwait(&t->tid, tmp, 0, 0, dummy, 0, 0);
+	while ((tmp = t->tid)) __timedwait(&t->tid, tmp, 0, 0, __weak_dummy_voidp, 0, 0);
 	if (res) *res = t->result;
 	if (t->map_base) munmap(t->map_base, t->map_size);
 	return 0;
-- 
1.7.9.5



  parent reply	other threads:[~2013-02-15 23:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-15 23:22 [PATCH 0/5] reorganize the use of weak symbols Jens Gustedt
2013-02-15 23:23 ` [PATCH 1/5] Clearly identify the readonly replacement symbols that serve as 'dummies' that could (or could not) be provided by other compilation units Jens Gustedt
2013-02-15 23:23 ` [PATCH 2/5] Clarify the implementation of the dummy alias used for pthread_self Jens Gustedt
2013-02-15 23:24 ` [PATCH 3/5] identify the weak function symbols that provide a real default action Jens Gustedt
2013-02-15 23:24 ` [PATCH 4/5] add three macros for empty dummy functions that do nothing Jens Gustedt
2013-02-15 23:25 ` Jens Gustedt [this message]
2013-02-16  5:59 ` [PATCH 0/5] reorganize the use of weak symbols Rich Felker
2013-02-16  8:16   ` Jens Gustedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fef8bbf759787cabc4ffd61c4e3357bc11112f8b.1360968989.git.Jens.Gustedt@inria.fr \
    --to=jens.gustedt@inria.fr \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).