Module Name:    src
Committed By:   pooka
Date:           Wed Feb 23 15:23:16 UTC 2011

Modified Files:
        src/lib/librumphijack: Makefile hijack.c
Added Files:
        src/lib/librumphijack: hijackdlsym.c

Log Message:
Put the dlsym-from-this-object trampoline into a separate source
module which is compiled -fno-optimize-sibling-calls instead of
trying to fool the optimizer in various ways in the trampoline.

thanks to yamt for the tip


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/librumphijack/Makefile
cvs rdiff -u -r1.63 -r1.64 src/lib/librumphijack/hijack.c
cvs rdiff -u -r0 -r1.1 src/lib/librumphijack/hijackdlsym.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumphijack/Makefile
diff -u src/lib/librumphijack/Makefile:1.6 src/lib/librumphijack/Makefile:1.7
--- src/lib/librumphijack/Makefile:1.6	Thu Jan 27 18:12:19 2011
+++ src/lib/librumphijack/Makefile	Wed Feb 23 15:23:15 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.6 2011/01/27 18:12:19 pooka Exp $
+#	$NetBSD: Makefile,v 1.7 2011/02/23 15:23:15 pooka Exp $
 #
 
 LIB=		rumphijack
@@ -8,7 +8,7 @@
 		rumpclient	${.CURDIR}/../librumpclient
 MAN=		rumphijack.3
 
-SRCS=		hijack.c
+SRCS=		hijack.c hijackdlsym.c
 
 CPPFLAGS+=	-D_DIAGNOSTIC -D_REENTRANT
 
@@ -16,5 +16,6 @@
 
 #DBG=-g
 #NOGCCERROR=1
+COPTS.hijackdlsym.c+=	-fno-optimize-sibling-calls
 
 .include <bsd.lib.mk>

Index: src/lib/librumphijack/hijack.c
diff -u src/lib/librumphijack/hijack.c:1.63 src/lib/librumphijack/hijack.c:1.64
--- src/lib/librumphijack/hijack.c:1.63	Mon Feb 21 20:11:56 2011
+++ src/lib/librumphijack/hijack.c	Wed Feb 23 15:23:15 2011
@@ -1,4 +1,4 @@
-/*      $NetBSD: hijack.c,v 1.63 2011/02/21 20:11:56 pooka Exp $	*/
+/*      $NetBSD: hijack.c,v 1.64 2011/02/23 15:23:15 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: hijack.c,v 1.63 2011/02/21 20:11:56 pooka Exp $");
+__RCSID("$NetBSD: hijack.c,v 1.64 2011/02/23 15:23:15 pooka Exp $");
 
 #define __ssp_weak_name(fun) _hijack_ ## fun
 
@@ -59,6 +59,8 @@
 #include <time.h>
 #include <unistd.h>
 
+#include "hijack.h"
+
 enum dualcall {
 	DUALCALL_WRITE, DUALCALL_WRITEV, DUALCALL_PWRITE, DUALCALL_PWRITEV,
 	DUALCALL_IOCTL, DUALCALL_FCNTL,
@@ -294,30 +296,6 @@
 }
 
 /*
- * This is called from librumpclient in case of LD_PRELOAD.
- * It ensures correct RTLD_NEXT.
- *
- * ... except, it's apparently extremely difficult to force
- * at least gcc to generate an actual stack frame here.  So
- * sprinkle some volatile foobar and baz to throw the optimizer
- * off the scent and generate a variable assignment with the
- * return value.  The posterboy for this meltdown is amd64
- * with -O2.  At least with gcc 4.1.3 i386 works regardless of
- * optimization.
- */
-volatile int rumphijack_unrope; /* there, unhang yourself */
-static void *
-hijackdlsym(void *handle, const char *symbol)
-{
-	void *rv;
-
-	rv = dlsym(handle, symbol);
-	rumphijack_unrope = *(volatile int *)rv;
-
-	return (void *)rv;
-}
-
-/*
  * This tracks if our process is in a subdirectory of /rump.
  * It's preserved over exec.
  */
@@ -452,7 +430,7 @@
 	extern void *(*rumpclient_dlsym)(void *, const char *);
 	unsigned i, j;
 
-	rumpclient_dlsym = hijackdlsym;
+	rumpclient_dlsym = rumphijack_dlsym;
 	host_fork = dlsym(RTLD_NEXT, "fork");
 	host_daemon = dlsym(RTLD_NEXT, "daemon");
 	host_execve = dlsym(RTLD_NEXT, "execve");

Added files:

Index: src/lib/librumphijack/hijackdlsym.c
diff -u /dev/null src/lib/librumphijack/hijackdlsym.c:1.1
--- /dev/null	Wed Feb 23 15:23:16 2011
+++ src/lib/librumphijack/hijackdlsym.c	Wed Feb 23 15:23:15 2011
@@ -0,0 +1,47 @@
+/*      $NetBSD: hijackdlsym.c,v 1.1 2011/02/23 15:23:15 pooka Exp $	*/
+
+/*-
+ * Copyright (c) 2011 Antti Kantee.  All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: hijackdlsym.c,v 1.1 2011/02/23 15:23:15 pooka Exp $");
+
+#include <dlfcn.h>
+
+#include "hijack.h"
+
+/*
+ * This is called from librumpclient in case of LD_PRELOAD.
+ * It ensures correct RTLD_NEXT.
+ *
+ * (note, this module is compiled with -fno-optimize-sibling-calls
+ * to make sure this function is not treated as a tailcall)
+ */
+void *
+rumphijack_dlsym(void *handle, const char *symbol)
+{
+
+	return dlsym(handle, symbol);
+}

Reply via email to