Module Name: src
Committed By: pooka
Date: Mon Feb 7 19:34:39 UTC 2011
Modified Files:
src/lib/librumphijack: hijack.c
Log Message:
Force gcc to generate a stack frame for the call to dlsym(RTLD_NEXT).
Without this hack at least amd64 -O2 just used jmp and The Wrong
Thing happened.
To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/lib/librumphijack/hijack.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/hijack.c
diff -u src/lib/librumphijack/hijack.c:1.31 src/lib/librumphijack/hijack.c:1.32
--- src/lib/librumphijack/hijack.c:1.31 Mon Feb 7 12:23:05 2011
+++ src/lib/librumphijack/hijack.c Mon Feb 7 19:34:39 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: hijack.c,v 1.31 2011/02/07 12:23:05 pooka Exp $ */
+/* $NetBSD: hijack.c,v 1.32 2011/02/07 19:34:39 pooka Exp $ */
/*-
* Copyright (c) 2011 Antti Kantee. All Rights Reserved.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: hijack.c,v 1.31 2011/02/07 12:23:05 pooka Exp $");
+__RCSID("$NetBSD: hijack.c,v 1.32 2011/02/07 19:34:39 pooka Exp $");
#define __ssp_weak_name(fun) _hijack_ ## fun
@@ -174,12 +174,25 @@
/*
* 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 dlsym(handle, symbol);
+ return (void *)rv;
}
/* low calorie sockets? */