Discussion:
[CMake] Suppressing -rdynamic
Gonzalo Garramuño
2007-10-06 06:25:23 UTC
Permalink
I'm compiling under Linux and it seems like cmake is automatically
adding -rdynamic to my build.
This switch is okay for debug builds and open source tools, but for
closed source it is a big problem.
This switch is unfortunately exposing some unwanted functions in my
code, like the licensing functions.
This makes the functions easily available by using objdump -T or nm -D,
even if the executable has been stripped.

Is there a way to suppress the use of this switch?
--
Gonzalo Garramuño
***@advancedsl.com.ar

AMD4400 - ASUS48N-E
GeForce7300GT
Kubuntu Edgy
Filip Brcic
2007-10-06 12:16:16 UTC
Permalink
Post by Gonzalo Garramuño
I'm compiling under Linux and it seems like cmake is automatically
adding -rdynamic to my build.
This switch is okay for debug builds and open source tools, but for
closed source it is a big problem.
This switch is unfortunately exposing some unwanted functions in my
code, like the licensing functions.
This makes the functions easily available by using objdump -T or nm -D,
even if the executable has been stripped.
Is there a way to suppress the use of this switch?
Hi,

If you do a:

[***@sirius ~]$ cd /usr/share/cmake/Modules
[***@sirius Modules]$ grep 'rdynamic' *
[***@sirius Modules]$ grep 'rdynamic' */*
Platform/kFreeBSD.cmake:SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-rdynamic")
Platform/Linux.cmake:SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-rdynamic")

Therefore, you have to override CMAKE_SHARED_LIBRARY_LINK_C_FLAGS and set it
to blank. Something like:

SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")

or something like that.

And do consider making your program free software ;)

Best regards
Filip

- --
Filip Brcic <***@users.sourceforge.net>
WWWeb: http://purl.org/NET/brcha/home/
Jabber: ***@kdetalk.net
ICQ# 40994923
Yahoo! brcha
MSN: ***@users.sourceforge.net
Gonzalo Garramuño
2007-10-06 14:33:50 UTC
Permalink
Post by Filip Brcic
Therefore, you have to override CMAKE_SHARED_LIBRARY_LINK_C_FLAGS and set it
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
or something like that.
Did you actually try it? Suppressing the variable does nothing.
Even replacing Linux.cmake with my own does nothing.
--
Gonzalo Garramuño
***@advancedsl.com.ar

AMD4400 - ASUS48N-E
GeForce7300GT
Kubuntu Edgy
Filip Brcic
2007-10-06 14:57:06 UTC
Permalink
Post by Gonzalo Garramuño
Post by Filip Brcic
Therefore, you have to override CMAKE_SHARED_LIBRARY_LINK_C_FLAGS and set
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
or something like that.
Did you actually try it? Suppressing the variable does nothing.
Even replacing Linux.cmake with my own does nothing.
It works for me. Take a look at the attacked "program".

Here is my version of CMake:
[***@sirius ~]$ rpm -q cmake
cmake-2.4.6-4.fc7

and here is the output of the verbose build:
[***@sirius build]$ make VERBOSE=1
/usr/bin/cmake -H/Users/brcha/tmp/helloWorld -B/Users/brcha/tmp/helloWorld/build --check-build-system
CMakeFiles/Makefile.cmake 0
Clearing dependencies in "CMakeFiles/helloWorld.dir/depend.make".
Clearing dependencies in "CMakeFiles/helloWorld.dir/depend.internal".
/usr/bin/cmake -E
cmake_progress_start /Users/brcha/tmp/helloWorld/build/CMakeFiles 1
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/Users/brcha/tmp/helloWorld/build'
make -f CMakeFiles/helloWorld.dir/build.make CMakeFiles/helloWorld.dir/depend
make[2]: Entering directory `/Users/brcha/tmp/helloWorld/build'
Scanning dependencies of target helloWorld
cd /Users/brcha/tmp/helloWorld/build && /usr/bin/cmake -E cmake_depends "Unix
Makefiles" /Users/brcha/tmp/helloWorld /Users/brcha/tmp/helloWorld /Users/brcha/tmp/helloWorld/build /Users/brcha/tmp/helloWorld/build /Users/brcha/tmp/helloWorld/build/CMakeFiles/helloWorld.dir/DependInfo.cmake
make[2]: Leaving directory `/Users/brcha/tmp/helloWorld/build'
make -f CMakeFiles/helloWorld.dir/build.make CMakeFiles/helloWorld.dir/build
make[2]: Entering directory `/Users/brcha/tmp/helloWorld/build'
/usr/bin/cmake -E
cmake_progress_report /Users/brcha/tmp/helloWorld/build/CMakeFiles 1
[100%] Building C object CMakeFiles/helloWorld.dir/helloWorld.o
/usr/lib64/ccache/gcc -o
CMakeFiles/helloWorld.dir/helloWorld.o -c /Users/brcha/tmp/helloWorld/helloWorld.c
Linking C executable helloWorld
/usr/bin/cmake -P CMakeFiles/helloWorld.dir/cmake_clean_target.cmake
/usr/lib64/ccache/gcc -fPIC "CMakeFiles/helloWorld.dir/helloWorld.o" -o
helloWorld
make[2]: Leaving directory `/Users/brcha/tmp/helloWorld/build'
/usr/bin/cmake -E
cmake_progress_report /Users/brcha/tmp/helloWorld/build/CMakeFiles 1
[100%] Built target helloWorld
make[1]: Leaving directory `/Users/brcha/tmp/helloWorld/build'
/usr/bin/cmake -E
cmake_progress_start /Users/brcha/tmp/helloWorld/build/CMakeFiles 0


- --
Filip Brcic <***@users.sourceforge.net>
WWWeb: http://purl.org/NET/brcha/home/
Jabber: ***@kdetalk.net
ICQ# 40994923
Yahoo! brcha
MSN: ***@users.sourceforge.net
Gonzalo Garramuño
2007-10-06 15:20:11 UTC
Permalink
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Post by Filip Brcic
Therefore, you have to override CMAKE_SHARED_LIBRARY_LINK_C_FLAGS and set
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS seems to be the key for c++. Have
not been able to guess where that is set thou.
--
Gonzalo Garramuño
***@advancedsl.com.ar

AMD4400 - ASUS48N-E
GeForce7300GT
Kubuntu Edgy
Filip Brcic
2007-10-06 15:52:16 UTC
Permalink
Post by Gonzalo Garramuño
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Post by Filip Brcic
Therefore, you have to override CMAKE_SHARED_LIBRARY_LINK_C_FLAGS and
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS seems to be the key for c++. Have
not been able to guess where that is set thou.
Yes, you are right. I made a new "advanced" version of my helloWorld++ (tm)
program using C++ (and cout for output) and it did include -rdynamic when
linking. But, after I added set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") the
problem dissapeared. Nice catch :)

And, here is where that is comming from:

[***@sirius Modules]$ grep CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS *
CMakeCXXInformation.cmake:IF(NOT CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
CMakeCXXInformation.cmake: SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS
${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
CMakeCXXInformation.cmake:ENDIF(NOT CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)

Since that is evaluated in enable_language(CXX) (I guess), it uses the system
CMAKE_SHARED_LIBRARY_LINK_C_FLAGS variable and not the CMakeFiles.txt
version. For Fortran you should override
CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS in the same way.

- --
Filip Brcic <***@users.sourceforge.net>
WWWeb: http://purl.org/NET/brcha/home/
Jabber: ***@kdetalk.net
ICQ# 40994923
Yahoo! brcha
MSN: ***@users.sourceforge.net

Loading...