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:
yuanyuanxianganddeepseek-flash committed 2026-11-20 17:40:00 +01:00
1 parent 326e162d16
commit 913b74097b
3 files changed
+22 -3

No files matched your search

+5
View File
@@ -124,6 +124,11 @@ target_compile_options(ghost PRIVATE
-fobjc-arc
)
# Release 链接时删掉 local 符号(对应 Linux 那边的 -s;ld64 用 -x)。
# 只删 non-global 符号,external 符号保留,dyld 绑定不受影响;签名由 ld 在链接
# 末尾完成,所以改符号表不会让签名失效。ghost 目前 ~19k 个符号里 8.3k 是 local。
target_link_options(ghost PRIVATE $<$<CONFIG:Release>:-Wl,-x>)
# Output directory
set_target_properties(ghost PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin