diff options
| author | ruki <[email protected]> | 2025-11-17 20:36:46 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-11-17 20:36:46 +0800 |
| commit | 71f48dd028d6a6ca0149784577b2c76d55af7871 (patch) | |
| tree | 2f7de64ff790cf776ab369a1ec80bd30b73d4e05 | |
| parent | 1122dba23f4d74a6be13a23ecd96fa458b9b5813 (diff) | |
| parent | 6d5be3643ae0f62095a7f5c589f09ad4c482a19b (diff) | |
Merge pull request #7032 from xmake-io/extract
improve to extract symbols
| -rw-r--r-- | xmake/rules/c++/build_optimization/config.lua | 15 | ||||
| -rw-r--r-- | xmake/rules/utils/symbols/extract/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/toolchains/clang/toolchain_clang.lua | 3 | ||||
| -rw-r--r-- | xmake/toolchains/llvm/xmake.lua | 3 |
4 files changed, 22 insertions, 1 deletions
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,<lto-filename>.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") 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") |
