-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add -fuse-lipo option #121231
base: main
Are you sure you want to change the base?
Add -fuse-lipo option #121231
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang-driver Author: Ashley Hauck (khyperia) ChangesThis is my first LLVM PR! Please feel free to provide feedback/etc. - I am especially unsure about the Partially fixes #59552 - opting for 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 Additionally, the binaries included in the release file Full diff: https://github.com/llvm/llvm-project/pull/121231.diff 2 Files Affected:
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));
}
|
@llvm/pr-subscribers-clang Author: Ashley Hauck (khyperia) ChangesThis is my first LLVM PR! Please feel free to provide feedback/etc. - I am especially unsure about the Partially fixes #59552 - opting for 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 Additionally, the binaries included in the release file Full diff: https://github.com/llvm/llvm-project/pull/121231.diff 2 Files Affected:
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));
}
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! This change needs new tests to be added.
std::string LipoName = | ||
std::string(Args.getLastArgValue(options::OPT_fuse_lipo_EQ, "lipo")); | ||
const char *Exec = | ||
Args.MakeArgString(getToolChain().GetProgramPath(LipoName.c_str())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a bit much to create a throwaway std::string
here. Something like this should work:
std::string LipoName = | |
std::string(Args.getLastArgValue(options::OPT_fuse_lipo_EQ, "lipo")); | |
const char *Exec = | |
Args.MakeArgString(getToolChain().GetProgramPath(LipoName.c_str())); | |
StringRef LipoName = | |
Args.getLastArgValue(options::OPT_fuse_lipo_EQ, "lipo"); | |
const char *Exec = | |
Args.MakeArgString(getToolChain().GetProgramPath(LipoName.data())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, StringRef::data() is documented as "data - Get a pointer to the start of the string (which may not be null terminated)". Because we're using it as a null-terminated string, I thought that making a copy is necessary to ensure it's null terminated, in case getLastArgValue ever changes to not return a null-terminated string. Depending on it always returning a null terminated string seems like what a lot of other code does already, though, I'll make that change.
@carlocab I've removed the temporary std::string and added a guess at basic tests. Let me know if there's additional tests in particular that you're thinking of! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM in general with a comment in test.
For discussion. Is it better if the option supplies the full path to lipo or just the name? Full path seems to be easy to use, but might deserve a warning if the tool doesn't exist.
If just the name, it might be better to rename the option to something like -fuse-lipo-program=
.
@@ -0,0 +1,11 @@ | |||
// RUN: %clang %s -### --target=arm64-apple-darwin -arch x86_64 -arch arm64 -fuse-lipo=llvm-lipo 2>&1 | FileCheck -check-prefix=TEST1 %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Add a test case to check when the flag is not supplied.
As a prefix: I am a new contributor, if you or someone else experienced has an opinion here I will gladly blindly follow it. I tried to take precedence from
Pushed |
(For what it's worth, just confirming that the current code doesn't work with a full path - it surprisingly kind of almost does, but not quite, due to quirks of |
Make sense to me. |
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 #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 includesllvm-lipo.exe
, nolipo.exe
alias/link, so clang fails to findlipo
when making a universal dylib. The release fileLLVM-19.1.6-win64.exe
does not includellvm-lipo.exe
at all. I'm going to look into including that next.