Skip to content

Commit

Permalink
i#4370: Fix CMake 3.18 and 3.19 build and test failures (#4582)
Browse files Browse the repository at this point in the history
Fixes multiple problems encountered with CMake 3.18+:

1) Deprecated old version support.  Solved by updating our minimums
   everywhere to 3.7 which was already our top-level minimum.  At this
   point it should be fine to require clients to use 3.7 too.

2) Missing -rdynamic for test executables, where some clients expect
    to find global symbols in .dynsym.  This is related to policy CMP0065.

3) Missing location property in the samples_proj test.
    The fix is in DynamoRIO_add_rel_rpaths(), instead of only using the per-file-type
    location property, use the actual path when the library is imported
    and we know the path at config time.

4) Assembly compilation breakage from two factors:

  A) The CMake-generated define -Ddynamorio_EXPORTS is being passed as
     --defsym dynamorio_EXPORTS in <DEFINES> for asm targets, but we pass
     that to cpp.

  B) Various compiler flags like --MD are in <FLAGS> and cpp does not
     like them.

My solution for assembly is to:

1) set(CMAKE_ASM_DEFINE_FLAG "-D")

2) Remove <FLAGS> from the cpp command for asm.
   We do end up needing "-mavx*" to set the built-in defines __AVX__, etc.
   I put in explicit setting of "-mavx*" using the existing avx support
   queries, shifted earlier during config.

3) Move all of our preprocessor defines from COMPILE_FLAGS properties with
   explicit -D to COMPILE_DEFINITIONS properites without -D so we get them
   in <DEFINES>.

   This was a little involved:
   + There were a number of places pasing defines as flags.

   + COMPILE_FLAGS is a string while COMPILE_DEFINITIONS is a list,
     necessitating some conversions and changes in handling.

   + I had to split out a new function DynamoRIO_extra_defines from
     DynamoRIO_extra_cflags.  I maintained the get_DynamoRIO_defines
     interface.

   + I had to update several places like in test setup where we remove
     defines to avoid duplicates from the command line and
     configure.h.

Fixes #4370
Fixes #4581
  • Loading branch information
derekbruening authored Dec 4, 2020
1 parent 536cbd0 commit 418c10c
Show file tree
Hide file tree
Showing 35 changed files with 191 additions and 161 deletions.
26 changes: 14 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,20 @@ set(INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
###########################################################################
# toolchain

# Figure out avx flags before asm setup, which requires it.
set(proc_supports_avx OFF)
set(proc_supports_avx2 OFF)
set(proc_supports_avx512 OFF)
if (UNIX)
set(CFLAGS_AVX "-mavx")
# BMI2 instructions are typically also supported on AVX2 processors.
set(CFLAGS_AVX2 "-mavx2 -mbmi2")
set(CFLAGS_AVX512 "-mavx512f")
check_avx_processor_and_compiler_support(proc_supports_avx)
check_avx2_processor_and_compiler_support(proc_supports_avx2)
check_avx512_processor_and_compiler_support(proc_supports_avx512)
endif ()

# Set up assembly support and CMAKE_CPP.
# Note that in cmake < 2.6.4, I had to fix a bug in
# /usr/share/cmake/Modules/CMakeASMInformation.cmake
Expand Down Expand Up @@ -1532,18 +1546,6 @@ if (BUILD_TESTS)
# Tests require tools
set(BUILD_TOOLS ON)
enable_testing()
set(proc_supports_avx OFF)
set(proc_supports_avx2 OFF)
set(proc_supports_avx512 OFF)
if (UNIX)
set(CFLAGS_AVX "-mavx")
# BMI2 instructions are typically also supported on AVX2 processors.
set(CFLAGS_AVX2 "-mavx2 -mbmi2")
set(CFLAGS_AVX512 "-mavx512f")
check_avx_processor_and_compiler_support(proc_supports_avx)
check_avx2_processor_and_compiler_support(proc_supports_avx2)
check_avx512_processor_and_compiler_support(proc_supports_avx512)
endif ()
# add Dashboard support
include(CTest)
endif (BUILD_TESTS)
Expand Down
8 changes: 4 additions & 4 deletions api/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# **********************************************************
# Copyright (c) 2010-2019 Google, Inc. All rights reserved.
# Copyright (c) 2010-2020 Google, Inc. All rights reserved.
# Copyright (c) 2009-2010 VMware, Inc. All rights reserved.
# **********************************************************

Expand Down Expand Up @@ -29,7 +29,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

if ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
set(DEBUG ON)
Expand Down Expand Up @@ -241,12 +241,12 @@ if (X86) # FIXME i#1551, i#1569: port to ARM and AArch64
"drcontainers;drmgr;drreg;drutil;drx")
add_sample_client(memtrace_x86_text "memtrace_x86.c;utils.c"
"drcontainers;drmgr;drreg;drutil;drx")
_DR_append_property_string(TARGET memtrace_x86_text COMPILE_DEFINITIONS "OUTPUT_TEXT")
_DR_append_property_list(TARGET memtrace_x86_text COMPILE_DEFINITIONS "OUTPUT_TEXT")
add_sample_client(instrace_x86_binary "instrace_x86.c;utils.c"
"drcontainers;drmgr;drreg;drx")
add_sample_client(instrace_x86_text "instrace_x86.c;utils.c"
"drcontainers;drmgr;drreg;drx")
_DR_append_property_string(TARGET instrace_x86_text COMPILE_DEFINITIONS "OUTPUT_TEXT")
_DR_append_property_list(TARGET instrace_x86_text COMPILE_DEFINITIONS "OUTPUT_TEXT")
add_sample_client(prefetch "prefetch.c" "drmgr")
if (NOT WIN32)
add_sample_client(ssljack "ssljack.c" "drmgr;drwrap")
Expand Down
2 changes: 1 addition & 1 deletion clients/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

