[clang] Add -fuse-lipo option (PR #121231)
https://github.com/khyperia updated https://github.com/llvm/llvm-project/pull/121231 >From 33b542152876b9ccbf42cc3d070d582c32145477 Mon Sep 17 00:00:00 2001 From: khyperia Date: Fri, 27 Dec 2024 23:03:58 +0100 Subject: [PATCH 1/2] Add -fuse-lipo option --- clang/include/clang/Driver/Options.td | 1 + clang/lib/Driver/ToolChains/Darwin.cpp | 5 - 2 files changed, 5 insertions(+), 1 deletion(-) 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, Flags<[LinkOption]>, Visibility<[ClangOption, FlangOption, CLOption]>; def ld_path_EQ : Joined<["--"], "ld-path=">, Group; +def fuse_lipo_EQ : Joined<["-"], "fuse-lipo=">, Group, Flags<[LinkOption]>; defm align_labels : BooleanFFlag<"align-labels">, Group; def falign_labels_EQ : Joined<["-"], "falign-labels=">, Group; diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 4105d38d15d7d8..0d3cbb57362164 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -910,7 +910,10 @@ 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(JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, Inputs, Output)); } >From fed315be5a6b2b5d898f92872782ec5f85dd8215 Mon Sep 17 00:00:00 2001 From: khyperia Date: Sat, 28 Dec 2024 11:11:35 +0100 Subject: [PATCH 2/2] Add basic fuse-lipo.c tests --- clang/lib/Driver/ToolChains/Darwin.cpp | 5 ++--- clang/test/Driver/fuse-lipo.c | 11 +++ 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 clang/test/Driver/fuse-lipo.c diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 0d3cbb57362164..e5f28fd0a49124 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -910,10 +910,9 @@ void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(II.getFilename()); } - std::string LipoName = - std::string(Args.getLastArgValue(options::OPT_fuse_lipo_EQ, "lipo")); + StringRef LipoName = Args.getLastArgValue(options::OPT_fuse_lipo_EQ, "lipo"); const char *Exec = - Args.MakeArgString(getToolChain().GetProgramPath(LipoName.c_str())); + Args.MakeArgString(getToolChain().GetProgramPath(LipoName.data())); C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, Inputs, Output)); } diff --git a/clang/test/Driver/fuse-lipo.c b/clang/test/Driver/fuse-lipo.c new file mode 100644 index 00..2cf478482be03f --- /dev/null +++ b/clang/test/Driver/fuse-lipo.c @@ -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 +// TEST1: llvm-lipo + +// RUN: %clang %s -### --target=arm64-apple-darwin -arch x86_64 -arch arm64 -fuse-lipo=nonexistant-lipo 2>&1 | FileCheck -check-prefix=TEST2 %s +// TEST2: nonexistant-lipo + +// RUN: %clang %s -### --target=arm64-apple-darwin -fuse-lipo=llvm-lipo 2>&1 | FileCheck -check-prefix=TEST3 %s +// TEST3: clang: warning: argument unused during compilation: '-fuse-lipo=llvm-lipo' + +// RUN: %clang %s -### --target=arm64-apple-darwin -Wno-unused-command-line-argument -fuse-lipo=llvm-lipo 2>&1 | FileCheck -check-prefix=TEST4 %s +// TEST4-NOT: llvm-lipo ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
khyperia wrote: @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! https://github.com/llvm/llvm-project/pull/121231 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
khyperia wrote: > It is better to add a CLANG_DEFAULT_LIPO cmake option to match the > CLANG_DEFAULT_LINKER for -fuse-ld. Sure, that's a possibility, but in my opinion can be done in a future PR. There's a lot of additional features that can be done in the future: - CLANG_DEFAULT_LIPO cmake option - `--lipo-path` commandline argument - `-fuse-llvm-darwin-tools`, described in the original issue - better error handling when the lipo tool isn't found - probably more... I have a motivation and use case for `-fuse-lipo` and I'd like to get this in first, and we can talk about additional features later - there's no backcompat issues/etc. that require these additional features to be done within this PR. https://github.com/llvm/llvm-project/pull/121231 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
https://github.com/khyperia created https://github.com/llvm/llvm-project/pull/121231 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. >From 51401ec4a8af7d926ba3c9faa818ecb9c68c0db7 Mon Sep 17 00:00:00 2001 From: khyperia <953151+khype...@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:12:52 +0100 Subject: [PATCH] Add -fuse-lipo option --- clang/include/clang/Driver/Options.td | 1 + clang/lib/Driver/ToolChains/Darwin.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) 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, Flags<[LinkOption]>, Visibility<[ClangOption, FlangOption, CLOption]>; def ld_path_EQ : Joined<["--"], "ld-path=">, Group; +def fuse_lipo_EQ : Joined<["-"], "fuse-lipo=">, Group, Flags<[LinkOption]>; defm align_labels : BooleanFFlag<"align-labels">, Group; def falign_labels_EQ : Joined<["-"], "falign-labels=">, 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(JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, Inputs, Output)); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
https://github.com/khyperia updated https://github.com/llvm/llvm-project/pull/121231 >From 33b542152876b9ccbf42cc3d070d582c32145477 Mon Sep 17 00:00:00 2001 From: khyperia Date: Fri, 27 Dec 2024 23:03:58 +0100 Subject: [PATCH] Add -fuse-lipo option --- clang/include/clang/Driver/Options.td | 1 + clang/lib/Driver/ToolChains/Darwin.cpp | 5 - 2 files changed, 5 insertions(+), 1 deletion(-) 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, Flags<[LinkOption]>, Visibility<[ClangOption, FlangOption, CLOption]>; def ld_path_EQ : Joined<["--"], "ld-path=">, Group; +def fuse_lipo_EQ : Joined<["-"], "fuse-lipo=">, Group, Flags<[LinkOption]>; defm align_labels : BooleanFFlag<"align-labels">, Group; def falign_labels_EQ : Joined<["-"], "falign-labels=">, Group; diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 4105d38d15d7d8..0d3cbb57362164 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -910,7 +910,10 @@ 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(JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, Inputs, Output)); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
@@ -910,7 +910,10 @@ 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())); khyperia wrote: 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. https://github.com/llvm/llvm-project/pull/121231 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
khyperia wrote: (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 `GetProgramPath`) https://github.com/llvm/llvm-project/pull/121231 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
https://github.com/khyperia updated https://github.com/llvm/llvm-project/pull/121231 >From 33b542152876b9ccbf42cc3d070d582c32145477 Mon Sep 17 00:00:00 2001 From: khyperia Date: Fri, 27 Dec 2024 23:03:58 +0100 Subject: [PATCH 1/3] Add -fuse-lipo option --- clang/include/clang/Driver/Options.td | 1 + clang/lib/Driver/ToolChains/Darwin.cpp | 5 - 2 files changed, 5 insertions(+), 1 deletion(-) 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, Flags<[LinkOption]>, Visibility<[ClangOption, FlangOption, CLOption]>; def ld_path_EQ : Joined<["--"], "ld-path=">, Group; +def fuse_lipo_EQ : Joined<["-"], "fuse-lipo=">, Group, Flags<[LinkOption]>; defm align_labels : BooleanFFlag<"align-labels">, Group; def falign_labels_EQ : Joined<["-"], "falign-labels=">, Group; diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 4105d38d15d7d8..0d3cbb57362164 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -910,7 +910,10 @@ 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(JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, Inputs, Output)); } >From fed315be5a6b2b5d898f92872782ec5f85dd8215 Mon Sep 17 00:00:00 2001 From: khyperia Date: Sat, 28 Dec 2024 11:11:35 +0100 Subject: [PATCH 2/3] Add basic fuse-lipo.c tests --- clang/lib/Driver/ToolChains/Darwin.cpp | 5 ++--- clang/test/Driver/fuse-lipo.c | 11 +++ 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 clang/test/Driver/fuse-lipo.c diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 0d3cbb57362164..e5f28fd0a49124 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -910,10 +910,9 @@ void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(II.getFilename()); } - std::string LipoName = - std::string(Args.getLastArgValue(options::OPT_fuse_lipo_EQ, "lipo")); + StringRef LipoName = Args.getLastArgValue(options::OPT_fuse_lipo_EQ, "lipo"); const char *Exec = - Args.MakeArgString(getToolChain().GetProgramPath(LipoName.c_str())); + Args.MakeArgString(getToolChain().GetProgramPath(LipoName.data())); C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, Inputs, Output)); } diff --git a/clang/test/Driver/fuse-lipo.c b/clang/test/Driver/fuse-lipo.c new file mode 100644 index 00..2cf478482be03f --- /dev/null +++ b/clang/test/Driver/fuse-lipo.c @@ -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 +// TEST1: llvm-lipo + +// RUN: %clang %s -### --target=arm64-apple-darwin -arch x86_64 -arch arm64 -fuse-lipo=nonexistant-lipo 2>&1 | FileCheck -check-prefix=TEST2 %s +// TEST2: nonexistant-lipo + +// RUN: %clang %s -### --target=arm64-apple-darwin -fuse-lipo=llvm-lipo 2>&1 | FileCheck -check-prefix=TEST3 %s +// TEST3: clang: warning: argument unused during compilation: '-fuse-lipo=llvm-lipo' + +// RUN: %clang %s -### --target=arm64-apple-darwin -Wno-unused-command-line-argument -fuse-lipo=llvm-lipo 2>&1 | FileCheck -check-prefix=TEST4 %s +// TEST4-NOT: llvm-lipo >From 1329e556cc84746c86ad3be4e592c09e557320cf Mon Sep 17 00:00:00 2001 From: khyperia Date: Thu, 2 Jan 2025 20:24:07 +0100 Subject: [PATCH 3/3] Add fuse-lipo test without arg --- clang/test/Driver/fuse-lipo.c | 4 1 file changed, 4 insertions(+) diff --git a/clang/test/Driver/fuse-lipo.c b/clang/test/Driver/fuse-lipo.c index 2cf478482be03f..2dedb86ddc527a 100644 --- a/clang/test/Driver/fuse-lipo.c +++ b/clang/test/Driver/fuse-lipo.c @@ -9,3 +9,7 @@ // RUN: %clang %s -### --target=arm64-apple-darwin -Wno-unused-command-line-argument -fuse-lipo=llvm-lipo 2>&1 | FileCheck -check-prefix=TEST4 %s // TEST4-NOT: llvm-lipo + +// RUN: %clang %s -### --target=arm64-apple-darwin -arch x86_64 -arch arm64 2>&1 | FileCheck -check-prefix=TEST5 %s +// TEST5: lipo +// TEST5-NOT: llvm-lipo ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://li
[clang] Add -fuse-lipo option (PR #121231)
khyperia wrote: > 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=`. 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 `-fuse-ld` and `--ld-path`, so `-fuse-lipo` takes a name, and a hypothetical future `--lipo-path` would be a full path. Perhaps these are only named this way due to legacy compatibility though, and new naming conventions should be something else, `fuse-lipo-program` as you say? I don't know the history and context here. Let me know what I should do! > Nit: Add a test case to check when the flag is not supplied. Pushed https://github.com/llvm/llvm-project/pull/121231 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Driver] Add -fuse-lipo option (PR #121231)
khyperia wrote: Looks great, thanks! https://github.com/llvm/llvm-project/pull/121231 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
khyperia wrote: @cachemeifyoucan thank you, done! (feel free to rewrite it as well, if you want or have any nitpicks) https://github.com/llvm/llvm-project/pull/121231 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
https://github.com/khyperia edited https://github.com/llvm/llvm-project/pull/121231 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
khyperia wrote: @cachemeifyoucan Could you possibly help me get this merged? I'm not sure if your approval is enough, or if more reviewers are needed - and if so, who. Are you able to merge this if just your approval is enough? https://github.com/llvm/llvm-project/pull/121231 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits