aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm/tools/llvm-rtdyld
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-08-16 21:02:59 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-08-16 21:02:59 +0000
commit3ca95b020283db6244cab92ede73c969253b6a31 (patch)
treed16e791e58694facd8f68d3e2797a1eaa8018afc /contrib/llvm/tools/llvm-rtdyld
parent27067774dce3388702a4cf744d7096c6fb71b688 (diff)
parentc3aee98e721333f265a88d6bf348e6e468f027d4 (diff)
downloadsrc-3ca95b020283db6244cab92ede73c969253b6a31.tar.gz
src-3ca95b020283db6244cab92ede73c969253b6a31.zip
Update llvm to release_39 branch r276489, and resolve conflicts.
Notes
Notes: svn path=/projects/clang390-import/; revision=304240
Diffstat (limited to 'contrib/llvm/tools/llvm-rtdyld')
-rw-r--r--contrib/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp108
1 files changed, 71 insertions, 37 deletions
diff --git a/contrib/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp b/contrib/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
index 6ee3a44b63bf..b1460e35de80 100644
--- a/contrib/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
+++ b/contrib/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
@@ -19,7 +19,7 @@
#include "llvm/ExecutionEngine/RuntimeDyldChecker.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
-#include "llvm/MC/MCDisassembler.h"
+#include "llvm/MC/MCDisassembler/MCDisassembler.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCRegisterInfo.h"
@@ -191,7 +191,7 @@ public:
}
uint8_t *allocateFromSlab(uintptr_t Size, unsigned Alignment, bool isCode) {
- Size = RoundUpToAlignment(Size, Alignment);
+ Size = alignTo(Size, Alignment);
if (CurrentSlabOffset + Size > SlabSize)
report_fatal_error("Can't allocate enough memory. Tune --preallocate");
@@ -254,9 +254,9 @@ uint8_t *TrivialMemoryManager::allocateDataSection(uintptr_t Size,
static const char *ProgramName;
-static int Error(const Twine &Msg) {
+static void ErrorAndExit(const Twine &Msg) {
errs() << ProgramName << ": error: " << Msg << "\n";
- return 1;
+ exit(1);
}
static void loadDylibs() {
@@ -290,13 +290,18 @@ static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) {
ErrorOr<std::unique_ptr<MemoryBuffer>> InputBuffer =
MemoryBuffer::getFileOrSTDIN(File);
if (std::error_code EC = InputBuffer.getError())
- return Error("unable to read input: '" + EC.message() + "'");
+ ErrorAndExit("unable to read input: '" + EC.message() + "'");
- ErrorOr<std::unique_ptr<ObjectFile>> MaybeObj(
+ Expected<std::unique_ptr<ObjectFile>> MaybeObj(
ObjectFile::createObjectFile((*InputBuffer)->getMemBufferRef()));
- if (std::error_code EC = MaybeObj.getError())
- return Error("unable to create object file: '" + EC.message() + "'");
+ if (!MaybeObj) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ logAllUnhandledErrors(MaybeObj.takeError(), OS, "");
+ OS.flush();
+ ErrorAndExit("unable to create object file: '" + Buf + "'");
+ }
ObjectFile &Obj = **MaybeObj;
@@ -309,7 +314,7 @@ static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) {
Dyld.loadObject(Obj);
if (Dyld.hasError())
- return Error(Dyld.getErrorString());
+ ErrorAndExit(Dyld.getErrorString());
// Resolve all the relocations we can.
Dyld.resolveRelocations();
@@ -330,13 +335,26 @@ static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) {
// Use symbol info to iterate functions in the object.
for (const auto &P : SymAddr) {
object::SymbolRef Sym = P.first;
- if (Sym.getType() == object::SymbolRef::ST_Function) {
- ErrorOr<StringRef> Name = Sym.getName();
- if (!Name)
+ Expected<SymbolRef::Type> TypeOrErr = Sym.getType();
+ if (!TypeOrErr) {
+ // TODO: Actually report errors helpfully.
+ consumeError(TypeOrErr.takeError());
+ continue;
+ }
+ SymbolRef::Type Type = *TypeOrErr;
+ if (Type == object::SymbolRef::ST_Function) {
+ Expected<StringRef> Name = Sym.getName();
+ if (!Name) {
+ // TODO: Actually report errors helpfully.
+ consumeError(Name.takeError());
continue;
- ErrorOr<uint64_t> AddrOrErr = Sym.getAddress();
- if (!AddrOrErr)
+ }
+ Expected<uint64_t> AddrOrErr = Sym.getAddress();
+ if (!AddrOrErr) {
+ // TODO: Actually report errors helpfully.
+ consumeError(AddrOrErr.takeError());
continue;
+ }
uint64_t Addr = *AddrOrErr;
uint64_t Size = P.second;
@@ -344,7 +362,13 @@ static int printLineInfoForInput(bool LoadObjects, bool UseDebugObj) {
// symbol in memory (rather than that in the unrelocated object file)
// and use that to query the DWARFContext.
if (!UseDebugObj && LoadObjects) {
- object::section_iterator Sec = *Sym.getSection();
+ auto SecOrErr = Sym.getSection();
+ if (!SecOrErr) {
+ // TODO: Actually report errors helpfully.
+ consumeError(SecOrErr.takeError());
+ continue;
+ }
+ object::section_iterator Sec = *SecOrErr;
StringRef SecName;
Sec->getName(SecName);
uint64_t SectionLoadAddress =
@@ -396,19 +420,24 @@ static int executeInput() {
ErrorOr<std::unique_ptr<MemoryBuffer>> InputBuffer =
MemoryBuffer::getFileOrSTDIN(File);
if (std::error_code EC = InputBuffer.getError())
- return Error("unable to read input: '" + EC.message() + "'");
- ErrorOr<std::unique_ptr<ObjectFile>> MaybeObj(
+ ErrorAndExit("unable to read input: '" + EC.message() + "'");
+ Expected<std::unique_ptr<ObjectFile>> MaybeObj(
ObjectFile::createObjectFile((*InputBuffer)->getMemBufferRef()));
- if (std::error_code EC = MaybeObj.getError())
- return Error("unable to create object file: '" + EC.message() + "'");
+ if (!MaybeObj) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ logAllUnhandledErrors(MaybeObj.takeError(), OS, "");
+ OS.flush();
+ ErrorAndExit("unable to create object file: '" + Buf + "'");
+ }
ObjectFile &Obj = **MaybeObj;
// Load the object file
Dyld.loadObject(Obj);
if (Dyld.hasError()) {
- return Error(Dyld.getErrorString());
+ ErrorAndExit(Dyld.getErrorString());
}
}
@@ -419,7 +448,7 @@ static int executeInput() {
// Get the address of the entry point (_main by default).
void *MainAddress = Dyld.getSymbolLocalAddress(EntryPoint);
if (!MainAddress)
- return Error("no definition for '" + EntryPoint + "'");
+ ErrorAndExit("no definition for '" + EntryPoint + "'");
// Invalidate the instruction cache for each loaded function.
for (auto &FM : MemMgr.FunctionMemory) {
@@ -428,7 +457,7 @@ static int executeInput() {
// setExecutable will call InvalidateInstructionCache.
std::string ErrorStr;
if (!sys::Memory::setExecutable(FM, &ErrorStr))
- return Error("unable to mark function executable: '" + ErrorStr + "'");
+ ErrorAndExit("unable to mark function executable: '" + ErrorStr + "'");
}
// Dispatch to _main().
@@ -448,12 +477,12 @@ static int checkAllExpressions(RuntimeDyldChecker &Checker) {
ErrorOr<std::unique_ptr<MemoryBuffer>> CheckerFileBuf =
MemoryBuffer::getFileOrSTDIN(CheckerFileName);
if (std::error_code EC = CheckerFileBuf.getError())
- return Error("unable to read input '" + CheckerFileName + "': " +
+ ErrorAndExit("unable to read input '" + CheckerFileName + "': " +
EC.message());
if (!Checker.checkAllRulesInBuffer("# rtdyld-check:",
CheckerFileBuf.get().get()))
- return Error("some checks in '" + CheckerFileName + "' failed");
+ ErrorAndExit("some checks in '" + CheckerFileName + "' failed");
}
return 0;
}
@@ -602,7 +631,7 @@ static int linkAndVerify() {
// Check for missing triple.
if (TripleName == "")
- return Error("-triple required when running in -verify mode.");
+ ErrorAndExit("-triple required when running in -verify mode.");
// Look up the target and build the disassembler.
Triple TheTriple(Triple::normalize(TripleName));
@@ -610,29 +639,29 @@ static int linkAndVerify() {
const Target *TheTarget =
TargetRegistry::lookupTarget("", TheTriple, ErrorStr);
if (!TheTarget)
- return Error("Error accessing target '" + TripleName + "': " + ErrorStr);
+ ErrorAndExit("Error accessing target '" + TripleName + "': " + ErrorStr);
TripleName = TheTriple.getTriple();
std::unique_ptr<MCSubtargetInfo> STI(
TheTarget->createMCSubtargetInfo(TripleName, MCPU, ""));
if (!STI)
- return Error("Unable to create subtarget info!");
+ ErrorAndExit("Unable to create subtarget info!");
std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName));
if (!MRI)
- return Error("Unable to create target register info!");
+ ErrorAndExit("Unable to create target register info!");
std::unique_ptr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*MRI, TripleName));
if (!MAI)
- return Error("Unable to create target asm info!");
+ ErrorAndExit("Unable to create target asm info!");
MCContext Ctx(MAI.get(), MRI.get(), nullptr);
std::unique_ptr<MCDisassembler> Disassembler(
TheTarget->createMCDisassembler(*STI, Ctx));
if (!Disassembler)
- return Error("Unable to create disassembler!");
+ ErrorAndExit("Unable to create disassembler!");
std::unique_ptr<MCInstrInfo> MII(TheTarget->createMCInstrInfo());
@@ -659,20 +688,25 @@ static int linkAndVerify() {
MemoryBuffer::getFileOrSTDIN(Filename);
if (std::error_code EC = InputBuffer.getError())
- return Error("unable to read input: '" + EC.message() + "'");
+ ErrorAndExit("unable to read input: '" + EC.message() + "'");
- ErrorOr<std::unique_ptr<ObjectFile>> MaybeObj(
+ Expected<std::unique_ptr<ObjectFile>> MaybeObj(
ObjectFile::createObjectFile((*InputBuffer)->getMemBufferRef()));
- if (std::error_code EC = MaybeObj.getError())
- return Error("unable to create object file: '" + EC.message() + "'");
+ if (!MaybeObj) {
+ std::string Buf;
+ raw_string_ostream OS(Buf);
+ logAllUnhandledErrors(MaybeObj.takeError(), OS, "");
+ OS.flush();
+ ErrorAndExit("unable to create object file: '" + Buf + "'");
+ }
ObjectFile &Obj = **MaybeObj;
// Load the object file
Dyld.loadObject(Obj);
if (Dyld.hasError()) {
- return Error(Dyld.getErrorString());
+ ErrorAndExit(Dyld.getErrorString());
}
}
@@ -688,14 +722,14 @@ static int linkAndVerify() {
int ErrorCode = checkAllExpressions(Checker);
if (Dyld.hasError())
- return Error("RTDyld reported an error applying relocations:\n " +
+ ErrorAndExit("RTDyld reported an error applying relocations:\n " +
Dyld.getErrorString());
return ErrorCode;
}
int main(int argc, char **argv) {
- sys::PrintStackTraceOnErrorSignal();
+ sys::PrintStackTraceOnErrorSignal(argv[0]);
PrettyStackTraceProgram X(argc, argv);
ProgramName = argv[0];