set(DynamoRIO_INTERNAL ON) # do not import dynamorio lib target
set(DynamoRIO_DIR ${PROJECT_BINARY_DIR}/cmake)
Expand Down
6 changes: 3 additions & 3 deletions clients/drcachesim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ endmacro()

add_drmemtrace(drmemtrace SHARED)
add_drmemtrace(drmemtrace_static STATIC)
append_property_string(TARGET drmemtrace_static COMPILE_FLAGS "-DDRMEMTRACE_STATIC")
append_property_list(TARGET drmemtrace_static COMPILE_DEFINITIONS "DRMEMTRACE_STATIC")
# We export drmemtrace.h to the same place as the analysis tool headers
# for simplicity, rather than sticking it into ext/include or sthg.
install_client_nonDR_header(drmemtrace tracer/drmemtrace.h)
Expand Down Expand Up @@ -326,8 +326,8 @@ macro(restore_nonclient_flags target)
endif ()
# However, we need the target os and arch defines (XXX: better way?) for
# the config, inject, and frontend headers:
DynamoRIO_extra_cflags(extra_cflags "" ON)
append_property_string(TARGET ${target} COMPILE_FLAGS "${extra_cflags}")
DynamoRIO_extra_defines(extra_defs ON)
append_property_list(TARGET ${target} COMPILE_DEFINITIONS "${extra_defs}")
if (implicit_fallthrough_avail)
append_property_string(TARGET ${target} COMPILE_FLAGS "-Wimplicit-fallthrough")
endif ()
Expand Down
2 changes: 1 addition & 1 deletion clients/drcachesim/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# This is NOT a CMake file for building the various test suite executables in
# this tests/ directory: this is only for the --build-and-test test!

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

project(DynamoRIO_drmemtrace)

Expand Down
2 changes: 1 addition & 1 deletion clients/drcov/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

include(../../make/policies.cmake NO_POLICY_SCOPE)

Expand Down
2 changes: 1 addition & 1 deletion clients/drcpusim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

include(../../make/policies.cmake NO_POLICY_SCOPE)

Expand Down
2 changes: 1 addition & 1 deletion clients/drdisas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

include(../../make/policies.cmake NO_POLICY_SCOPE)

Expand Down
2 changes: 1 addition & 1 deletion clients/standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

include(../../make/policies.cmake NO_POLICY_SCOPE)

Expand Down
14 changes: 7 additions & 7 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ else (UNIX)
win32/resources.rc
)
set_target_properties(drearlyhelp1 PROPERTIES
COMPILE_FLAGS "-DRC_IS_EARLY1")
COMPILE_DEFINITIONS "RC_IS_EARLY1")
# base = (release base - 64k)
set_target_properties(drearlyhelp1 PROPERTIES
# not bothering with map files
Expand All @@ -466,7 +466,7 @@ else (UNIX)
win32/resources.rc
)
set_target_properties(drearlyhelp2 PROPERTIES
COMPILE_FLAGS "-DRC_IS_EARLY2")
COMPILE_DEFINITIONS "RC_IS_EARLY2")
# base = (helper1 base - 64k)
set_target_properties(drearlyhelp2 PROPERTIES
# not bothering with map files
Expand Down Expand Up @@ -918,7 +918,7 @@ copy_target_to_device(${PRELOAD_NAME} "${location_suffix}")
# drpreinject.dll doesn't link in instr_shared.c so we can't include our inline
# functions.
set_target_properties(${PRELOAD_NAME} PROPERTIES
COMPILE_FLAGS "-DNOT_DYNAMORIO_CORE_PROPER -DRC_IS_PRELOAD -DDR_NO_FAST_IR")
COMPILE_DEFINITIONS "NOT_DYNAMORIO_CORE_PROPER;RC_IS_PRELOAD;DR_NO_FAST_IR")

if (UNIX)
# FIXME case 69/1891: -z initfirst = initialize first at runtime (before libc)
Expand Down Expand Up @@ -971,7 +971,7 @@ add_library(drdecode
io.c
)
set_target_properties(drdecode PROPERTIES
COMPILE_FLAGS "-DNOT_DYNAMORIO_CORE_PROPER -DSTANDALONE_DECODER")
COMPILE_DEFINITIONS "NOT_DYNAMORIO_CORE_PROPER;STANDALONE_DECODER")
if (UNIX)
append_property_string(TARGET drdecode COMPILE_FLAGS "-fPIC")
endif (UNIX)
Expand Down Expand Up @@ -1006,9 +1006,8 @@ if (UNIX)
target_link_libraries(drinjectlib drmemfuncs)
endif ()
set_target_properties(drinjectlib PROPERTIES
# COMPILE_DEFINITONS isn't working for me: cmake bug?
# Set define parameters for resources.rc
COMPILE_FLAGS "-DNOT_DYNAMORIO_CORE_PROPER -DRC_IS_DRINJECTLIB")
COMPILE_DEFINITIONS "NOT_DYNAMORIO_CORE_PROPER;RC_IS_DRINJECTLIB")
if (WIN32)
set(drinjectlib_link_flags
# not bothering with map files
Expand Down Expand Up @@ -1103,7 +1102,8 @@ if (BUILD_TESTS AND NOT DR_HOST_NOT_TARGET)
endif ()
endif ()
set_target_properties(unit_tests PROPERTIES
COMPILE_FLAGS "-DRC_IS_TEST -DSTANDALONE_UNIT_TEST ${unit_tests_extra_flags}"
COMPILE_DEFINITIONS "RC_IS_TEST;STANDALONE_UNIT_TEST"
COMPILE_FLAGS "${unit_tests_extra_flags}"
RUNTIME_OUTPUT_DIRECTORY${location_suffix} "${EXECUTABLE_OUTPUT_DIRECTORY}")
if (UNIX)
if (NOT APPLE)
Expand Down
2 changes: 1 addition & 1 deletion core/unix/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -5389,7 +5389,7 @@ master_signal_handler_C(byte *xsp)
* The pointers may be different if a thread is on its way to exit, and the app's
* sigstack was already restored (i#3369).
*/
IF_LINUX(ASSERT(dcontext == NULL || dcontext == GLOBAL_DCONTEXT ||
IF_LINUX(ASSERT(dcontext == NULL || dcontext == GLOBAL_DCONTEXT || dynamo_exited ||
dcontext->is_exiting ||
frame->uc.uc_stack.ss_sp ==
((thread_sig_info_t *)dcontext->signal_field)->sigstack.ss_sp));
Expand Down
2 changes: 1 addition & 1 deletion ext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

# i#277/PR 540817: DynamoRIO Extensions support

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

include(../make/policies.cmake NO_POLICY_SCOPE)

Expand Down
2 changes: 1 addition & 1 deletion ext/drbbdup/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

include(../../make/policies.cmake NO_POLICY_SCOPE)

Expand Down
2 changes: 1 addition & 1 deletion ext/drcontainers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

include(../../make/policies.cmake NO_POLICY_SCOPE)

Expand Down
2 changes: 1 addition & 1 deletion ext/drcovlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

include(../../make/policies.cmake NO_POLICY_SCOPE)

Expand Down
2 changes: 1 addition & 1 deletion ext/drgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ elseif ("${CMAKE_VERSION}" VERSION_LESS "3.2")
message(STATUS "WARNING: CMake version is < 3.2: DrGUI will NOT be built")
else () # Qt5 and CMake 3.2+
# Build Qt Visualizer
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.7)

message(STATUS "Found Qt 5: DrGUI will be built")

Expand Down
2 changes: 1 addition & 1 deletion ext/drmgr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

include(../../make/policies.cmake NO_POLICY_SCOPE)

Expand Down
2 changes: 1 addition & 1 deletion ext/droption/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

include(../../make/policies.cmake NO_POLICY_SCOPE)

Expand Down
2 changes: 1 addition & 1 deletion ext/drreg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

include(../../make/policies.cmake NO_POLICY_SCOPE)

Expand Down
4 changes: 2 additions & 2 deletions ext/drsyms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

# symbol access library

cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.7)

include(../../make/policies.cmake NO_POLICY_SCOPE)

Expand Down Expand Up @@ -157,7 +157,7 @@ macro(configure_drsyms_target target)
endif ()
endif ()
# we always use the elftoolchain library when building with cmake
append_property_string(TARGET ${target} COMPILE_FLAGS "-DDRSYM_HAVE_LIBELFTC")
append_property_list(TARGET ${target} COMPILE_DEFINITIONS "DRSYM_HAVE_LIBELFTC")
endmacro(configure_drsyms_target)

configure_drsyms_target(drsyms)
Expand Down
2 changes: 1 addition & 1 deletion ext/drutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

include(../../make/policies.cmake NO_POLICY_SCOPE)

Expand Down
5 changes: 3 additions & 2 deletions ext/drwrap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

include(../../make/policies.cmake NO_POLICY_SCOPE)

Expand Down Expand Up @@ -90,7 +90,8 @@ macro(configure_drwrap_target target)
if (NOT "${CMAKE_GENERATOR}" MATCHES "Visual Studio")
# we need to add asm_defs to target b/c add_asm_target() is not able to set flags
# for non-VS generators
append_property_string(TARGET ${target} COMPILE_FLAGS "${asm_defs}")
string(REPLACE "-D" "" asm_defs_list "${asm_defs}")
append_property_list(TARGET ${target} COMPILE_DEFINITIONS "${asm_defs_list}")
endif ()

if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
Expand Down
2 changes: 1 addition & 1 deletion ext/drx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.

cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.7)

include(../../make/policies.cmake NO_POLICY_SCOPE)

Expand Down
11 changes: 7 additions & 4 deletions libutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ if (WIN32)

add_library(policy_static ${BASE_SRCS} ${ROOT_SRCS} ${CORE_SRCS})
set_target_properties(policy_static PROPERTIES
COMPILE_FLAGS "${libutil_cflags} -DNOT_DYNAMORIO_CORE")
COMPILE_FLAGS "${libutil_cflags}" COMPILE_DEFINITIONS "NOT_DYNAMORIO_CORE")
set_target_properties(policy_static PROPERTIES
LINK_FLAGS "${libutil_ldflags}")
add_gen_events_deps(policy_static)
Expand Down Expand Up @@ -144,7 +144,8 @@ set_target_properties(drconfiglib PROPERTIES
# Since it's hard to pass spaces in defines (I can get a " through using
# \\\\\\\" but no spaces) we put strings in resources.rc and select
# using RC_ defines.
COMPILE_FLAGS "${libutil_cflags} -DRC_IS_DRCONFIGLIB -DNOT_DYNAMORIO_CORE"
COMPILE_FLAGS "${libutil_cflags}"
COMPILE_DEFINITIONS "RC_IS_DRCONFIGLIB;NOT_DYNAMORIO_CORE"
# put in lib dir
RUNTIME_OUTPUT_DIRECTORY${location_suffix} "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
add_gen_events_deps(drconfiglib)
Expand All @@ -160,7 +161,8 @@ if (WIN32)
add_executable(dumpevts dumpevts.c elm.c ${RESOURCES})
set_target_properties(dumpevts PROPERTIES
# Set define parameters for resources.rc
COMPILE_FLAGS "${libutil_cflags} -DRC_IS_DUMPEVTS -DNOT_DYNAMORIO_CORE")
COMPILE_FLAGS "${libutil_cflags}"
COMPILE_DEFINITIONS "RC_IS_DUMPEVTS;NOT_DYNAMORIO_CORE")
set_target_properties(dumpevts PROPERTIES
LINK_FLAGS "${libutil_ldflags}")
add_gen_events_deps(dumpevts)
Expand All @@ -171,7 +173,8 @@ if (WIN32)
${RESOURCES} mfapi.c mfapi.res)
set_target_properties(mfapi PROPERTIES
# Set define parameters for resources.rc
COMPILE_FLAGS "${libutil_cflags} -DRC_IS_MFAPI -DNOT_DYNAMORIO_CORE")
COMPILE_FLAGS "${libutil_cflags}"
COMPILE_DEFINITIONS "RC_IS_MFAPI;NOT_DYNAMORIO_CORE")
set_target_properties(mfapi PROPERTIES
LINK_FLAGS "${libutil_ldflags}")
add_gen_events_deps(mfapi)
Expand Down
Loading

0 comments on commit 418c10c

Please sign in to comment.