cmake: rework elf detection (#1058)
This commit is contained in:
parent
8d13b3bb0c
commit
7e6fca90e8
@ -125,8 +125,11 @@ if (Unwind_FOUND)
|
|||||||
endif (Unwind_FOUND)
|
endif (Unwind_FOUND)
|
||||||
|
|
||||||
check_include_file_cxx (dlfcn.h HAVE_DLFCN_H)
|
check_include_file_cxx (dlfcn.h HAVE_DLFCN_H)
|
||||||
|
check_include_file_cxx (elf.h HAVE_ELF_H)
|
||||||
check_include_file_cxx (glob.h HAVE_GLOB_H)
|
check_include_file_cxx (glob.h HAVE_GLOB_H)
|
||||||
|
check_include_file_cxx (link.h HAVE_LINK_H)
|
||||||
check_include_file_cxx (pwd.h HAVE_PWD_H)
|
check_include_file_cxx (pwd.h HAVE_PWD_H)
|
||||||
|
check_include_file_cxx (sys/exec_elf.h HAVE_SYS_EXEC_ELF_H)
|
||||||
check_include_file_cxx (sys/syscall.h HAVE_SYS_SYSCALL_H)
|
check_include_file_cxx (sys/syscall.h HAVE_SYS_SYSCALL_H)
|
||||||
check_include_file_cxx (sys/time.h HAVE_SYS_TIME_H)
|
check_include_file_cxx (sys/time.h HAVE_SYS_TIME_H)
|
||||||
check_include_file_cxx (sys/types.h HAVE_SYS_TYPES_H)
|
check_include_file_cxx (sys/types.h HAVE_SYS_TYPES_H)
|
||||||
@ -275,9 +278,9 @@ if (WITH_SYMBOLIZE)
|
|||||||
set (HAVE_STACKTRACE 1)
|
set (HAVE_STACKTRACE 1)
|
||||||
endif (HAVE_SYMBOLIZE)
|
endif (HAVE_SYMBOLIZE)
|
||||||
elseif (UNIX)
|
elseif (UNIX)
|
||||||
cmake_push_check_state (RESET)
|
if (HAVE_ELF_H OR HAVE_SYS_EXEC_ELF_H)
|
||||||
check_cxx_symbol_exists (__ELF__ "" HAVE_SYMBOLIZE)
|
set (HAVE_SYMBOLIZE 1)
|
||||||
cmake_pop_check_state ()
|
endif (HAVE_ELF_H OR HAVE_SYS_EXEC_ELF_H)
|
||||||
elseif (APPLE AND HAVE_DLADDR)
|
elseif (APPLE AND HAVE_DLADDR)
|
||||||
set (HAVE_SYMBOLIZE 1)
|
set (HAVE_SYMBOLIZE 1)
|
||||||
endif (WIN32 OR CYGWIN)
|
endif (WIN32 OR CYGWIN)
|
||||||
|
|||||||
@ -86,11 +86,13 @@ def glog_library(with_gflags = 1, **kwargs):
|
|||||||
freebsd_only_copts = [
|
freebsd_only_copts = [
|
||||||
# Enable declaration of _Unwind_Backtrace
|
# Enable declaration of _Unwind_Backtrace
|
||||||
"-D_GNU_SOURCE",
|
"-D_GNU_SOURCE",
|
||||||
|
"-DHAVE_LINK_H",
|
||||||
]
|
]
|
||||||
|
|
||||||
linux_only_copts = [
|
linux_only_copts = [
|
||||||
# For utilities.h.
|
# For utilities.h.
|
||||||
"-DHAVE_EXECINFO_H",
|
"-DHAVE_EXECINFO_H",
|
||||||
|
"-DHAVE_LINK_H",
|
||||||
]
|
]
|
||||||
|
|
||||||
darwin_only_copts = [
|
darwin_only_copts = [
|
||||||
|
|||||||
@ -52,6 +52,15 @@
|
|||||||
/* Define to 1 if you have the <syslog.h> header file. */
|
/* Define to 1 if you have the <syslog.h> header file. */
|
||||||
#cmakedefine HAVE_SYSLOG_H
|
#cmakedefine HAVE_SYSLOG_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <elf.h> header file. */
|
||||||
|
#cmakedefine HAVE_ELF_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/exec_elf.h> header file. */
|
||||||
|
#cmakedefine HAVE_SYS_EXEC_ELF_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <link.h> header file. */
|
||||||
|
#cmakedefine HAVE_LINK_H
|
||||||
|
|
||||||
/* Define to 1 if you have the <sys/syscall.h> header file. */
|
/* Define to 1 if you have the <sys/syscall.h> header file. */
|
||||||
#cmakedefine HAVE_SYS_SYSCALL_H
|
#cmakedefine HAVE_SYS_SYSCALL_H
|
||||||
|
|
||||||
|
|||||||
@ -109,16 +109,11 @@ void InstallSymbolizeOpenObjectFileCallback(
|
|||||||
} // namespace glog_internal_namespace_
|
} // namespace glog_internal_namespace_
|
||||||
} // namespace google
|
} // namespace google
|
||||||
|
|
||||||
# if defined(__ELF__)
|
# if defined(HAVE_LINK_H)
|
||||||
|
|
||||||
# if defined(HAVE_DLFCN_H)
|
# if defined(HAVE_DLFCN_H)
|
||||||
# include <dlfcn.h>
|
# include <dlfcn.h>
|
||||||
# endif
|
# endif
|
||||||
# if defined(GLOG_OS_OPENBSD)
|
|
||||||
# include <sys/exec_elf.h>
|
|
||||||
# else
|
|
||||||
# include <elf.h>
|
|
||||||
# endif
|
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
|
|||||||
@ -61,6 +61,14 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "glog/platform.h"
|
#include "glog/platform.h"
|
||||||
|
|
||||||
|
#if defined(HAVE_LINK_H)
|
||||||
|
# include <link.h> // For ElfW() macro.
|
||||||
|
#elif defined(HAVE_ELF_H)
|
||||||
|
# include <elf.h>
|
||||||
|
#elif defined(HAVE_SYS_EXEC_ELF_H)
|
||||||
|
# include <sys/exec_elf.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(GLOG_USE_GLOG_EXPORT)
|
#if defined(GLOG_USE_GLOG_EXPORT)
|
||||||
# include "glog/export.h"
|
# include "glog/export.h"
|
||||||
#endif
|
#endif
|
||||||
@ -72,7 +80,7 @@
|
|||||||
#ifndef GLOG_NO_SYMBOLIZE_DETECTION
|
#ifndef GLOG_NO_SYMBOLIZE_DETECTION
|
||||||
# ifndef HAVE_SYMBOLIZE
|
# ifndef HAVE_SYMBOLIZE
|
||||||
// defined by gcc
|
// defined by gcc
|
||||||
# if defined(__ELF__) && defined(GLOG_OS_LINUX)
|
# if defined(HAVE_ELF_H) || defined(HAVE_SYS_EXEC_ELF_H)
|
||||||
# define HAVE_SYMBOLIZE
|
# define HAVE_SYMBOLIZE
|
||||||
# elif defined(GLOG_OS_MACOSX) && defined(HAVE_DLADDR)
|
# elif defined(GLOG_OS_MACOSX) && defined(HAVE_DLADDR)
|
||||||
// Use dladdr to symbolize.
|
// Use dladdr to symbolize.
|
||||||
@ -86,26 +94,11 @@
|
|||||||
|
|
||||||
#ifdef HAVE_SYMBOLIZE
|
#ifdef HAVE_SYMBOLIZE
|
||||||
|
|
||||||
# if defined(__ELF__) // defined by gcc
|
# if !defined(SIZEOF_VOID_P) && defined(__SIZEOF_POINTER__)
|
||||||
# if defined(__OpenBSD__)
|
# define SIZEOF_VOID_P __SIZEOF_POINTER__
|
||||||
# include <sys/exec_elf.h>
|
|
||||||
# else
|
|
||||||
# include <elf.h>
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if !defined(GLOG_OS_ANDROID)
|
# if defined(HAVE_ELF_H) || defined(HAVE_SYS_EXEC_ELF_H)
|
||||||
# include <link.h> // For ElfW() macro.
|
|
||||||
# endif
|
|
||||||
|
|
||||||
// For systems where SIZEOF_VOID_P is not defined, determine it
|
|
||||||
// based on __LP64__ (defined by gcc on 64-bit systems)
|
|
||||||
# if !defined(SIZEOF_VOID_P)
|
|
||||||
# if defined(__LP64__)
|
|
||||||
# define SIZEOF_VOID_P 8
|
|
||||||
# else
|
|
||||||
# define SIZEOF_VOID_P 4
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
|
|
||||||
// If there is no ElfW macro, let's define it by ourself.
|
// If there is no ElfW macro, let's define it by ourself.
|
||||||
# ifndef ElfW
|
# ifndef ElfW
|
||||||
@ -130,7 +123,7 @@ bool GetSectionHeaderByName(int fd, const char* name, size_t name_len,
|
|||||||
} // namespace glog_internal_namespace_
|
} // namespace glog_internal_namespace_
|
||||||
} // namespace google
|
} // namespace google
|
||||||
|
|
||||||
# endif /* __ELF__ */
|
# endif
|
||||||
|
|
||||||
namespace google {
|
namespace google {
|
||||||
inline namespace glog_internal_namespace_ {
|
inline namespace glog_internal_namespace_ {
|
||||||
|
|||||||
@ -40,6 +40,7 @@
|
|||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
#include "googletest.h"
|
#include "googletest.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
#include "stacktrace.h"
|
||||||
|
|
||||||
#ifdef GLOG_USE_GFLAGS
|
#ifdef GLOG_USE_GFLAGS
|
||||||
# include <gflags/gflags.h>
|
# include <gflags/gflags.h>
|
||||||
@ -60,7 +61,8 @@ using namespace google;
|
|||||||
|
|
||||||
# define always_inline
|
# define always_inline
|
||||||
|
|
||||||
# if defined(__ELF__) || defined(GLOG_OS_WINDOWS) || defined(GLOG_OS_CYGWIN)
|
# if defined(HAVE_ELF_H) || defined(HAVE_SYS_EXEC_ELF_H) || \
|
||||||
|
defined(GLOG_OS_WINDOWS) || defined(GLOG_OS_CYGWIN)
|
||||||
// A wrapper function for Symbolize() to make the unit test simple.
|
// A wrapper function for Symbolize() to make the unit test simple.
|
||||||
static const char* TrySymbolize(void* pc, google::SymbolizeOptions options =
|
static const char* TrySymbolize(void* pc, google::SymbolizeOptions options =
|
||||||
google::SymbolizeOptions::kNone) {
|
google::SymbolizeOptions::kNone) {
|
||||||
@ -73,8 +75,7 @@ static const char* TrySymbolize(void* pc, google::SymbolizeOptions options =
|
|||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if defined(__ELF__)
|
# if defined(HAVE_ELF_H) || defined(HAVE_SYS_EXEC_ELF_H)
|
||||||
|
|
||||||
// This unit tests make sense only with GCC.
|
// This unit tests make sense only with GCC.
|
||||||
// Uses lots of GCC specific features.
|
// Uses lots of GCC specific features.
|
||||||
# if defined(__GNUC__) && !defined(__OPENCC__)
|
# if defined(__GNUC__) && !defined(__OPENCC__)
|
||||||
@ -449,7 +450,7 @@ __declspec(noinline) void TestWithReturnAddress() {
|
|||||||
# endif
|
# endif
|
||||||
cout << "Test case TestWithReturnAddress passed." << endl;
|
cout << "Test case TestWithReturnAddress passed." << endl;
|
||||||
}
|
}
|
||||||
# endif // __ELF__
|
# endif
|
||||||
#endif // HAVE_STACKTRACE
|
#endif // HAVE_STACKTRACE
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
@ -457,7 +458,7 @@ int main(int argc, char** argv) {
|
|||||||
InitGoogleLogging(argv[0]);
|
InitGoogleLogging(argv[0]);
|
||||||
InitGoogleTest(&argc, argv);
|
InitGoogleTest(&argc, argv);
|
||||||
#if defined(HAVE_SYMBOLIZE) && defined(HAVE_STACKTRACE)
|
#if defined(HAVE_SYMBOLIZE) && defined(HAVE_STACKTRACE)
|
||||||
# if defined(__ELF__)
|
# if defined(HAVE_ELF_H) || defined(HAVE_SYS_EXEC_ELF_H)
|
||||||
// We don't want to get affected by the callback interface, that may be
|
// We don't want to get affected by the callback interface, that may be
|
||||||
// used to install some callback function at InitGoogle() time.
|
// used to install some callback function at InitGoogle() time.
|
||||||
InstallSymbolizeCallback(nullptr);
|
InstallSymbolizeCallback(nullptr);
|
||||||
@ -472,7 +473,7 @@ int main(int argc, char** argv) {
|
|||||||
# else // GLOG_OS_WINDOWS
|
# else // GLOG_OS_WINDOWS
|
||||||
printf("PASS (no symbolize_unittest support)\n");
|
printf("PASS (no symbolize_unittest support)\n");
|
||||||
return 0;
|
return 0;
|
||||||
# endif // __ELF__
|
# endif // defined(HAVE_ELF_H) || defined(HAVE_SYS_EXEC_ELF_H)
|
||||||
#else
|
#else
|
||||||
printf("PASS (no symbolize support)\n");
|
printf("PASS (no symbolize support)\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user