[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Libunwind-devel] Fix compilation on non-glibc machines.
From: |
Konstantin Belousov |
Subject: |
[Libunwind-devel] Fix compilation on non-glibc machines. |
Date: |
Sat, 26 Nov 2011 19:30:53 +0200 |
User-agent: |
Mutt/1.4.2.3i |
Commit 297d9cd07d7ea9b541fb13bffe418 (Fix for failing test-setjmp)
breaks non glibc systems, since __GLIBC_PREREQ is not defined there.
As a consequence, preprocessor aborts with an error.
Trying to hide __GLIBC_PREREQ under #ifdef __GLIBC would require
either code duplication, or moving the longjmp implementation into
the separate file, which is included twice. In fact, I am not sure
in any use of the __GLIBC_PREREQ at the compile time, because the
compiled code can be run on the later version of glibc.
Below is the patch, tested on FreeBSD x86/x86_64 and Scientific Linux 6.1
x86_64. I compile the code always, but keep it in under unused static
symbol. In principle, the code could be optimized out by linker.
diff --git a/src/setjmp/longjmp.c b/src/setjmp/longjmp.c
index 00a58c2..bf2df4c 100644
--- a/src/setjmp/longjmp.c
+++ b/src/setjmp/longjmp.c
@@ -35,7 +35,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. */
#include "jmpbuf.h"
#include "setjmp_i.h"
-#if defined(__GLIBC__) && __GLIBC_PREREQ(2, 4)
+#if defined(__GLIBC__)
+#if __GLIBC_PREREQ(2, 4)
/* Starting with glibc-2.4, {sig,}setjmp in GLIBC obfuscates the
register values in jmp_buf by XORing them with a "random"
@@ -46,8 +47,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. */
Doing so is possible, but doesn't appear to be worth the trouble,
so we simply defer to glibc longjmp here. */
-
-#else
+#define _longjmp __nonworking__longjmp
+#define longjmp __nonworking_longjmp
+static void _longjmp (jmp_buf env, int val);
+static void longjmp (jmp_buf env, int val);
+#endif
+#endif
void
_longjmp (jmp_buf env, int val)
@@ -95,7 +100,9 @@ _longjmp (jmp_buf env, int val)
}
#ifdef __GNUC__
-void longjmp (jmp_buf env, int val) __attribute__ ((alias ("_longjmp")));
+#define STRINGIFY1(x) #x
+#define STRINGIFY(x) STRINGIFY1(x)
+void longjmp (jmp_buf env, int val) __attribute__ ((alias
(STRINGIFY(_longjmp))));
#else
void
@@ -104,6 +111,4 @@ longjmp (jmp_buf env, int val)
_longjmp (env, val);
}
-#endif /* __GLIBC__ */
-
#endif
diff --git a/src/setjmp/siglongjmp.c b/src/setjmp/siglongjmp.c
index bfe148b..6e7cb66 100644
--- a/src/setjmp/siglongjmp.c
+++ b/src/setjmp/siglongjmp.c
@@ -35,7 +35,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. */
# define _NSIG (_SIG_MAXSIG - 1)
#endif
-#if defined(__GLIBC__) && __GLIBC_PREREQ(2, 4)
+#if defined(__GLIBC_PREREQ)
+#if __GLIBC_PREREQ(2, 4)
/* Starting with glibc-2.4, {sig,}setjmp in GLIBC obfuscates the
register values in jmp_buf by XORing them with a "random"
@@ -47,7 +48,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. */
Doing so is possible, but doesn't appear to be worth the trouble,
so we simply defer to glibc siglongjmp here. */
-#else
+#define siglongjmp __nonworking_siglongjmp
+static void siglongjmp (sigjmp_buf env, int val);
+#endif
+#endif
void
siglongjmp (sigjmp_buf env, int val)
@@ -114,5 +118,3 @@ siglongjmp (sigjmp_buf env, int val)
abort ();
}
-
-#endif /* __GLIBC__ */
pgpsZ0SQgDdvM.pgp
Description: PGP signature
- [Libunwind-devel] Fix compilation on non-glibc machines.,
Konstantin Belousov <=