[clang] Add -fuse-lipo option (PR #121231)

via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 27 13:27:50 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Ashley Hauck (khyperia)

<details>
<summary>Changes</summary>

This is my first LLVM PR! Please feel free to provide feedback/etc. - I am especially unsure about the `Options.td` change - I just kind of guessed here.

Partially fixes https://github.com/llvm/llvm-project/issues/59552 - opting for `-fuse-lipo=llvm-lipo` rather than `-fuse-llvm-darwin-tools` since it solves my use case, and I figure that if `-fuse-llvm-darwin-tools` is eventually added, it'll still be nice to have the fine-grained control with `-fuse-lipo`.

---

My use case is that I'm cross compiling from Windows to Mac (creating an arm/x86 dylib), so I don't have the native `lipo`.

Additionally, the binaries included in the release file `LLVM-19.1.0-Windows-X64.tar.xz` only includes `llvm-lipo.exe`, no `lipo.exe` alias/link, so clang fails to find `lipo` when making a universal dylib. The release file `LLVM-19.1.6-win64.exe` does not include `llvm-lipo.exe` at all. I'm going to look into including that next.

---
Full diff: https://github.com/llvm/llvm-project/pull/121231.diff


2 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+1) 
- (modified) clang/lib/Driver/ToolChains/Darwin.cpp (+2-1) 


``````````diff
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index d922709db17786..6cd23de87bacde 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6654,6 +6654,7 @@ def fbinutils_version_EQ : Joined<["-"], "fbinutils-version=">,
 def fuse_ld_EQ : Joined<["-"], "fuse-ld=">, Group<f_Group>,
   Flags<[LinkOption]>, Visibility<[ClangOption, FlangOption, CLOption]>;
 def ld_path_EQ : Joined<["--"], "ld-path=">, Group<Link_Group>;
+def fuse_lipo_EQ : Joined<["-"], "fuse-lipo=">, Group<f_clang_Group>, Flags<[LinkOption]>;
 
 defm align_labels : BooleanFFlag<"align-labels">, Group<clang_ignored_gcc_optimization_f_Group>;
 def falign_labels_EQ : Joined<["-"], "falign-labels=">, Group<clang_ignored_gcc_optimization_f_Group>;
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index 4105d38d15d7d8..c23f6830b8c764 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -910,7 +910,8 @@ void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back(II.getFilename());
   }
 
-  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("lipo"));
+  std::string LipoName = std::string(Args.getLastArgValue(options::OPT_fuse_lipo_EQ, "lipo"));
+  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(LipoName.c_str()));
   C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
                                          Exec, CmdArgs, Inputs, Output));
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/121231


More information about the cfe-commits mailing list