Use hidden visibility with GCC and Clang
authorEmil Velikov <emil.velikov@collabora.com>
Wed, 30 Aug 2017 14:12:14 +0000 (15:12 +0100)
committerMika Isojärvi <misojarvi@google.com>
Mon, 25 Sep 2017 19:58:32 +0000 (12:58 -0700)
The final result of the build are standalone executables, with all the
code statically linked.

Change the visibility to hidden, to avoid the symbol leakage and allow
the compiler to discard some code.

As a result the binary size is drastically decreased.

Total executable size on my setup drops by ~20%
 158M    before
 128M    after

Note: The binaries still export multiple unneeded symbols. Resolving
those is left as an exercise for later.

Test: full rebuild, running resulting binaries.

Change-Id: Ife10bbd123d59f4480349794785f13978516df30
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
framework/delibs/cmake/CFlags.cmake

index 8a4b9ad..bcb11ab 100644 (file)
@@ -53,6 +53,11 @@ if (DE_COMPILER_IS_GCC OR DE_COMPILER_IS_CLANG)
        # Turn on -Wstrict-overflow=5 and check all warnings before removing
        set(CMAKE_C_FLAGS                       "${CMAKE_C_FLAGS} -fwrapv")
        set(CMAKE_CXX_FLAGS                     "${CMAKE_CXX_FLAGS} -fwrapv")
+
+       # Force compiler to not export any symbols.
+       # Any static libraries build are linked into the standalone executable binaries.
+       set(CMAKE_C_FLAGS                       "${CMAKE_C_FLAGS} -fvisibility=hidden")
+       set(CMAKE_CXX_FLAGS                     "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
 elseif (DE_COMPILER_IS_MSC)
        # Compiler flags for msc