Commit 382d5095 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Rebase to LLVM r223801

Primary challenge is rebasing past the JITEventListener changes.

Some API changes, but also some considerable functionality changes,
since we no longer get the loaded version of the object file.

They added a feature to get the load address of a section, but not of
a symbol; I think that makes sense so I'll submit a patch for that.
parent 3a338555
......@@ -741,12 +741,12 @@ endef
$(call link,_grwl,stdlib.grwl.bc.o $(SRCS:.cpp=.grwl.o),$(LDFLAGS_RELEASE),$(LLVM_RELEASE_DEPS))
$(call link,_grwl_dbg,stdlib.grwl_dbg.bc.o $(SRCS:.cpp=.grwl_dbg.o),$(LDFLAGS),$(LLVM_DEPS))
$(call link,_nosync,stdlib.nosync.bc.o $(SRCS:.cpp=.nosync.o),$(LDFLAGS_RELEASE),$(LLVM_RELEASE_DEPS))
pyston_oprof: $(OPT_OBJS) codegen/profiling/oprofile.o $(LLVM_DEPS)
pyston_oprof: $(OPT_OBJS) src/codegen/profiling/oprofile.o $(LLVM_DEPS)
$(ECHO) Linking $@
$(VERB) $(CXX) $(OPT_OBJS) codegen/profiling/oprofile.o $(LDFLAGS_RELEASE) -lopagent -o $@
pyston_pprof: $(OPT_OBJS) codegen/profiling/pprof.release.o $(LLVM_DEPS)
$(VERB) $(CXX) $(OPT_OBJS) src/codegen/profiling/oprofile.o $(LDFLAGS_RELEASE) -lopagent -o $@
pyston_pprof: $(OPT_OBJS) src/codegen/profiling/pprof.release.o $(LLVM_DEPS)
$(ECHO) Linking $@
$(VERB) $(CXX) $(OPT_OBJS) codegen/profiling/pprof.release.o $(LDFLAGS_RELEASE) -lprofiler -o $@
$(VERB) $(CXX) $(OPT_OBJS) src/codegen/profiling/pprof.release.o $(LDFLAGS_RELEASE) -lprofiler -o $@
pyston_prof: $(PROFILE_OBJS) $(LLVM_DEPS)
$(ECHO) Linking $@
$(VERB) $(CXX) $(PROFILE_OBJS) $(LDFLAGS) -pg -o $@
......
......@@ -35,7 +35,7 @@ diff --git a/include/llvm/IR/Intrinsics.td b/include/llvm/IR/Intrinsics.td
index 1b9339a..45eecca 100644
--- a/include/llvm/IR/Intrinsics.td
+++ b/include/llvm/IR/Intrinsics.td
@@ -490,6 +490,11 @@ def int_experimental_patchpoint_i64 : Intrinsic<[llvm_i64_ty],
@@ -490,4 +490,9 @@ def int_experimental_patchpoint_i64 : Intrinsic<[llvm_i64_ty],
llvm_ptr_ty, llvm_i32_ty,
llvm_vararg_ty],
[Throws]>;
......@@ -45,8 +45,6 @@ index 1b9339a..45eecca 100644
+ llvm_vararg_ty],
+ [Throws]>;
//===-------------------------- Other Intrinsics --------------------------===//
//
diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp
index 72390a9..b624a63 100644
--- a/lib/CodeGen/SelectionDAG/FastISel.cpp
......
From 0fdc4cdde6c1642c2860a41af31f10f85153f1f6 Mon Sep 17 00:00:00 2001
From: Kevin Modzelewski <kevmod@gmail.com>
Date: Mon, 5 Jan 2015 04:10:04 +0000
Subject: [PATCH] Expose getSymbolLoadAddress through LoadedObjectInfo
---
include/llvm/ExecutionEngine/RuntimeDyld.h | 1 +
lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/include/llvm/ExecutionEngine/RuntimeDyld.h b/include/llvm/ExecutionEngine/RuntimeDyld.h
index 799fc34..ae8d699 100644
--- a/include/llvm/ExecutionEngine/RuntimeDyld.h
+++ b/include/llvm/ExecutionEngine/RuntimeDyld.h
@@ -60,6 +60,7 @@ public:
virtual object::OwningBinary<object::ObjectFile>
getObjectForDebug(const object::ObjectFile &Obj) const = 0;
+ uint64_t getSymbolLoadAddress(StringRef Name) const;
uint64_t getSectionLoadAddress(StringRef Name) const;
protected:
diff --git a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
index 00ac869..f7c5934 100644
--- a/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
+++ b/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
@@ -742,6 +742,11 @@ uint64_t RuntimeDyld::LoadedObjectInfo::getSectionLoadAddress(
return 0;
}
+uint64_t RuntimeDyld::LoadedObjectInfo::getSymbolLoadAddress(
+ StringRef SymbolName) const {
+ return RTDyld.getSymbolLoadAddress(SymbolName);
+}
+
RuntimeDyld::RuntimeDyld(RTDyldMemoryManager *mm) {
// FIXME: There's a potential issue lurking here if a single instance of
// RuntimeDyld is used to load multiple objects. The current implementation
--
1.9.1
......@@ -20,9 +20,10 @@
#include <unistd.h>
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/ExecutionEngine/ObjectImage.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/FileSystem.h"
#include "analysis/scoping_analysis.h"
#include "core/ast.h"
......@@ -154,20 +155,15 @@ std::string FunctionAddressRegistry::getFuncNameAtAddress(void* addr, bool deman
class RegistryEventListener : public llvm::JITEventListener {
public:
void NotifyObjectEmitted(const llvm::ObjectImage& Obj) {
virtual void NotifyObjectEmitted(const llvm::object::ObjectFile& Obj,
const llvm::RuntimeDyld::LoadedObjectInfo& L) {
static StatCounter code_bytes("code_bytes");
code_bytes.log(Obj.getData().size());
llvm_error_code code;
for (llvm::object::symbol_iterator I = Obj.begin_symbols(), E = Obj.end_symbols(); I != E;
#if LLVMREV < 200442
I = I.increment(code)
#else
++I
#endif
) {
llvm::object::section_iterator section(Obj.end_sections());
code = I->getSection(section);
for (const auto& sym : Obj.symbols()) {
llvm::object::section_iterator section(Obj.section_end());
code = sym.getSection(section);
assert(!code);
bool is_text;
#if LLVMREV < 219314
......@@ -180,18 +176,20 @@ public:
continue;
llvm::StringRef name;
uint64_t addr, size;
code = I->getName(name);
assert(!code);
code = I->getAddress(addr);
code = sym.getName(name);
assert(!code);
code = I->getSize(size);
uint64_t size;
code = sym.getSize(size);
assert(!code);
if (name == ".text")
continue;
g.func_addr_registry.registerFunction(name.data(), (void*)addr, size, NULL);
uint64_t sym_addr = L.getSymbolLoadAddress(name);
assert(sym_addr);
g.func_addr_registry.registerFunction(name.data(), (void*)sym_addr, size, NULL);
}
}
};
......
// Copyright (c) 2014-2015 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "codegen/dis.h"
#if LLVMREV < 216983
#include <cstdio>
#include <iostream>
#include <unordered_map>
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
#include "llvm/IR/Mangler.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCAtom.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDisassembler.h"
#include "llvm/MC/MCFunction.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCModule.h"
#include "llvm/MC/MCObjectDisassembler.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
#include "codegen/codegen.h"
namespace pyston {
DisassemblerJITEventListener::DisassemblerJITEventListener() {
llvm::InitializeNativeTargetAsmPrinter();
llvm::InitializeNativeTargetAsmParser();
llvm::InitializeNativeTargetDisassembler();
std::string err;
const llvm::Target* target = llvm::TargetRegistry::getClosestTargetForJIT(err);
assert(target);
const llvm::StringRef triple = g.tm->getTargetTriple();
// llvm::Triple *ltriple = new llvm::Triple(triple);
const llvm::StringRef CPU = "";
const llvm::MCRegisterInfo* MRI = target->createMCRegInfo(triple);
assert(MRI);
const llvm::MCAsmInfo* MAI = target->createMCAsmInfo(*MRI, triple);
assert(MAI);
const llvm::MCInstrInfo* MII = target->createMCInstrInfo();
assert(MII);
std::string FeaturesStr;
const llvm::MCSubtargetInfo* STI = target->createMCSubtargetInfo(triple, CPU, FeaturesStr);
assert(STI);
llvm::MCObjectFileInfo* MOFI = new llvm::MCObjectFileInfo();
llvm::MCContext* Ctx = new llvm::MCContext(MAI, MRI, MOFI);
assert(Ctx);
assert(Ctx->getObjectFileInfo());
MOFI->InitMCObjectFileInfo(triple, llvm::Reloc::Default, llvm::CodeModel::Default, *Ctx);
llvm::MCAsmBackend* TAB = target->createMCAsmBackend(*MRI, triple, CPU);
assert(TAB);
int AsmPrinterVariant = MAI->getAssemblerDialect(); // 0 is ATT, 1 is Intel
IP = target->createMCInstPrinter(AsmPrinterVariant, *MAI, *MII, *MRI, *STI);
assert(IP);
llvm::MCCodeEmitter* CE = target->createMCCodeEmitter(*MII, *MRI, *STI, *Ctx);
assert(CE);
bool verbose = false;
#if LLVMREV < 208205
llvm::MCStreamer* streamer = target->createAsmStreamer(*Ctx, llvm::ferrs(), verbose, true, true, IP, CE, TAB, true);
#else
llvm::MCStreamer* streamer = target->createAsmStreamer(*Ctx, llvm::ferrs(), verbose, true, IP, CE, TAB, true);
#endif
assert(streamer);
streamer->InitSections();
streamer->SwitchSection(Ctx->getObjectFileInfo()->getTextSection());
asm_printer = target->createAsmPrinter(*g.tm, *streamer);
assert(asm_printer);
llvm::TargetOptions Options;
llvm::TargetMachine* tmachine = target->createTargetMachine(triple, "", "", Options, llvm::Reloc::Default,
llvm::CodeModel::Default, llvm::CodeGenOpt::Default);
// asm_printer->Mang = new llvm::Mangler(*Ctx, *tmachine->getDataLayout());
asm_printer->Mang = new llvm::Mangler(tmachine->getDataLayout());
DisAsm = target->createMCDisassembler(*STI, *Ctx);
assert(DisAsm);
MIA = target->createMCInstrAnalysis(MII);
assert(MIA);
}
void DisassemblerJITEventListener::NotifyFunctionEmitted(const llvm::Function& f, void* ptr, size_t size,
const llvm::JITEvent_EmittedFunctionDetails& details) {
const llvm::MachineFunction& MF = *details.MF; //*const_cast<llvm::MachineFunction*>(details.MF);
printf("emitted! %p %ld %s\n", ptr, size, f.getName().data());
// MF.dump();
// MF.print(llvm::errs());
asm_printer->MF = &MF;
for (llvm::MachineFunction::const_iterator it = MF.begin(); it != MF.end(); it++) {
// it->dump();
asm_printer->EmitBasicBlockStart(*it);
for (llvm::MachineBasicBlock::const_instr_iterator it2 = it->instr_begin(); it2 != it->instr_end(); it2++) {
// llvm::errs() << "dump:";
// it2->print(llvm::errs());
if (it2->getNumOperands() && (it2->getOperand(0).getType() == llvm::MachineOperand::MO_MCSymbol)) {
// it2->print(llvm::errs());
// it2->getOperand(0).print(llvm::errs());
llvm::errs() << it2->getOperand(0).getMCSymbol()->getName() << '\n';
} else {
asm_printer->EmitInstruction(it2);
}
}
}
llvm::errs() << '\n';
llvm::errs().flush();
}
void DisassemblerJITEventListener::NotifyObjectEmitted(const llvm::ObjectImage& Obj) {
llvm::outs() << "An object has been emitted:\n";
llvm::error_code code;
for (llvm::object::section_iterator I = Obj.begin_sections(), E = Obj.end_sections(); I != E;) {
llvm::StringRef name;
code = I->getName(name);
assert(!code);
uint64_t address, size;
const char* type = "unknown";
bool b;
code = I->isText(b);
assert(!code);
if (b)
type = "text";
code = I->isData(b);
assert(!code);
if (b)
type = "data";
code = I->isBSS(b);
assert(!code);
if (b)
type = "bss";
code = I->isReadOnlyData(b);
assert(!code);
if (b)
type = "rodata";
code = I->getAddress(address);
assert(!code);
code = I->getSize(size);
assert(!code);
printf("Section: %s %s (%lx %lx)\n", name.data(), type, address, size);
#if LLVMREV < 200442
I = I.increment(code);
#else
++I;
#endif
}
for (llvm::object::symbol_iterator I = Obj.begin_symbols(), E = Obj.end_symbols(); I != E;) {
llvm::StringRef name;
uint64_t addr, size;
code = I->getName(name);
assert(!code);
code = I->getAddress(addr);
assert(!code);
code = I->getSize(size);
assert(!code);
printf("%lx %lx %s\n", addr, addr + size, name.data());
#if LLVMREV < 200442
I = I.increment(code);
#else
++I;
#endif
}
llvm::MCObjectDisassembler* OD = new llvm::MCObjectDisassembler(*Obj.getObjectFile(), *DisAsm, *MIA);
llvm::MCModule* Mod = OD->buildModule(true);
// This is taken from llvm-objdump.cpp:
uint64_t text_start = 0;
for (llvm::MCModule::const_atom_iterator AI = Mod->atom_begin(), AE = Mod->atom_end(); AI != AE; ++AI) {
llvm::outs() << "Atom " << (*AI)->getName() << ", starts at " << (void*)(*AI)->getBeginAddr() << ": \n";
if ((*AI)->getName() == ".text")
text_start = (*AI)->getBeginAddr();
if (const llvm::MCTextAtom* TA = llvm::dyn_cast<llvm::MCTextAtom>(*AI)) {
for (llvm::MCTextAtom::const_iterator II = TA->begin(), IE = TA->end(); II != IE; ++II) {
llvm::outs() << "0x";
llvm::outs().write_hex(II->Address);
// llvm::outs() << " (+0x";
// llvm::outs().write_hex(II->Address - text_start);
llvm::outs() << " (+" << II->Address - text_start;
llvm::outs() << ") ";
IP->printInst(&II->Inst, llvm::outs(), "");
llvm::outs() << "\n";
}
}
}
llvm::outs().flush();
}
}
#endif
// Copyright (c) 2014-2015 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef PYSTON_CODEGEN_DIS_H
#define PYSTON_CODEGEN_DIS_H
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/ExecutionEngine/ObjectImage.h"
namespace llvm {
class MCDisassembler;
class MCInstrAnalysis;
class MCInstPrinter;
}
namespace pyston {
class DisassemblerJITEventListener : public llvm::JITEventListener {
private:
llvm::AsmPrinter* asm_printer;
llvm::MCDisassembler* DisAsm;
llvm::MCInstrAnalysis* MIA;
llvm::MCInstPrinter* IP;
public:
DisassemblerJITEventListener();
virtual void NotifyFunctionEmitted(const llvm::Function& f, void* ptr, size_t size,
const llvm::JITEvent_EmittedFunctionDetails& details);
virtual void NotifyObjectEmitted(const llvm::ObjectImage& Obj);
};
}
#endif
......@@ -21,6 +21,7 @@
#include "llvm/Analysis/Passes.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/ExecutionEngine/MCJIT.h"
#include "llvm/ExecutionEngine/ObjectCache.h"
#include "llvm/IR/IRBuilder.h"
......@@ -35,7 +36,6 @@
#include "llvm/Transforms/Utils/Cloning.h"
#include "codegen/codegen.h"
#include "codegen/dis.h"
#include "codegen/memmgr.h"
#include "codegen/profiling/profiling.h"
#include "codegen/stackmaps.h"
......@@ -199,7 +199,11 @@ void initCodegen() {
#endif
eb.setEngineKind(llvm::EngineKind::JIT); // specify we only want the JIT, and not the interpreter fallback
#if LLVMREV < 223183
eb.setMCJITMemoryManager(createMemoryManager().release());
#else
eb.setMCJITMemoryManager(createMemoryManager());
#endif
// eb.setOptLevel(llvm::CodeGenOpt::None); // -O0
// eb.setOptLevel(llvm::CodeGenOpt::Less); // -O1
// eb.setOptLevel(llvm::CodeGenOpt::Default); // -O2, -Os
......
......@@ -63,17 +63,6 @@ void MyInserter::InsertHelper(llvm::Instruction* I, const llvm::Twine& Name, llv
llvm::IRBuilderDefaultInserter<true>::InsertHelper(I, Name, BB, InsertPt);
}
static void addIRDebugSymbols(llvm::Function* f) {
llvm::legacy::PassManager mpm;
llvm_error_code code = llvm::sys::fs::create_directory(".debug_ir", true);
assert(!code);
mpm.add(llvm::createDebugIRPass(false, false, ".debug_ir", f->getName()));
mpm.run(*g.cur_module);
}
static void optimizeIR(llvm::Function* f, EffortLevel::EffortLevel effort) {
// TODO maybe should do some simple passes (ex: gvn?) if effort level isn't maximal?
// In general, this function needs a lot of tuning.
......@@ -1259,12 +1248,6 @@ CompiledFunction* doCompile(SourceInfo* source, const OSREntryDescriptor* entry_
if (ENABLE_LLVMOPTS)
optimizeIR(f, effort);
bool ENABLE_IR_DEBUG = false;
if (ENABLE_IR_DEBUG) {
addIRDebugSymbols(f);
// dumpPrettyIR(f);
}
g.cur_module = NULL;
return cf;
......
......@@ -227,8 +227,8 @@ PystonMemoryManager::~PystonMemoryManager() {
sys::Memory::releaseMappedMemory(RODataMem.AllocatedMem[i]);
}
llvm::RTDyldMemoryManager* createMemoryManager() {
return new PystonMemoryManager();
std::unique_ptr<llvm::RTDyldMemoryManager> createMemoryManager() {
return std::unique_ptr<llvm::RTDyldMemoryManager>(new PystonMemoryManager());
}
// These functions exist as instance methods of the RTDyldMemoryManager class,
......
......@@ -17,6 +17,7 @@
#include <cstddef>
#include <cstdint>
#include <memory>
namespace llvm {
class RTDyldMemoryManager;
......@@ -24,7 +25,7 @@ class RTDyldMemoryManager;
namespace pyston {
llvm::RTDyldMemoryManager* createMemoryManager();
std::unique_ptr<llvm::RTDyldMemoryManager> createMemoryManager();
void registerEHFrames(uint8_t* addr, uint64_t load_addr, size_t size);
void deregisterEHFrames(uint8_t* addr, uint64_t load_addr, size_t size);
}
......
......@@ -15,7 +15,7 @@
#include <sstream>
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/ExecutionEngine/ObjectImage.h"
#include "llvm/Object/ObjectFile.h"
#include "codegen/profiling/profiling.h"
#include "core/common.h"
......@@ -26,11 +26,12 @@ namespace pyston {
class DumpJITEventListener : public llvm::JITEventListener {
private:
public:
virtual void NotifyObjectEmitted(const llvm::ObjectImage& Obj);
virtual void NotifyObjectEmitted(const llvm::object::ObjectFile& Obj, const llvm::RuntimeDyld::LoadedObjectInfo& L);
};
static int num = 0;
void DumpJITEventListener::NotifyObjectEmitted(const llvm::ObjectImage& Obj) {
void DumpJITEventListener::NotifyObjectEmitted(const llvm::object::ObjectFile& Obj,
const llvm::RuntimeDyld::LoadedObjectInfo& L) {
llvm_error_code code;
std::ostringstream os("");
......
......@@ -13,7 +13,7 @@
// limitations under the License.
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/ExecutionEngine/ObjectImage.h"
#include "llvm/Object/ObjectFile.h"
#include "opagent.h"
......@@ -35,26 +35,26 @@ public:
virtual ~OprofileJITEventListener() { op_close_agent(agent); }
virtual void NotifyObjectEmitted(const llvm::ObjectImage& Obj);
virtual void NotifyObjectEmitted(const llvm::object::ObjectFile& Obj, const llvm::RuntimeDyld::LoadedObjectInfo& L);
};
void OprofileJITEventListener::NotifyObjectEmitted(const llvm::ObjectImage& Obj) {
void OprofileJITEventListener::NotifyObjectEmitted(const llvm::object::ObjectFile& Obj,
const llvm::RuntimeDyld::LoadedObjectInfo& L) {
if (VERBOSITY() >= 1)
printf("An object has been emitted:\n");
llvm_error_code code;
for (llvm::object::symbol_iterator I = Obj.begin_symbols(), E = Obj.end_symbols(); I != E;) {
for (const auto& sym : Obj.symbols()) {
llvm::object::SymbolRef::Type type;
code = I->getType(type);
code = sym.getType(type);
assert(!code);
if (type == llvm::object::SymbolRef::ST_Function) {
llvm::StringRef name;
uint64_t addr, size;
code = I->getName(name);
code = sym.getName(name);
assert(!code);
code = I->getAddress(addr);
assert(!code);
code = I->getSize(size);
addr = L.getSymbolLoadAddress(name);
code = sym.getSize(size);
assert(!code);
if (VERBOSITY() >= 1)
......@@ -63,11 +63,10 @@ void OprofileJITEventListener::NotifyObjectEmitted(const llvm::ObjectImage& Obj)
assert(r == 0);
//} else {
// llvm::StringRef name;
// code = I->getName(name);
// code = sym.getName(name);
// assert(!code);
// printf("Skipping %s\n", name.data());
}
++I;
}
}
......
......@@ -13,7 +13,7 @@
// limitations under the License.
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/ExecutionEngine/ObjectImage.h"
#include "llvm/Object/ObjectFile.h"
#include "codegen/profiling/profiling.h"
#include "core/common.h"
......@@ -29,23 +29,23 @@ public:
PprofJITEventListener() { of = fopen("pprof.jit", "w"); }
virtual ~PprofJITEventListener() { fclose(of); }
virtual void NotifyObjectEmitted(const llvm::ObjectImage& Obj);
virtual void NotifyObjectEmitted(const llvm::object::ObjectFile& Obj, const llvm::RuntimeDyld::LoadedObjectInfo& L);
};
void PprofJITEventListener::NotifyObjectEmitted(const llvm::ObjectImage& Obj) {
llvm::error_code code;
for (llvm::object::symbol_iterator I = Obj.begin_symbols(), E = Obj.end_symbols(); I != E;) {
void PprofJITEventListener::NotifyObjectEmitted(const llvm::object::ObjectFile& Obj,
const llvm::RuntimeDyld::LoadedObjectInfo& L) {
llvm_error_code code;
for (const auto& sym : Obj.symbols()) {
llvm::object::SymbolRef::Type type;
code = I->getType(type);
code = sym.getType(type);
assert(!code);
if (type == llvm::object::SymbolRef::ST_Function) {
llvm::StringRef name;
uint64_t addr, size;
code = I->getName(name);
code = sym.getName(name);
assert(!code);
code = I->getAddress(addr);
assert(!code);
code = I->getSize(size);
addr = L.getSymbolLoadAddress(name);
code = sym.getSize(size);
assert(!code);
// fprintf(of, "%lx-%lx: %s\n", addr, addr + size, name.data());
......@@ -55,7 +55,6 @@ void PprofJITEventListener::NotifyObjectEmitted(const llvm::ObjectImage& Obj) {
if (VERBOSITY() >= 1)
printf("%lx %lx %s\n", addr, addr + size, name.data());
}
++I;
}
}
......
......@@ -21,7 +21,6 @@
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/ExecutionEngine/ObjectImage.h"
#include "llvm/Object/ObjectFile.h"
#include "codegen/codegen.h"
......@@ -43,7 +42,7 @@ StackMap* parseStackMap() {
class StackmapJITEventListener : public llvm::JITEventListener {
private:
public:
virtual void NotifyObjectEmitted(const llvm::ObjectImage&);
virtual void NotifyObjectEmitted(const llvm::object::ObjectFile&, const llvm::RuntimeDyld::LoadedObjectInfo& L);
};
// LLVM will silently not register the eh frames with libgcc if these functions don't exist;
......@@ -57,23 +56,21 @@ extern void _force_link() {
__deregister_frame(nullptr);
}
void StackmapJITEventListener::NotifyObjectEmitted(const llvm::ObjectImage& Obj) {
void StackmapJITEventListener::NotifyObjectEmitted(const llvm::object::ObjectFile& Obj,
const llvm::RuntimeDyld::LoadedObjectInfo& L) {
// llvm::outs() << "An object has been emitted:\n";
llvm_error_code code;
for (llvm::object::symbol_iterator I = Obj.begin_symbols(), E = Obj.end_symbols(); I != E;) {
for (const auto& sec : Obj.sections()) {
llvm::StringRef name;
code = I->getName(name);
code = sec.getName(name);
assert(!code);
if (name == "__LLVM_StackMaps") {
uint64_t stackmap_address = 0;
code = I->getAddress(stackmap_address);
assert(!code);
// code = I->getSize(stackmap_size);
// assert(stackmap_size > 0);
// assert(!code);
if (name == ".llvm_stackmaps") {
uint64_t stackmap_address = L.getSectionLoadAddress(name);
assert(stackmap_address > 0);
if (VERBOSITY() >= 2)
printf("Found the stackmaps at stackmap_address 0x%lx\n", stackmap_address);
......@@ -175,28 +172,9 @@ void StackmapJITEventListener::NotifyObjectEmitted(const llvm::ObjectImage& Obj)
ptr.u32++; // pad to 8-byte boundary
}
#ifndef NDEBUG
uint64_t stackmap_size;
llvm::object::section_iterator section(Obj.end_sections());
code = I->getSection(section);
assert(!code);
#if LLVMREV < 219314
code = section->getSize(stackmap_size);
assert(!code);
#else
stackmap_size = section->getSize();
#endif
assert(stackmap_size > 0);
uint64_t stackmap_size = sec.getSize();
ASSERT(ptr.i8 - start_ptr == stackmap_size, "%ld %ld", ptr.i8 - start_ptr, stackmap_size);
#endif
}
#if LLVMREV < 200442
I = I.increment(code);
#else
++I;
#endif
}
}
......
......@@ -20,8 +20,8 @@
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/ExecutionEngine/ObjectImage.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/Object/ObjectFile.h"
#include "codegen/ast_interpreter.h"
#include "codegen/codegen.h"
......@@ -97,25 +97,26 @@ CompiledFunction* getCFForAddress(uint64_t addr) {
class TracebacksEventListener : public llvm::JITEventListener {
public:
void NotifyObjectEmitted(const llvm::ObjectImage& Obj) {
std::unique_ptr<llvm::DIContext> Context(llvm::DIContext::getDWARFContext(*Obj.getObjectFile()));
virtual void NotifyObjectEmitted(const llvm::object::ObjectFile& Obj,
const llvm::RuntimeDyld::LoadedObjectInfo& L) {
std::unique_ptr<llvm::DIContext> Context(llvm::DIContext::getDWARFContext(Obj));
assert(g.cur_cf);
llvm_error_code ec;
for (llvm::object::symbol_iterator I = Obj.begin_symbols(), E = Obj.end_symbols(); I != E && !ec; ++I) {
for (const auto& sym : Obj.symbols()) {
llvm::object::SymbolRef::Type SymType;
if (I->getType(SymType))
if (sym.getType(SymType))
continue;
if (SymType == llvm::object::SymbolRef::ST_Function) {
llvm::StringRef Name;
uint64_t Addr;
uint64_t Size;
if (I->getName(Name))
if (sym.getName(Name))
continue;
if (I->getAddress(Addr))
continue;
if (I->getSize(Size))
Addr = L.getSymbolLoadAddress(Name);
assert(Addr);
if (sym.getSize(Size))
continue;
// TODO this should be the Python name, not the C name:
......@@ -148,38 +149,24 @@ public:
uint64_t text_addr = -1, text_size = -1;
uint64_t eh_frame_addr = -1, eh_frame_size = -1;
for (llvm::object::section_iterator I = Obj.begin_sections(), E = Obj.end_sections(); I != E; ++I) {
for (const auto& sec : Obj.sections()) {
llvm::StringRef name;
code = I->getName(name);
code = sec.getName(name);
assert(!code);
uint64_t addr, size;
if (name == ".eh_frame") {
assert(!found_eh_frame);
#if LLVMREV < 219314
if (I->getAddress(eh_frame_addr))
continue;
if (I->getSize(eh_frame_size))
continue;
#else
eh_frame_addr = I->getAddress();
eh_frame_size = I->getSize();
#endif
eh_frame_addr = L.getSectionLoadAddress(name);
eh_frame_size = sec.getSize();
if (VERBOSITY())
printf("eh_frame: %lx %lx\n", eh_frame_addr, eh_frame_size);
found_eh_frame = true;
} else if (name == ".text") {
assert(!found_text);
#if LLVMREV < 219314
if (I->getAddress(text_addr))
continue;
if (I->getSize(text_size))
continue;
#else
text_addr = I->getAddress();
text_size = I->getSize();
#endif
text_addr = L.getSectionLoadAddress(name);
text_size = sec.getSize();
if (VERBOSITY())
printf("text: %lx %lx\n", text_addr, text_size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment