Skip to content

Commit

Permalink
Add prefix-map compile options
Browse files Browse the repository at this point in the history
GCC starting with version 8 supports a flag called -fmacro-prefix-map
that allows you to remap source paths. This will affect the __FILE__
macro.
This patch remaps the core directory to . so we leak fewer build system
paths into the final binaries.

This patch also adds -fdebug-prefix-map parameter to the compiler calls.
This is usually something you want which is why it is enabled by
default (and maps the same was as -fmacro-prefix-map).
To disable the behaviour the new cmake option DEBUG_PREFIX_MAP has been
added. This can be set to NO to disable remapping of debug source paths.

The patch also disables DEBUG_PREFIX_MAP for RPM and DEB builds, because
these build systems rewrite the paths themselves and thus need them
unchanged.
  • Loading branch information
arogge committed Oct 9, 2019
1 parent 7731644 commit ad8056e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
18 changes: 18 additions & 0 deletions core/CMakeLists.txt
Expand Up @@ -48,6 +48,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()

include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(-Wsuggest-override compiler_will_suggest_override)

Expand All @@ -65,6 +66,23 @@ if (${compiler_error_format_security})
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=format-security")
endif()

option(DEBUG_PREFIX_MAP "remap absolute debug paths to relative if compiler supports it" ON)
CHECK_C_COMPILER_FLAG(-fdebug-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=. c_compiler_debug_prefix_map)
CHECK_CXX_COMPILER_FLAG(-fdebug-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=. cxx_compiler_debug_prefix_map)
if(DEBUG_PREFIX_MAP AND c_compiler_debug_prefix_map AND cxx_compiler_debug_prefix_map)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdebug-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdebug-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.")
endif()

CHECK_C_COMPILER_FLAG(-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=. c_compiler_macro_prefix_map)
CHECK_CXX_COMPILER_FLAG(-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=. cxx_compiler_macro_prefix_map)
if (c_compiler_macro_prefix_map)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.")
endif()
if (cxx_compiler_macro_prefix_map)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.")
endif()

# warn on sign-conversion
#include(CheckCCompilerFlag)
#CHECK_C_COMPILER_FLAG(-Wsign-conversion c_compiler_will_warn_sign_conversion)
Expand Down
1 change: 1 addition & 0 deletions core/debian/rules
Expand Up @@ -29,6 +29,7 @@ STORAGE_DAEMON_GROUP = $(DAEMON_GROUP)
BAREOS_VERSION := $(shell dpkg-parsechangelog | egrep '^Version:' | sed 's/Version: //g')

define CONFIGURE_COMMON
-DDEBUG_PREFIX_MAP:BOOL=OFF \
-Dsbin-perm=755 \
-Dsbindir=/usr/sbin \
-Dbindir=/usr/bin \
Expand Down
17 changes: 9 additions & 8 deletions core/platforms/packaging/bareos.spec
Expand Up @@ -737,14 +737,15 @@ CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS ;

# use our own cmake call instead of cmake macro as it is different on different platforms/versions
cmake .. \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DCMAKE_INSTALL_PREFIX:PATH=/usr \
-DCMAKE_INSTALL_LIBDIR:PATH=/usr/lib \
-DINCLUDE_INSTALL_DIR:PATH=/usr/include \
-DLIB_INSTALL_DIR:PATH=/usr/lib \
-DSYSCONF_INSTALL_DIR:PATH=/etc \
-DSHARE_INSTALL_PREFIX:PATH=/usr/share \
-DBUILD_SHARED_LIBS:BOOL=ON \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DCMAKE_INSTALL_PREFIX:PATH=/usr \
-DCMAKE_INSTALL_LIBDIR:PATH=/usr/lib \
-DINCLUDE_INSTALL_DIR:PATH=/usr/include \
-DLIB_INSTALL_DIR:PATH=/usr/lib \
-DSYSCONF_INSTALL_DIR:PATH=/etc \
-DSHARE_INSTALL_PREFIX:PATH=/usr/share \
-DBUILD_SHARED_LIBS:BOOL=ON \
-DDEBUG_PREFIX_MAP:BOOL=OFF \
-Dprefix=%{_prefix}\
-Dlibdir=%{library_dir} \
-Dsbindir=%{_sbindir} \
Expand Down

0 comments on commit ad8056e

Please sign in to comment.