1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00
llvm-mirror/tools/dsymutil/MachOUtils.cpp
Frederic Riss f7cdc109f3 [dsymutil] Reapply r245960.
There was an issue in the test setup because the test requires an arch that
wasn't filtered by the lit.local.cfg, but given the set of bots that failed,
I'm not confident this is the (only) issue. So this commit also adds more
output to the test to help me track down the failure if it happens again.

Original commit message:
[dsymutil] Rewrite thumb triple names in user visible messages.

We autodetect triples from the input file(s) while reading the mach-o debug map.
As we need to create a Target from those triples, we always chose the thumb
variant (because the arm variant might not be 'instantiable' eg armv7m). The
user visible architecture names should still be 'arm' and not 'thumb' variants
though.

llvm-svn: 245988
2015-08-25 23:15:26 +00:00

94 lines
2.6 KiB
C++

//===-- MachOUtils.h - Mach-o specific helpers for dsymutil --------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "MachOUtils.h"
#include "dsymutil.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
namespace dsymutil {
namespace MachOUtils {
std::string getArchName(StringRef Arch) {
if (Arch.startswith("thumb"))
return (llvm::Twine("arm") + Arch.drop_front(5)).str();
return Arch;
}
static bool runLipo(SmallVectorImpl<const char *> &Args) {
auto Path = sys::findProgramByName("lipo");
if (!Path) {
errs() << "error: lipo: " << Path.getError().message() << "\n";
return false;
}
std::string ErrMsg;
int result =
sys::ExecuteAndWait(*Path, Args.data(), nullptr, nullptr, 0, 0, &ErrMsg);
if (result) {
errs() << "error: lipo: " << ErrMsg << "\n";
return false;
}
return true;
}
bool generateUniversalBinary(SmallVectorImpl<ArchAndFilename> &ArchFiles,
StringRef OutputFileName,
const LinkOptions &Options) {
// 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.
if (ArchFiles.size() == 1) {
StringRef From(ArchFiles.front().Path);
if (sys::fs::rename(From, OutputFileName)) {
if (std::error_code EC = sys::fs::copy_file(From, OutputFileName)) {
errs() << "error: while copying " << From << " to " << OutputFileName
<< ": " << EC.message() << "\n";
return false;
}
sys::fs::remove(From);
}
return true;
}
SmallVector<const char *, 8> Args;
Args.push_back("lipo");
Args.push_back("-create");
for (auto &Thin : ArchFiles)
Args.push_back(Thin.Path.c_str());
// Align segments to match dsymutil-classic alignment
for (auto &Thin : ArchFiles) {
Thin.Arch = getArchName(Thin.Arch);
Args.push_back("-segalign");
Args.push_back(Thin.Arch.c_str());
Args.push_back("20");
}
Args.push_back("-output");
Args.push_back(OutputFileName.data());
Args.push_back(nullptr);
if (Options.Verbose) {
outs() << "Running lipo\n";
for (auto Arg : Args)
outs() << ' ' << ((Arg == nullptr) ? "\n" : Arg);
}
return Options.NoOutput ? true : runLipo(Args);
}
}
}
}