1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2025-02-02 20:52:55 +01:00

Fix compilation on non-glibc machines.

Commit 297d9cd07d (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.

[ Minor formatting edits: asharma@fb.com ]
This commit is contained in:
Konstantin Belousov 2011-11-26 19:30:53 +02:00 committed by Arun Sharma
parent 1010880548
commit 2b606faa21
2 changed files with 19 additions and 11 deletions

View file

@ -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 /* __GLIBC__ */
void
_longjmp (jmp_buf env, int val)
@ -95,7 +100,10 @@ _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 +112,4 @@ longjmp (jmp_buf env, int val)
_longjmp (env, val);
}
#endif /* __GLIBC__ */
#endif
#endif /* __GNUC__ */

View file

@ -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__)
#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 /* __GLIBC_PREREQ */
void
siglongjmp (sigjmp_buf env, int val)
@ -114,5 +118,3 @@ siglongjmp (sigjmp_buf env, int val)
abort ();
}
#endif /* __GLIBC__ */