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 1/5] Clearly identify the readonly replacement symbols that serve as 'dummies' that could (or could not) be provided by other compilation units.
Date: Sat, 16 Feb 2013 00:23:18 +0100	[thread overview]
Message-ID: <cec5070e43b6a06a77908c926d8822ed58baa458.1360968989.git.Jens.Gustedt@inria.fr> (raw)
In-Reply-To: <cover.1360968989.git.Jens.Gustedt@inria.fr>


9	0	src/internal/libc.h
4	4	src/stdio/__stdio_exit.c
2	2	src/stdio/__toread.c
2	2	src/stdio/fflush.c
3	5	src/stdio/popen.c
5	7	src/thread/pthread_create.c

diff --git a/src/internal/libc.h b/src/internal/libc.h
index c9416f0..a2f36fb 100644
--- a/src/internal/libc.h
+++ b/src/internal/libc.h
@@ -58,6 +58,15 @@ int __setxid(int, int, int, int);
 
 extern char **__environ;
 
+
+/* Provide a dummy location for all readonly symbols that are
+   weak. This is a fallback that should always have a value of all
+   zero and suitable aligned to be able to serve as an address for any
+   type. */
+#define WEAK_PROVIDE_DUMMY __attribute__((__weak__, __aligned__(32))) struct { unsigned char const _arr[32]; }  __readonly_dummy
+
+#define _Readonly_alias extern __attribute__((__weak__,__alias__("__readonly_dummy")))
+
 #undef weak_alias
 #define weak_alias(old, new) \
 	extern __typeof(old) new __attribute__((weak, alias(#old)))
diff --git a/src/stdio/__stdio_exit.c b/src/stdio/__stdio_exit.c
index 0fb3323..2a38c8d 100644
--- a/src/stdio/__stdio_exit.c
+++ b/src/stdio/__stdio_exit.c
@@ -1,9 +1,9 @@
 #include "stdio_impl.h"
 
-static FILE *const dummy_file = 0;
-weak_alias(dummy_file, __stdin_used);
-weak_alias(dummy_file, __stdout_used);
-weak_alias(dummy_file, __stderr_used);
+WEAK_PROVIDE_DUMMY;
+_Readonly_alias FILE *const __stdin_used;
+_Readonly_alias FILE *const __stdout_used;
+_Readonly_alias FILE *const __stderr_used;
 
 static void close_file(FILE *f)
 {
diff --git a/src/stdio/__toread.c b/src/stdio/__toread.c
index 2e804f6..7c5145c 100644
--- a/src/stdio/__toread.c
+++ b/src/stdio/__toread.c
@@ -13,8 +13,8 @@ int __toread(FILE *f)
 	return 0;
 }
 
-static const int dummy = 0;
-weak_alias(dummy, __towrite_used);
+WEAK_PROVIDE_DUMMY;
+_Readonly_alias int const __towrite_used;
 
 void __stdio_exit(void);
 
diff --git a/src/stdio/fflush.c b/src/stdio/fflush.c
index af70950..22debf0 100644
--- a/src/stdio/fflush.c
+++ b/src/stdio/fflush.c
@@ -19,8 +19,8 @@ static int __fflush_unlocked(FILE *f)
 }
 
 /* stdout.c will override this if linked */
-static FILE *const dummy = 0;
-weak_alias(dummy, __stdout_used);
+WEAK_PROVIDE_DUMMY;
+_Readonly_alias FILE *const __stdout_used;
 
 int fflush(FILE *f)
 {
diff --git a/src/stdio/popen.c b/src/stdio/popen.c
index e5fbc4f..a1fa149 100644
--- a/src/stdio/popen.c
+++ b/src/stdio/popen.c
@@ -6,11 +6,9 @@
 #include "pthread_impl.h"
 #include "syscall.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);
 
 pid_t __vfork(void);
 
diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c
index d11dcfa..3f30116 100644
--- a/src/thread/pthread_create.c
+++ b/src/thread/pthread_create.c
@@ -81,13 +81,11 @@ static int start(void *p)
 #define ROUND(x) (((x)+PAGE_SIZE-1)&-PAGE_SIZE)
 
 /* pthread_key_create.c overrides this */
-static const size_t dummy = 0;
-weak_alias(dummy, __pthread_tsd_size);
-
-static FILE *const dummy_file = 0;
-weak_alias(dummy_file, __stdin_used);
-weak_alias(dummy_file, __stdout_used);
-weak_alias(dummy_file, __stderr_used);
+WEAK_PROVIDE_DUMMY;
+_Readonly_alias const size_t __pthread_tsd_size;
+_Readonly_alias FILE *const __stdin_used;
+_Readonly_alias FILE *const __stdout_used;
+_Readonly_alias FILE *const __stderr_used;
 
 static void init_file_lock(FILE *f)
 {
-- 
1.7.9.5



  reply	other threads:[~2013-02-15 23:23 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 ` Jens Gustedt [this message]
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 ` [PATCH 5/5] Use the weak functions that do nothing as aliases for the default actions Jens Gustedt
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=cec5070e43b6a06a77908c926d8822ed58baa458.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).