Improve: ship release builds without debug info and symbols
linux/CMakeLists.txt forced -g into the global flags regardless of build type, so even a Release build carried full DWARF: 7.7MB of the 10.3MB binary was .debug_* material the client never uses at runtime. Drop the forced -g and default CMAKE_BUILD_TYPE to Release, stripping the symbol table at link time (-s) so only Debug builds keep symbols. Do the same for macOS with ld64's -Wl,-x on Release, which drops the 8.3k local symbols while keeping external ones and the signature ld appends. linux/ghost drops from 10.3MB to 2.5MB (UPX on top: 0.87MB). Rebuilt under WSL and verified with readelf: no .debug_*/.symtab/.strtab, BuildID kept. The macOS change is not verified here; it needs a build on the Mac. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
326e162d16
commit
913b74097b
3 files changed
+22
-3
No files matched your search
@@ -35,9 +35,15 @@ set(SOURCES
|
||||
add_executable(ghost ${SOURCES})
|
||||
|
||||
|
||||
# 设置为可以调试
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
|
||||
# 默认使用 Release:无调试信息、-O3,链接时剥离符号表(ghost 约 2.5MB);
|
||||
# 需要 gdb 调试时用:cmake -DCMAKE_BUILD_TYPE=Debug . && make
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
|
||||
endif()
|
||||
|
||||
# 注意:这里不要再往 CMAKE_CXX_FLAGS 里塞 -g,否则 Release 也会带上 DWARF
|
||||
# (ghost 会涨到 10MB 以上,其中 75% 是 .debug_* 段)。
|
||||
target_link_options(ghost PRIVATE $<$<CONFIG:Release>:-s>)
|
||||
|
||||
# 链接 ZSTD 库
|
||||
message(STATUS "链接库文件: ${CMAKE_SOURCE_DIR}/lib/libzstd.a")
|
||||
|
||||
Reference in new issue
Block a user