Преглед изворни кода

Fix fdatasync() feature detection in opensource build.

The CMake feature-detection code used check_symbol_exists(), which
invokes the C compiler. However, some glibc versions don't expose the
fdatasync() declaration when compiled with -std=c11, but do expose it
when compiled with -std=c++11. This most likely comes down to how
_POSIX_SOURCE is defined -- it needs to be >= 201112L for <unistd.h> to
expose fdatasync().

This CL switches to check_cxx_symbol_exists(), which uses the C++
compiler. Asides from fixing the problem above, this is the right thing
to do, because we use <unistd.h> in env_posix.cc, which is compiled with
the C++ compiler.

This CL also fixes a previously introduced inconsistency, where the
macro indicating the fdatasync() feature detection result was referred
to as HAVE_FDATASYNC and HAVE_FUNC_FDATASYNC. The former appears to be
used in other libraries, so this CL switches all our references to
HAVE_FDATASYNC.

Fixes https://github.com/google/leveldb/issues/629

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=228392612
main
costan пре 6 година
committed by Victor Costan
родитељ
комит
b70493ca85
2 измењених фајлова са 10 додато и 5 уклоњено
  1. +7
    -2
      CMakeLists.txt
  2. +3
    -3
      port/port_config.h.in

+ 7
- 2
CMakeLists.txt Прегледај датотеку

@ -30,8 +30,13 @@ check_library_exists(crc32c crc32c_value "" HAVE_CRC32C)
check_library_exists(snappy snappy_compress "" HAVE_SNAPPY)
check_library_exists(tcmalloc malloc "" HAVE_TCMALLOC)
include(CheckSymbolExists)
check_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC)
include(CheckCXXSymbolExists)
# Using check_cxx_symbol_exists() instead of check_c_symbol_exists() because
# we're including the header from C++, and feature detection should use the same
# compiler language that the project will use later. Principles aside, some
# versions of do not expose fdatasync() in <unistd.h> in standard C mode
# (-std=c11), but do expose the function in standard C++ mode (-std=c++11).
check_cxx_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC)
include(CheckCXXSourceCompiles)

+ 3
- 3
port/port_config.h.in Прегледај датотеку

@ -6,9 +6,9 @@
#define STORAGE_LEVELDB_PORT_PORT_CONFIG_H_
// Define to 1 if you have a definition for fdatasync() in <unistd.h>.
#if !defined(HAVE_FUNC_FDATASYNC)
#cmakedefine01 HAVE_FUNC_FDATASYNC
#endif // !defined(HAVE_FUNC_FDATASYNC)
#if !defined(HAVE_FDATASYNC)
#cmakedefine01 HAVE_FDATASYNC
#endif // !defined(HAVE_FDATASYNC)
// Define to 1 if you have Google CRC32C.
#if !defined(HAVE_CRC32C)

Loading…
Откажи
Сачувај