Skip to content

[clang][Driver] Add -fuse-lipo option #121231

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

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
5 changes: 4 additions & 1 deletion clang/lib/Driver/ToolChains/Darwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Copy link
Member

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:

Suggested change
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()));

Copy link
Contributor Author

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.

C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
Exec, CmdArgs, Inputs, Output));
}
Expand Down
Loading