View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015630CMakeCMakepublic2015-06-24 04:322016-06-10 14:21
ReporterNicolas Deherly 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformLinuxOSDebianOS Version8.0
Product VersionCMake 3.0.2 
Target VersionCMake 3.4Fixed in VersionCMake 3.4 
Summary0015630: ENABLE_EXPORTS value is not used for gcc makefile -rdynamic option
DescriptionWhatever is the value of ENABLE_EXPORTS, executable are linked with the -rdynamic option.

I have to reset the __linux_compiler_gnu macro to link without -rdynamic parameter.
Additional InformationThis bug has already been opened (9985).
TagsNo tags attached.
Attached Files

 Relationships
related to 0009985closedBrad King Linux.cmake should not hard-code -rdynamic 

  Notes
(0038964)
Brad King (manager)
2015-06-24 08:45

Yes. The current behavior is historical, left from before we had an explicit ENABLE_EXPORTS option, and has been preserved for compatibility.

If anyone wants to work on this, it will require a policy to change such behavior while preserving compatibility for existing projects.
(0038967)
Nicolas Deherly (reporter)
2015-06-24 08:50

If ENABLE_EXPORTS default value is ON, the historical behaviour is kept and it is possible to remove -rdynamic option by setting ENABLE_EXPORTS to OFF (as I was expecting).
(0038969)
Brad King (manager)
2015-06-24 09:07

Re 0015630:0038967: The ENABLE_EXPORTS option default is OFF. It is meant for use when the executable intends to support plugins and enables allowing MODULE libraries to reference the executable as the intended loader when they are linked. It has effects other than just an equivalent to -rdymamic.

The -rdynamic option has been used since CMake's earliest days, along with similar options on other platforms. Fixing this will require auditing the effects of all options named in CMAKE_SHARED_LIBRARY_LINK_<LANG>_FLAGS settings in Modules/Platform/*.cmake to see which ones need to be converted to be based on ENABLE_EXPORTS.
(0040680)
Bernd Lörwald (reporter)
2016-03-14 12:08

As noted in (closed) issue 9985, this can be worked around with unsetting CMAKE_SHARED_LIBRARY_LINK_<LANG>_FLAGS.

This does not allow to only override this for specific targets only though, as the value is not used at declaration of the target but afterwards:

$ touch foo.cpp

$ cat > CMakeLists.txt
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
add_executable (foo "foo.cpp")

$ cmake . -G "Unix Makefiles" >/dev/null 2>&1 && cat CMakeFiles/foo.dir/link.txt
/soft/clang/3.7.1/bin/clang++ -O3 -DNDEBUG CMakeFiles/foo.dir/foo.cpp.o -o foo

$ cat > CMakeLists.txt
set (safe ${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS})
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
add_executable (foo "foo.cpp")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS ${safe})

$ cmake . -G "Unix Makefiles" >/dev/null 2>&1 && cat CMakeFiles/foo.dir/link.txt
/soft/clang/3.7.1/bin/clang++ -O3 -DNDEBUG CMakeFiles/foo.dir/foo.cpp.o -o foo -rdynamic

Overwriting the LINK_FLAGS property does nothing there either, as that's additional only:

$ cat > CMakeLists.txt
set (safe ${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS})
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
add_executable (foo "foo.cpp")
set_property (TARGET foo PROPERTY LINK_FLAGS "-static")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS ${safe})

$ cmake . -G "Unix Makefiles" >/dev/null 2>&1 && cat CMakeFiles/foo.dir/link.txt
/soft/clang/3.7.1/bin/clang++ -O3 -DNDEBUG -static CMakeFiles/foo.dir/foo.o -o foo -rdynamic


As we too do not want to audit the effects of -rdynamic on all of our targets, this is quite a bummer. The only thing that worked would be adding -Wl,--no-export-dynamic (which is the inverse of -rdynamic) to LINK_FLAGS, but that was added to ld in 2009 only, so distros like centos5 do not have that flag.

Am I missing something here or does this really mean that having a single target without -rdynamic is not possible, unless doing it the other way around and specifying -rdynamic for all but one target?
(0040681)
Brad King (manager)
2016-03-14 13:04

The audit mentioned in 0015630:0038969 has been done.

Since CMake 3.4 one can set policy CMP0065:

  https://cmake.org/cmake/help/v3.5/policy/CMP0065.html [^]

to disable use of -rdynamic outright, except for executables where it is explicitly requested via the ENABLE_EXPORTS property.

Using

  cmake_minimum_required(VERSION 3.4)

at the top of a project is sufficient to set CMP0065 to NEW. Otherwise an explicit

  if(POLICY CMP0065)
    cmake_policy(SET CMP0065 NEW)
  endif()

will do it.
(0041228)
Kitware Robot (administrator)
2016-06-10 14:21

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.

 Issue History
Date Modified Username Field Change
2015-06-24 04:32 Nicolas Deherly New Issue
2015-06-24 08:42 Brad King Relationship added related to 0009985
2015-06-24 08:45 Brad King Note Added: 0038964
2015-06-24 08:50 Nicolas Deherly Note Added: 0038967
2015-06-24 09:07 Brad King Note Added: 0038969
2016-03-14 12:08 Bernd Lörwald Note Added: 0040680
2016-03-14 13:04 Brad King Note Added: 0040681
2016-03-14 13:04 Brad King Status new => resolved
2016-03-14 13:04 Brad King Resolution open => fixed
2016-03-14 13:04 Brad King Fixed in Version => CMake 3.4
2016-03-14 13:04 Brad King Target Version => CMake 3.4
2016-06-10 14:21 Kitware Robot Note Added: 0041228
2016-06-10 14:21 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team