From a642d2c6cbb00a82e111f32f2792594ac8092cca Mon Sep 17 00:00:00 2001 From: Frederic Riss Date: Thu, 8 Oct 2015 22:35:53 +0000 Subject: [PATCH] [dsymutil] Try to find lipo first besides dsymutil before looking up the PATH. Even if we don't have it in PATH, lipo should usually exist in the same directory as dsymutil. Keep the fallback looking up the PATH, it's very useful when testing a non-installed executable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249762 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/dsymutil/MachOUtils.cpp | 10 ++++++---- tools/dsymutil/MachOUtils.h | 3 ++- tools/dsymutil/dsymutil.cpp | 5 ++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/dsymutil/MachOUtils.cpp b/tools/dsymutil/MachOUtils.cpp index b6438789465..44cc528ed8f 100644 --- a/tools/dsymutil/MachOUtils.cpp +++ b/tools/dsymutil/MachOUtils.cpp @@ -32,8 +32,10 @@ std::string getArchName(StringRef Arch) { return Arch; } -static bool runLipo(SmallVectorImpl &Args) { - auto Path = sys::findProgramByName("lipo"); +static bool runLipo(StringRef SDKPath, SmallVectorImpl &Args) { + auto Path = sys::findProgramByName("lipo", makeArrayRef(SDKPath)); + if (!Path) + Path = sys::findProgramByName("lipo"); if (!Path) { errs() << "error: lipo: " << Path.getError().message() << "\n"; @@ -53,7 +55,7 @@ static bool runLipo(SmallVectorImpl &Args) { bool generateUniversalBinary(SmallVectorImpl &ArchFiles, StringRef OutputFileName, - const LinkOptions &Options) { + const LinkOptions &Options, StringRef SDKPath) { // No need to merge one file into a universal fat binary. First, try // to move it (rename) to the final location. If that fails because // of cross-device link issues then copy and delete. @@ -95,7 +97,7 @@ bool generateUniversalBinary(SmallVectorImpl &ArchFiles, outs() << ' ' << ((Arg == nullptr) ? "\n" : Arg); } - return Options.NoOutput ? true : runLipo(Args); + return Options.NoOutput ? true : runLipo(SDKPath, Args); } // Return a MachO::segment_command_64 that holds the same values as diff --git a/tools/dsymutil/MachOUtils.h b/tools/dsymutil/MachOUtils.h index 9a63645ab4a..61dfadc7027 100644 --- a/tools/dsymutil/MachOUtils.h +++ b/tools/dsymutil/MachOUtils.h @@ -26,7 +26,8 @@ struct ArchAndFilename { }; bool generateUniversalBinary(SmallVectorImpl &ArchFiles, - StringRef OutputFileName, const LinkOptions &); + StringRef OutputFileName, const LinkOptions &, + StringRef SDKPath); bool generateDsymCompanion(const DebugMap &DM, MCStreamer &MS, raw_fd_ostream &OutFile); diff --git a/tools/dsymutil/dsymutil.cpp b/tools/dsymutil/dsymutil.cpp index fef4cbd8e52..419d220aa4b 100644 --- a/tools/dsymutil/dsymutil.cpp +++ b/tools/dsymutil/dsymutil.cpp @@ -237,6 +237,9 @@ int main(int argc, char **argv) { llvm::PrettyStackTraceProgram StackPrinter(argc, argv); llvm::llvm_shutdown_obj Shutdown; LinkOptions Options; + void *MainAddr = reinterpret_cast(&exitDsymutil); + std::string SDKPath = llvm::sys::fs::getMainExecutable(argv[0], MainAddr); + SDKPath = llvm::sys::path::parent_path(SDKPath); HideUnrelatedOptions(DsymCategory); llvm::cl::ParseCommandLineOptions( @@ -330,7 +333,7 @@ int main(int argc, char **argv) { if (NeedsTempFiles && !MachOUtils::generateUniversalBinary( - TempFiles, getOutputFileName(InputFile), Options)) + TempFiles, getOutputFileName(InputFile), Options, SDKPath)) exitDsymutil(1); } -- 2.34.1