diff options
author | Stephen Hines <srhines@google.com> | 2014-07-21 00:45:20 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-07-21 00:45:20 -0700 |
commit | c6a4f5e819217e1e12c458aed8e7b122e23a3a58 (patch) | |
tree | 81b7dd2bb4370a392f31d332a566c903b5744764 /tools/llvm-rtdyld | |
parent | 19c6fbb3e8aaf74093afa08013134b61fa08f245 (diff) | |
download | external_llvm-c6a4f5e819217e1e12c458aed8e7b122e23a3a58.zip external_llvm-c6a4f5e819217e1e12c458aed8e7b122e23a3a58.tar.gz external_llvm-c6a4f5e819217e1e12c458aed8e7b122e23a3a58.tar.bz2 |
Update LLVM for rebase to r212749.
Includes a cherry-pick of:
r212948 - fixes a small issue with atomic calls
Change-Id: Ib97bd980b59f18142a69506400911a6009d9df18
Diffstat (limited to 'tools/llvm-rtdyld')
-rw-r--r-- | tools/llvm-rtdyld/Android.mk | 29 | ||||
-rw-r--r-- | tools/llvm-rtdyld/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tools/llvm-rtdyld/llvm-rtdyld.cpp | 150 |
3 files changed, 164 insertions, 17 deletions
diff --git a/tools/llvm-rtdyld/Android.mk b/tools/llvm-rtdyld/Android.mk index 54a612a..6f902d3 100644 --- a/tools/llvm-rtdyld/Android.mk +++ b/tools/llvm-rtdyld/Android.mk @@ -11,11 +11,38 @@ llvm_rtdyld_SRC_FILES := \ llvm-rtdyld.cpp llvm_rtdyld_STATIC_LIBRARIES := \ + libLLVMARMCodeGen \ + libLLVMARMInfo \ + libLLVMARMDesc \ + libLLVMARMAsmPrinter \ + libLLVMARMAsmParser \ + libLLVMARMDisassembler \ + libLLVMAArch64CodeGen \ + libLLVMAArch64Info \ + libLLVMAArch64AsmParser \ + libLLVMAArch64Desc \ + libLLVMAArch64AsmPrinter \ + libLLVMAArch64Utils \ + libLLVMAArch64Disassembler \ + libLLVMMipsCodeGen \ + libLLVMMipsInfo \ + libLLVMMipsDesc \ + libLLVMMipsAsmPrinter \ + libLLVMMipsAsmParser \ + libLLVMMipsDisassembler \ + libLLVMX86CodeGen \ + libLLVMX86Info \ + libLLVMX86Desc \ + libLLVMX86AsmPrinter \ + libLLVMX86AsmParser \ + libLLVMX86Utils \ + libLLVMX86Disassembler \ libLLVMDebugInfo \ libLLVMExecutionEngine \ + libLLVMObject \ libLLVMMC \ + libLLVMMCParser \ libLLVMRuntimeDyld \ - libLLVMObject \ libLLVMBitReader \ libLLVMCore \ libLLVMSupport \ diff --git a/tools/llvm-rtdyld/CMakeLists.txt b/tools/llvm-rtdyld/CMakeLists.txt index 3ad127f..feb2134 100644 --- a/tools/llvm-rtdyld/CMakeLists.txt +++ b/tools/llvm-rtdyld/CMakeLists.txt @@ -1,6 +1,8 @@ set(LLVM_LINK_COMPONENTS + ${LLVM_TARGETS_TO_BUILD} DebugInfo ExecutionEngine + MC RuntimeDyld Support ) diff --git a/tools/llvm-rtdyld/llvm-rtdyld.cpp b/tools/llvm-rtdyld/llvm-rtdyld.cpp index be5c345..45734f4 100644 --- a/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -16,6 +16,13 @@ #include "llvm/ExecutionEngine/ObjectBuffer.h" #include "llvm/ExecutionEngine/ObjectImage.h" #include "llvm/ExecutionEngine/RuntimeDyld.h" +#include "llvm/ExecutionEngine/RuntimeDyldChecker.h" +#include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCContext.h" +#include "llvm/MC/MCDisassembler.h" +#include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCInstPrinter.h" +#include "llvm/MC/MCRegisterInfo.h" #include "llvm/Object/MachO.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/DynamicLibrary.h" @@ -23,9 +30,12 @@ #include "llvm/Support/Memory.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/PrettyStackTrace.h" -#include "llvm/Support/Signals.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Support/system_error.h" +#include "llvm/Support/Signals.h" +#include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/TargetSelect.h" +#include <system_error> + using namespace llvm; using namespace llvm::object; @@ -35,7 +45,8 @@ InputFileList(cl::Positional, cl::ZeroOrMore, enum ActionType { AC_Execute, - AC_PrintLineInfo + AC_PrintLineInfo, + AC_Verify }; static cl::opt<ActionType> @@ -45,6 +56,8 @@ Action(cl::desc("Action to perform:"), "Load, link, and execute the inputs."), clEnumValN(AC_PrintLineInfo, "printline", "Load, link, and print line information for each function."), + clEnumValN(AC_Verify, "verify", + "Load, link and verify the resulting memory image."), clEnumValEnd)); static cl::opt<std::string> @@ -57,6 +70,14 @@ Dylibs("dylib", cl::desc("Add library."), cl::ZeroOrMore); +static cl::opt<std::string> +TripleName("triple", cl::desc("Target triple for disassembler")); + +static cl::list<std::string> +CheckFiles("check", + cl::desc("File containing RuntimeDyld verifier checks."), + cl::ZeroOrMore); + /* *** */ // A trivial memory manager that doesn't do anything fancy, just uses the @@ -139,7 +160,6 @@ static void loadDylibs() { } } - /* *** */ static int printLineInfoForInput() { @@ -155,14 +175,16 @@ static int printLineInfoForInput() { RuntimeDyld Dyld(&MemMgr); // Load the input memory buffer. - std::unique_ptr<MemoryBuffer> InputBuffer; - std::unique_ptr<ObjectImage> LoadedObject; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFileList[i], - InputBuffer)) - return Error("unable to read input: '" + ec.message() + "'"); + ErrorOr<std::unique_ptr<MemoryBuffer>> InputBuffer = + MemoryBuffer::getFileOrSTDIN(InputFileList[i]); + if (std::error_code EC = InputBuffer.getError()) + return Error("unable to read input: '" + EC.message() + "'"); + + std::unique_ptr<ObjectImage> LoadedObject; // Load the object file - LoadedObject.reset(Dyld.loadObject(new ObjectBuffer(InputBuffer.release()))); + LoadedObject.reset( + Dyld.loadObject(new ObjectBuffer(InputBuffer.get().release()))); if (!LoadedObject) { return Error(Dyld.getErrorString()); } @@ -216,14 +238,14 @@ static int executeInput() { InputFileList.push_back("-"); for(unsigned i = 0, e = InputFileList.size(); i != e; ++i) { // Load the input memory buffer. - std::unique_ptr<MemoryBuffer> InputBuffer; + ErrorOr<std::unique_ptr<MemoryBuffer>> InputBuffer = + MemoryBuffer::getFileOrSTDIN(InputFileList[i]); + if (std::error_code EC = InputBuffer.getError()) + return Error("unable to read input: '" + EC.message() + "'"); std::unique_ptr<ObjectImage> LoadedObject; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFileList[i], - InputBuffer)) - return Error("unable to read input: '" + ec.message() + "'"); - // Load the object file - LoadedObject.reset(Dyld.loadObject(new ObjectBuffer(InputBuffer.release()))); + LoadedObject.reset( + Dyld.loadObject(new ObjectBuffer(InputBuffer.get().release()))); if (!LoadedObject) { return Error(Dyld.getErrorString()); } @@ -263,6 +285,96 @@ static int executeInput() { return Main(1, Argv); } +static int checkAllExpressions(RuntimeDyldChecker &Checker) { + for (const auto& CheckerFileName : CheckFiles) { + ErrorOr<std::unique_ptr<MemoryBuffer>> CheckerFileBuf = + MemoryBuffer::getFileOrSTDIN(CheckerFileName); + if (std::error_code EC = CheckerFileBuf.getError()) + return Error("unable to read input '" + CheckerFileName + "': " + + EC.message()); + + if (!Checker.checkAllRulesInBuffer("# rtdyld-check:", + CheckerFileBuf.get().get())) + return Error("some checks in '" + CheckerFileName + "' failed"); + } + return 0; +} + +static int linkAndVerify() { + + // Check for missing triple. + if (TripleName == "") { + llvm::errs() << "Error: -triple required when running in -verify mode.\n"; + return 1; + } + + // Look up the target and build the disassembler. + Triple TheTriple(Triple::normalize(TripleName)); + std::string ErrorStr; + const Target *TheTarget = + TargetRegistry::lookupTarget("", TheTriple, ErrorStr); + if (!TheTarget) { + llvm::errs() << "Error accessing target '" << TripleName << "': " + << ErrorStr << "\n"; + return 1; + } + TripleName = TheTriple.getTriple(); + + std::unique_ptr<MCSubtargetInfo> STI( + TheTarget->createMCSubtargetInfo(TripleName, "", "")); + assert(STI && "Unable to create subtarget info!"); + + std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TripleName)); + assert(MRI && "Unable to create target register info!"); + + std::unique_ptr<MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*MRI, TripleName)); + assert(MAI && "Unable to create target asm info!"); + + MCContext Ctx(MAI.get(), MRI.get(), nullptr); + + std::unique_ptr<MCDisassembler> Disassembler( + TheTarget->createMCDisassembler(*STI, Ctx)); + assert(Disassembler && "Unable to create disassembler!"); + + std::unique_ptr<MCInstrInfo> MII(TheTarget->createMCInstrInfo()); + + std::unique_ptr<MCInstPrinter> InstPrinter( + TheTarget->createMCInstPrinter(0, *MAI, *MII, *MRI, *STI)); + + // Load any dylibs requested on the command line. + loadDylibs(); + + // Instantiate a dynamic linker. + TrivialMemoryManager MemMgr; + RuntimeDyld Dyld(&MemMgr); + + // If we don't have any input files, read from stdin. + if (!InputFileList.size()) + InputFileList.push_back("-"); + for(unsigned i = 0, e = InputFileList.size(); i != e; ++i) { + // Load the input memory buffer. + ErrorOr<std::unique_ptr<MemoryBuffer>> InputBuffer = + MemoryBuffer::getFileOrSTDIN(InputFileList[i]); + if (std::error_code EC = InputBuffer.getError()) + return Error("unable to read input: '" + EC.message() + "'"); + + std::unique_ptr<ObjectImage> LoadedObject; + // Load the object file + LoadedObject.reset( + Dyld.loadObject(new ObjectBuffer(InputBuffer.get().release()))); + if (!LoadedObject) { + return Error(Dyld.getErrorString()); + } + } + + // Resolve all the relocations we can. + Dyld.resolveRelocations(); + + RuntimeDyldChecker Checker(Dyld, Disassembler.get(), InstPrinter.get(), + llvm::dbgs()); + return checkAllExpressions(Checker); +} + int main(int argc, char **argv) { sys::PrintStackTraceOnErrorSignal(); PrettyStackTraceProgram X(argc, argv); @@ -270,6 +382,10 @@ int main(int argc, char **argv) { ProgramName = argv[0]; llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllDisassemblers(); + cl::ParseCommandLineOptions(argc, argv, "llvm MC-JIT tool\n"); switch (Action) { @@ -277,5 +393,7 @@ int main(int argc, char **argv) { return executeInput(); case AC_PrintLineInfo: return printLineInfoForInput(); + case AC_Verify: + return linkAndVerify(); } } |