From 9b91cb225b0036464770a52ed48661dae9922d2a Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 17 Nov 2025 23:56:44 +0800 Subject: improve to extract symbols --- xmake/rules/utils/symbols/extract/xmake.lua | 2 +- xmake/toolchains/clang/toolchain_clang.lua | 3 +++ xmake/toolchains/llvm/xmake.lua | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/xmake/rules/utils/symbols/extract/xmake.lua b/xmake/rules/utils/symbols/extract/xmake.lua index b9fd816eb..92abd3df3 100644 --- a/xmake/rules/utils/symbols/extract/xmake.lua +++ b/xmake/rules/utils/symbols/extract/xmake.lua @@ -103,7 +103,7 @@ rule("utils.symbols.extract") -- strip it local strip_argv = {} - if target:is_plat("macosx", "iphoneos", "watchos") then + if target:is_plat("macosx", "iphoneos", "watchos") and not strip:find("llvm-strip", 1, true) then -- do not support `-s`, we can only strip debug symbols local arch = target:arch() if arch then diff --git a/xmake/toolchains/clang/toolchain_clang.lua b/xmake/toolchains/clang/toolchain_clang.lua index c22bd3d75..b1e59356f 100644 --- a/xmake/toolchains/clang/toolchain_clang.lua +++ b/xmake/toolchains/clang/toolchain_clang.lua @@ -42,6 +42,9 @@ function toolchain_clang(version) set_toolset("as", "clang" .. suffix) set_toolset("mrc", "llvm-rc" .. suffix) set_toolset("dlltool", "llvm-dlltool" .. suffix) + if is_host("macosx") then + set_toolset("dsymutil", "dsymutil") + end on_check(function (toolchain) if toolchain:is_plat("windows") then diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua index b1cf68d5c..d4557071c 100644 --- a/xmake/toolchains/llvm/xmake.lua +++ b/xmake/toolchains/llvm/xmake.lua @@ -38,6 +38,9 @@ toolchain("llvm") set_toolset("objcopy", "llvm-objcopy") set_toolset("mrc", "llvm-rc") set_toolset("dlltool", "llvm-dlltool") + if is_host("macosx") then + set_toolset("dsymutil", "dsymutil") + end set_toolset("sc", "$(env SC)", "swift-frontend", "swiftc") set_toolset("scsh", "$(env SC)", "swiftc") -- cgit v1.3.1 From 6d5be3643ae0f62095a7f5c589f09ad4c482a19b Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 18 Nov 2025 00:07:30 +0800 Subject: add lto symbols support --- xmake/rules/c++/build_optimization/config.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/xmake/rules/c++/build_optimization/config.lua b/xmake/rules/c++/build_optimization/config.lua index 0f79a909b..686ef76c5 100644 --- a/xmake/rules/c++/build_optimization/config.lua +++ b/xmake/rules/c++/build_optimization/config.lua @@ -44,6 +44,21 @@ function _add_lto_optimization(target, sourcekind) elseif ld == "clang" or ld == "clangxx" then target:add("ldflags", "-flto=thin") target:add("shflags", "-flto=thin") + + -- On Darwin, when using -flto along with -g and compiling and linking in separate steps, + -- you also need to pass -Wl,-object_path_lto,.o at the linking step to instruct + -- the ld64 linker not to delete the temporary object file generated during Link Time Optimization + -- (this flag is automatically passed to the linker by Clang if compilation and linking are done in a single step). + -- + -- This allows debugging the executable as well as generating the .dSYM bundle using dsymutil(1). + -- + -- @see https://github.com/xmake-io/xmake/issues/7029 + -- https://clang.llvm.org/docs/CommandGuide/clang.html + if target:is_plat("macosx", "iphoneos", "watchos") then + local lto_objectfile = target:objectfile(target:targetfile() .. ".lto") + target:add("ldflags", "-Wl,-object_path_lto," .. lto_objectfile) + target:add("shflags", "-Wl,-object_path_lto," .. lto_objectfile) + end elseif ld == "gcc" or ld == "gxx" then target:add("ldflags", "-flto") target:add("shflags", "-flto") -- cgit v1.3.1