Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sat, 16 Feb 2013 00:23:18 +0100
From: Jens Gustedt <Jens.Gustedt@...ia.fr>
To: musl@...ts.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.


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

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.