tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

__dead functions



Hi,

An attempt to compile current kernel with gcc 4.3.1 revealed a couple of
functions declared 'noreturn', which from compiler's POV can return. My
guess is that there's been yet another go at C frontend heuristics
improvement, but what do I know. Anyway, the functions in question are
exit1() and lwp_exit():

 * exit1() does call lwp_exit_switchaway() (which is de-facto a never
   returning function as well, but not declared as such), that in turn
   calls cpu_switchto() that _can_ return in other call paths, thus
   cannot be declared as a 'noreturn';
 * lwp_exit() is not something I fully understand, but provided that
   it's too declared __dead.

What I propose is to declare lwp_exit_switchaway() as __dead as well and
explicitly tell gcc that it and lwp_exit() do not return.

The patch [1] is also appended for convenience.

[1]: http://koowaldah.org/people/ash/netbsd/noreturn-fix.patch

Regards,
--
Alex

diff --git a/sys/kern/kern_lwp.c b/sys/kern/kern_lwp.c
index 611cf89..59cda2a 100644
--- a/sys/kern/kern_lwp.c
+++ b/sys/kern/kern_lwp.c
@@ -837,6 +837,8 @@ lwp_exit(struct lwp *l)
 #endif
                lwp_exit_switchaway(l);
        }
+
+       __NOTREACHED;
 }
 
 /*
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index a83e8b2..cdc8d1d 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -885,7 +885,7 @@ lwp_exit_switchaway(lwp_t *l)
        /* Switch to the new LWP.. */
        (void)cpu_switchto(NULL, newl, false);
 
-       /* NOTREACHED */
+       __NOTREACHED;
 }
 
 /*
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
index 3ce17c3..d47e7e7 100644
--- a/sys/sys/cdefs.h
+++ b/sys/sys/cdefs.h
@@ -164,6 +164,12 @@
 #endif
 
 /*
+ * Explicitly specify that a certain point in the codepath should not
+ * be reached and indicate so to gcc.
+ */
+#define __NOTREACHED for (;;)
+
+/*
  * GCC1 and some versions of GCC2 declare dead (non-returning) and
  * pure (no side effects) functions using "volatile" and "const";
  * unfortunately, these then cause warnings under "-ansi -pedantic".
diff --git a/sys/sys/lwp.h b/sys/sys/lwp.h
index 84c0b93..f5bb7bd 100644
--- a/sys/sys/lwp.h
+++ b/sys/sys/lwp.h
@@ -281,7 +281,7 @@ void        cpu_setfunc(lwp_t *, void (*)(void *), void *);
 void   startlwp(void *);
 void   upcallret(lwp_t *);
 void   lwp_exit(lwp_t *) __dead;
-void   lwp_exit_switchaway(lwp_t *);
+void   lwp_exit_switchaway(lwp_t *) __dead;
 lwp_t *proc_representative_lwp(struct proc *, int *, int);
 int    lwp_suspend(lwp_t *, lwp_t *);
 int    lwp_create1(lwp_t *, const void *, size_t, u_long, lwpid_t *);
-- 
1.5.5.4



Home | Main Index | Thread Index | Old Index