1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-25 08:37:38 +01:00

Check __builtin___clear_cache() at configuration time

Fixup commit 39b83981 ("Flush icache with __builtin___clear_cache() in
tests when compiling with GCC") to fix compilation with older GCC
versions that do not provide __builtin___clear_cache().
This commit is contained in:
Tommi Rantala 2012-08-30 14:18:33 +03:00
parent a15874f2cb
commit aed6c8b994
6 changed files with 62 additions and 20 deletions

View file

@ -277,6 +277,17 @@ if test x$intel_compiler = xyes; then
AC_MSG_RESULT([$have_static_libcxa]) AC_MSG_RESULT([$have_static_libcxa])
fi fi
AC_MSG_CHECKING([for __builtin___clear_cache])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[]], [[__builtin___clear_cache(0, 0)]])],
[have__builtin___clear_cache=yes],
[have__builtin___clear_cache=no])
if test x$have__builtin___clear_cache = xyes; then
AC_DEFINE([HAVE__BUILTIN___CLEAR_CACHE], [1],
[Defined if __builtin___clear_cache() is available])
fi
AC_MSG_RESULT([$have__builtin___clear_cache])
CCASFLAGS="${CCASFLAGS} ${CPPFLAGS}" CCASFLAGS="${CCASFLAGS} ${CPPFLAGS}"
arch="$target_arch" arch="$target_arch"

View file

@ -25,6 +25,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/* This file tests dynamic code-generation via function-cloning. */ /* This file tests dynamic code-generation via function-cloning. */
#include "flush-cache.h"
#include <libunwind.h> #include <libunwind.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -86,10 +88,6 @@ struct fdesc
# define get_gp(fdesc) (0) # define get_gp(fdesc) (0)
#endif #endif
#ifndef __GNUC__
extern void flush_cache (void *addr, size_t len);
#endif
void void
template (int i, template_t self, template (int i, template_t self,
int (*printer)(const char *, ...), const char *fmt, const char **arr) int (*printer)(const char *, ...), const char *fmt, const char **arr)
@ -187,11 +185,7 @@ main (int argc, char *argv[] __attribute__((unused)))
mprotect ((void *) ((long) mem & ~(getpagesize () - 1)), mprotect ((void *) ((long) mem & ~(getpagesize () - 1)),
2*getpagesize(), PROT_READ | PROT_WRITE | PROT_EXEC); 2*getpagesize(), PROT_READ | PROT_WRITE | PROT_EXEC);
#ifdef __GNUC__
__builtin___clear_cache(mem, mem + MAX_FUNC_SIZE);
#else
flush_cache (mem, MAX_FUNC_SIZE); flush_cache (mem, MAX_FUNC_SIZE);
#endif
signal (SIGSEGV, sighandler); signal (SIGSEGV, sighandler);

View file

@ -101,15 +101,16 @@ Lia64_test_rbs_SOURCES = Lia64-test-rbs.c ia64-test-rbs-asm.S ia64-test-rbs.h
Gia64_test_rbs_SOURCES = Gia64-test-rbs.c ia64-test-rbs-asm.S ia64-test-rbs.h Gia64_test_rbs_SOURCES = Gia64-test-rbs.c ia64-test-rbs-asm.S ia64-test-rbs.h
Lia64_test_nat_SOURCES = Lia64-test-nat.c ia64-test-nat-asm.S Lia64_test_nat_SOURCES = Lia64-test-nat.c ia64-test-nat-asm.S
Gia64_test_nat_SOURCES = Gia64-test-nat.c ia64-test-nat-asm.S Gia64_test_nat_SOURCES = Gia64-test-nat.c ia64-test-nat-asm.S
ia64_test_dyn1_SOURCES = ia64-test-dyn1.c ia64-dyn-asm.S flush-cache.S ia64_test_dyn1_SOURCES = ia64-test-dyn1.c ia64-dyn-asm.S flush-cache.S \
flush-cache.h
ppc64_test_altivec_SOURCES = ppc64-test-altivec.c ppc64-test-altivec-utils.c ppc64_test_altivec_SOURCES = ppc64-test-altivec.c ppc64-test-altivec-utils.c
ppc64_test_wchar_SOURCES = ppc64-test-wchar.c ppc64_test_wchar_SOURCES = ppc64-test-wchar.c
Gtest_init_SOURCES = Gtest-init.cxx Gtest_init_SOURCES = Gtest-init.cxx
Ltest_init_SOURCES = Ltest-init.cxx Ltest_init_SOURCES = Ltest-init.cxx
Ltest_cxx_exceptions_SOURCES = Ltest-cxx-exceptions.cxx Ltest_cxx_exceptions_SOURCES = Ltest-cxx-exceptions.cxx
Gtest_dyn1_SOURCES = Gtest-dyn1.c flush-cache.S Gtest_dyn1_SOURCES = Gtest-dyn1.c flush-cache.S flush-cache.h
Ltest_dyn1_SOURCES = Ltest-dyn1.c flush-cache.S Ltest_dyn1_SOURCES = Ltest-dyn1.c flush-cache.S flush-cache.h
test_static_link_SOURCES = test-static-link-loc.c test-static-link-gen.c test_static_link_SOURCES = test-static-link-loc.c test-static-link-gen.c
test_static_link_LDFLAGS = -static test_static_link_LDFLAGS = -static
forker_LDFLAGS = -static forker_LDFLAGS = -static

View file

@ -1,4 +1,8 @@
#ifndef __GNUC__ #ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifndef HAVE__BUILTIN___CLEAR_CACHE
#if defined(__ia64__) #if defined(__ia64__)

38
tests/flush-cache.h Normal file
View file

@ -0,0 +1,38 @@
/* libunwind - a platform-independent unwind library
Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#ifndef FLUSH_CACHE_H
#define FLUSH_CACHE_H
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE__BUILTIN___CLEAR_CACHE
#define flush_cache(ADDR, LEN) \
__builtin___clear_cache((ADDR), (ADDR) + (LEN))
#else
#include <stddef.h>
extern void flush_cache (void *addr, size_t len);
#endif
#endif /* FLUSH_CACHE_H */

View file

@ -1,3 +1,5 @@
#include "flush-cache.h"
#include <assert.h> #include <assert.h>
#include <libunwind.h> #include <libunwind.h>
#include <unistd.h> #include <unistd.h>
@ -20,10 +22,6 @@ int verbose;
# define EXTRA 0 # define EXTRA 0
#endif #endif
#ifndef __GNUC__
extern void flush_cache (void *addr, size_t len);
#endif
int int
make_executable (void *addr, size_t len) make_executable (void *addr, size_t len)
{ {
@ -33,11 +31,7 @@ make_executable (void *addr, size_t len)
perror ("mprotect"); perror ("mprotect");
return -1; return -1;
} }
#ifdef __GNUC__
__builtin___clear_cache(addr, addr + len);
#else
flush_cache (addr, len); flush_cache (addr, len);
#endif
return 0; return 0;
} }