Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/librumphijack Force gcc to generate a stack frame for th...
details: https://anonhg.NetBSD.org/src/rev/1bab2bdf40e2
branches: trunk
changeset: 761787:1bab2bdf40e2
user: pooka <pooka%NetBSD.org@localhost>
date: Mon Feb 07 19:34:39 2011 +0000
description:
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.
diffstat:
lib/librumphijack/hijack.c | 19 ++++++++++++++++---
1 files changed, 16 insertions(+), 3 deletions(-)
diffs (45 lines):
diff -r 483c558b0386 -r 1bab2bdf40e2 lib/librumphijack/hijack.c
--- a/lib/librumphijack/hijack.c Mon Feb 07 19:20:35 2011 +0000
+++ b/lib/librumphijack/hijack.c Mon Feb 07 19:34:39 2011 +0000
@@ -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;
- return dlsym(handle, symbol);
+ rv = dlsym(handle, symbol);
+ rumphijack_unrope = *(volatile int *)rv;
+
+ return (void *)rv;
}
/* low calorie sockets? */
Home |
Main Index |
Thread Index |
Old Index