Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tpde-llvm/include/tpde-llvm/LLVMCompiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ class JITMapper {

/// Get the address for a global, which must be contained in the compiled
/// module.
void *lookup_global(llvm::GlobalValue *);
void *lookup_global(llvm::GlobalValue *) const;

/// Get the range, mapped to memory
std::pair<void*, void*> get_mapped_range() const;

/// Indicate whether compilation and in-memory mapping was successful.
operator bool() const { return impl != nullptr; }
Expand Down
6 changes: 5 additions & 1 deletion tpde-llvm/src/JITMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ JITMapper::~JITMapper() = default;
JITMapper::JITMapper(JITMapper &&other) = default;
JITMapper &JITMapper::operator=(JITMapper &&other) = default;

void *JITMapper::lookup_global(llvm::GlobalValue *gv) {
void *JITMapper::lookup_global(llvm::GlobalValue *gv) const {
return impl ? impl->lookup_global(gv) : nullptr;
}

std::pair<void*, void*> JITMapper::get_mapped_range() const {
return impl ? impl->get_mapped_range() : std::make_pair(nullptr, nullptr);
}

} // namespace tpde_llvm
6 changes: 5 additions & 1 deletion tpde-llvm/src/JITMapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ class JITMapperImpl {
/// Map the ELF from the assembler into memory, returns true on success.
bool map(tpde::elf::AssemblerElf &, tpde::elf::ElfMapper::SymbolResolver);

void *lookup_global(llvm::GlobalValue *gv) {
void *lookup_global(llvm::GlobalValue *gv) const {
return mapper.get_sym_addr(globals.lookup(gv));
}

std::pair<void*, void*> get_mapped_range() const {
return mapper.get_mapped_range();
}
};

} // namespace tpde_llvm
6 changes: 4 additions & 2 deletions tpde/include/tpde/ElfMapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ElfMapper {

private:
u8 *mapped_addr = nullptr;
size_t mapped_size;
size_t mapped_size = 0;
u32 registered_frame_off = 0;

u32 local_sym_count = 0;
Expand All @@ -38,7 +38,9 @@ class ElfMapper {

bool map(AssemblerElf &assembler, SymbolResolver resolver);

void *get_sym_addr(SymRef sym);
void *get_sym_addr(SymRef sym) const;

std::pair<void*, void*> get_mapped_range() const;
};

} // namespace tpde::elf
10 changes: 8 additions & 2 deletions tpde/src/ElfMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void ElfMapper::reset() {

munmap(mapped_addr, mapped_size);
mapped_addr = nullptr;
mapped_size = 0;
sym_addrs.clear();
}

Expand Down Expand Up @@ -423,7 +424,7 @@ bool ElfMapper::map(AssemblerElf &assembler, SymbolResolver resolver) {
return true;
}

void *ElfMapper::get_sym_addr(SymRef sym) {
void *ElfMapper::get_sym_addr(SymRef sym) const {
auto idx = AssemblerElf::sym_idx(sym);
if (!AssemblerElf::sym_is_local(sym)) {
idx += local_sym_count;
Expand All @@ -432,6 +433,10 @@ void *ElfMapper::get_sym_addr(SymRef sym) {
return sym_addrs[idx];
}

std::pair<void*, void*> ElfMapper::get_mapped_range() const {
return {mapped_addr, mapped_addr + mapped_size};
}

} // namespace tpde::elf

#else
Expand All @@ -445,7 +450,8 @@ void ElfMapper::reset() {
(void)local_sym_count;
}
bool ElfMapper::map(AssemblerElf &, SymbolResolver) { return false; }
void *ElfMapper::get_sym_addr(SymRef) { return nullptr; }
void *ElfMapper::get_sym_addr(SymRef) const { return nullptr; }
std::pair<void*, void*> ElfMapper::get_mapped_range() const { return {nullptr, nullptr}; }
} // namespace tpde::elf

#endif