From c12c7cbff47414ba3c843e86a7c336802f0217f8 Mon Sep 17 00:00:00 2001 From: "Keith W. Campbell" Date: Wed, 1 Apr 2020 13:03:39 -0400 Subject: [PATCH] Generate libX.debuginfo instead of libX.so.dbg * rework computation of debug info filenames Signed-off-by: Keith W. Campbell --- .gitignore | 7 ++-- cmake/modules/OmrTargetSupport.cmake | 6 +-- cmake/modules/OmrUtility.cmake | 48 ++++++++++++++++++++++-- cmake/modules/platform/toolcfg/gnu.cmake | 8 ++-- cmake/modules/platform/toolcfg/xlc.cmake | 9 +++-- doc/ddr.md | 8 ++-- 6 files changed, 63 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index d858cd2263..cb9f11eca8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2014, 2019 IBM Corp. and others +# Copyright (c) 2014, 2020 IBM Corp. and others # # This program and the accompanying materials are made available under # the terms of the Eclipse Public License 2.0 which accompanies this @@ -112,13 +112,12 @@ Testing/ *.lo *.o *.obj -*.dbg +*.debuginfo # Compiled Dynamic libraries *.so -*.so.dbg *.dylib -*.dylib.dbg +*.dSYM *.def *.dll *.exp diff --git a/cmake/modules/OmrTargetSupport.cmake b/cmake/modules/OmrTargetSupport.cmake index ada79fea6a..8e63700786 100644 --- a/cmake/modules/OmrTargetSupport.cmake +++ b/cmake/modules/OmrTargetSupport.cmake @@ -33,15 +33,14 @@ include(OmrUtility) # and split debug info are handled function(omr_add_library name) set(options SHARED STATIC OBJECT INTERFACE) - set(oneValueArgs ) - set(multiValueArgs ) + set(oneValueArgs) + set(multiValueArgs) foreach(var IN LISTS options oneValueArgs multiValueArgs) set(opt_${var} "") endforeach() cmake_parse_arguments(opt "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - omr_count_true(num_types VARIABLES opt_SHARED opt_STATIC opt_OBJECT opt_INTERFACE) omr_assert(TEST num_types LESS 2 MESSAGE "Only one of STATIC | SHARED | OBJECT | INTERFACE may be given") @@ -75,7 +74,6 @@ function(omr_add_library name) endif() endfunction() - # omr_add_executable(name ...) # At present, a thin wrapper around add_executable, but it ensures that # split debug info is handled diff --git a/cmake/modules/OmrUtility.cmake b/cmake/modules/OmrUtility.cmake index 9d0dd9b6b7..a62d1f6892 100644 --- a/cmake/modules/OmrUtility.cmake +++ b/cmake/modules/OmrUtility.cmake @@ -97,9 +97,8 @@ endmacro(omr_list_contains) # processes a template file by first expanding variable references, and then # evaluating generator expressions. @ONLY and ESCAPE_QUOTES are treated as # they are for configure_file(). -# NOTE: like file(GENERATE ) output is not written until the end cmake evaluation +# NOTE: like file(GENERATE) output is not written until the end of cmake evaluation function(omr_process_template input output) - set(opts @ONLY ESCAPE_QUOTES) cmake_parse_arguments(opt "${opts}" "" "" ${ARGN}) @@ -118,7 +117,7 @@ function(omr_process_template input output) file(READ "${input_abs}" template) string(CONFIGURE "${template}" configured_template ${configure_args}) file(GENERATE OUTPUT "${output}" CONTENT "${configured_template}") -endfunction() +endfunction(omr_process_template) # omr_count_true( [...] [VARIABLES ...]) # count the nuber of and which evaluate to true @@ -138,4 +137,45 @@ function(omr_count_true out) endforeach() math(EXPR result "${result}") set("${out}" "${result}" PARENT_SCOPE) -endfunction() +endfunction(omr_count_true) + +# return the path of the target ${tgt} in VAR +# (only executable and shared library targets are currently supported) +function(omr_get_target_path VAR tgt) + get_target_property(target_type ${tgt} TYPE) + if(target_type STREQUAL "EXECUTABLE") + get_target_property(target_directory ${tgt} RUNTIME_OUTPUT_DIRECTORY) + get_target_property(target_name ${tgt} RUNTIME_OUTPUT_NAME) + if(NOT target_name) + set(target_name "${tgt}${CMAKE_EXECUTABLE_SUFFIX}") + endif() + elseif(target_type STREQUAL "SHARED_LIBRARY") + get_target_property(target_directory ${tgt} LIBRARY_OUTPUT_DIRECTORY) + get_target_property(target_name ${tgt} LIBRARY_OUTPUT_NAME) + if(NOT target_name) + set(target_name "lib${tgt}${CMAKE_SHARED_LIBRARY_SUFFIX}") + endif() + else() + message(FATAL_ERROR "omr_get_target_path: ${tgt} type is ${target_type}") + endif() + set(${VAR} "${target_directory}/${target_name}" PARENT_SCOPE) +endfunction(omr_get_target_path) + +# replace the suffix of ${input} with ${new_suffix} +# +# The suffix is defined here as the portion string +# starting with the last "." in the last path segment. +# This is consistent with: +# get_filename_component(suffix ${input} LAST_EXT) +# without requiring cmake version 3.14. +function(omr_replace_suffix VAR input new_suffix) + string(FIND "${input}" "/" slash_index REVERSE) + string(FIND "${input}" "." dot_index REVERSE) + if(dot_index GREATER slash_index) + string(SUBSTRING "${input}" 0 ${dot_index} base) + set(result "${base}${new_suffix}") + else() + set(result "${input}${new_suffix}") + endif() + set(${VAR} "${result}" PARENT_SCOPE) +endfunction(omr_replace_suffix) diff --git a/cmake/modules/platform/toolcfg/gnu.cmake b/cmake/modules/platform/toolcfg/gnu.cmake index 8eecb95505..cfe508300f 100644 --- a/cmake/modules/platform/toolcfg/gnu.cmake +++ b/cmake/modules/platform/toolcfg/gnu.cmake @@ -87,20 +87,22 @@ endif() function(_omr_toolchain_separate_debug_symbols tgt) set(exe_file "$") - set(dbg_file "$.dbg") if(OMR_OS_OSX) + set(dbg_file "${exe_file}.dSYM") add_custom_command( TARGET "${tgt}" POST_BUILD - COMMAND dsymutil -f ${exe_file} -o ${dbg_file} + COMMAND dsymutil -o "${dbg_file}" "${exe_file}" ) else() + omr_get_target_path(target_path ${tgt}) + omr_replace_suffix(dbg_file "${target_path}" ".debuginfo") add_custom_command( TARGET "${tgt}" POST_BUILD COMMAND "${CMAKE_OBJCOPY}" --only-keep-debug "${exe_file}" "${dbg_file}" COMMAND "${CMAKE_OBJCOPY}" --strip-debug "${exe_file}" - COMMAND "${CMAKE_OBJCOPY}" "--add-gnu-debuglink=${dbg_file}" "${exe_file}" + COMMAND "${CMAKE_OBJCOPY}" --add-gnu-debuglink="${dbg_file}" "${exe_file}" ) endif() set_target_properties(${tgt} PROPERTIES OMR_DEBUG_FILE "${dbg_file}") diff --git a/cmake/modules/platform/toolcfg/xlc.cmake b/cmake/modules/platform/toolcfg/xlc.cmake index d94382a79f..cbb620775e 100644 --- a/cmake/modules/platform/toolcfg/xlc.cmake +++ b/cmake/modules/platform/toolcfg/xlc.cmake @@ -189,9 +189,9 @@ if(OMR_OS_ZOS) endif() add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND "${CMAKE_COMMAND}" - "-DLIBRARY_FILE_NAME=$" - "-DLIBRARY_FOLDER=$" - -P "${omr_SOURCE_DIR}/cmake/modules/platform/toolcfg/zos_rename_exports.cmake" + "-DLIBRARY_FILE_NAME=$" + "-DLIBRARY_FOLDER=$" + -P "${omr_SOURCE_DIR}/cmake/modules/platform/toolcfg/zos_rename_exports.cmake" ) endfunction() else() @@ -212,7 +212,8 @@ else() function(_omr_toolchain_separate_debug_symbols tgt) set(exe_file "$") - set(dbg_file "$.dbg") + omr_get_target_path(target_path ${tgt}) + omr_replace_suffix(dbg_file "${target_path}" ".debuginfo") add_custom_command( TARGET "${tgt}" POST_BUILD diff --git a/doc/ddr.md b/doc/ddr.md index d1d48af183..9377033735 100644 --- a/doc/ddr.md +++ b/doc/ddr.md @@ -1,5 +1,5 @@