Skip to content

Commit

Permalink
cmake: rework elf detection
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiud committed Dec 30, 2023
1 parent 546906f commit 8fd1d2e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ endif (Unwind_FOUND)

check_include_file_cxx (dlfcn.h HAVE_DLFCN_H)
check_include_file_cxx (glob.h HAVE_GLOB_H)
check_include_file_cxx (link.h HAVE_LINK_H)
check_include_file_cxx (memory.h HAVE_MEMORY_H)
check_include_file_cxx (pwd.h HAVE_PWD_H)
check_include_file_cxx (strings.h HAVE_STRINGS_H)
Expand Down Expand Up @@ -378,9 +379,9 @@ if (WITH_SYMBOLIZE)
set (HAVE_STACKTRACE 1)
endif (HAVE_SYMBOLIZE)
elseif (UNIX)
cmake_push_check_state (RESET)
check_cxx_symbol_exists (__ELF__ "" HAVE_SYMBOLIZE)
cmake_pop_check_state ()
if (HAVE_LINK_H)
set (HAVE_SYMBOLIZE 1)
endif (HAVE_LINK_H)
elseif (APPLE AND HAVE_DLADDR)
set (HAVE_SYMBOLIZE 1)
endif (WIN32 OR CYGWIN)
Expand Down
3 changes: 3 additions & 0 deletions bazel/glog.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
"-Wno-unused-function",
"-Wno-unused-local-typedefs",
"-Wno-unused-variable",
"-DHAVE_ELF_H",
# Allows src/base/mutex.h to include pthread.h.
"-DHAVE_PTHREAD",
# Allows src/logging.cc to determine the host name.
Expand All @@ -83,6 +84,7 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):

linux_or_darwin_copts = wasm_copts + [
"-DGLOG_EXPORT=__attribute__((visibility(\\\"default\\\")))",
"-DHAVE_LINK_H",
# For src/utilities.cc.
"-DHAVE_SYS_SYSCALL_H",
# For src/logging.cc to create symlinks.
Expand All @@ -94,6 +96,7 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs):
freebsd_only_copts = [
# Enable declaration of _Unwind_Backtrace
"-D_GNU_SOURCE",
"-DHAVE_ELF_H",
]

linux_only_copts = [
Expand Down
3 changes: 3 additions & 0 deletions src/config.h.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
/* Define to 1 if you have the <syslog.h> header file. */
#cmakedefine HAVE_SYSLOG_H

/* Define to 1 if you have the <link.h> header file. */
#cmakedefine HAVE_LINK_H

/* Define to 1 if you have the <sys/stat.h> header file. */
#cmakedefine HAVE_SYS_STAT_H

Expand Down
10 changes: 3 additions & 7 deletions src/symbolize.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2006, Google Inc.
// Copyright (c) 2023, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -108,17 +108,13 @@ static ATTRIBUTE_NOINLINE void DemangleInplace(char *out, size_t out_size) {

_END_GOOGLE_NAMESPACE_

#if defined(__ELF__)
#if defined(HAVE_LINK_H)

#if defined(HAVE_DLFCN_H)
#include <dlfcn.h>
#endif
#if defined(GLOG_OS_OPENBSD)
#include <sys/exec_elf.h>
#else
#include <elf.h>
#endif
#include <fcntl.h>
#include <link.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
Expand Down

0 comments on commit 8fd1d2e

Please sign in to comment.