Skip to content

Commit 78f043d

Browse files
committed
cmake: compress DWARF debug sections with -gz in debug builds
Debug info dominates the size of these binaries (template-heavy C++; TestAccessPoint was ~97% DWARF). Enable -gz=zlib for GNU/Clang in the Debug and RelWithDebInfo configs, at both compile and link, to compress the .debug_* sections. This is transparent to gdb/lldb/readelf/addr2line and a no-op for builds without -g (e.g. Release). TestAccessPoint drops 330 MB -> 89 MB (-73%). Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
1 parent e921e5d commit 78f043d

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,25 @@ if (LINK_TIME_OPTIMIZATION AND NOT LTO_UNSUPPORTED_OS)
180180
endif()
181181
message(STATUS "LTO/IPO is ${LTO_STATUS}")
182182

183+
# Compress DWARF debug sections in builds that emit debug info. This is a
184+
# large on-disk win for template-heavy C++ (debug info dominates these
185+
# binaries) and is transparent to gdb/readelf/addr2line/lldb. It is a no-op
186+
# for builds without -g (e.g. Release), so it is safe to apply globally.
187+
# Excluded on Apple platforms: Mach-O does not support -gz=zlib and AppleClang
188+
# (which CMAKE_CXX_COMPILER_ID matches as "Clang") would fail the build.
189+
# The compile flag is scoped to C/C++: -gz is a GCC/Clang host-compiler flag
190+
# that nvcc does not accept (it would need explicit -Xcompiler forwarding), so
191+
# applying it directory-wide would break CUDA (ENABLE_GPU) debug builds where
192+
# gpl marks GPU sources as LANGUAGE CUDA. The link flag needs no such guard:
193+
# linking is driven by the host C++ compiler.
194+
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
195+
AND NOT APPLE)
196+
set(DEBUG_CONFIG_GENEX "$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>")
197+
add_compile_options(
198+
"$<$<AND:${DEBUG_CONFIG_GENEX},$<COMPILE_LANGUAGE:CXX,C>>:-gz=zlib>")
199+
add_link_options("$<${DEBUG_CONFIG_GENEX}:-gz=zlib>")
200+
endif()
201+
183202
# configure a header file to pass some of the CMake settings
184203
configure_file(
185204
${OPENROAD_HOME}/include/ord/Version.hh.cmake

0 commit comments

Comments
 (0)