-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLlvmObject.h
63 lines (47 loc) · 1.25 KB
/
LlvmObject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include "Vpu.h"
#include "llvm/Support/Error.h"
#include "llvm/Object/Binary.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Object/COFF.h"
#include "llvm/Object/ELF.h"
#include <map>
#include <vector>
struct VpuObjRelocation {
uint32_t m_type;
uint64_t m_fixupOffset; // offset from base to fixup
std::string m_symbolName;
};
class VpuObject
{
public:
VpuObject() { m_loaded = false; }
~VpuObject() { assert(!m_loaded); }
bool Open(const char * filePath);
void Close();
bool GetSymbolValue(const char * name, uint64_t & value)
{
assert(m_loaded);
if (m_symbolTable.count(name) == 0)
return false;
value = m_symbolTable[name];
return true;
}
const std::vector<VpuObjRelocation> & GetRelocations(void)
{
assert(m_loaded);
return m_relocations;
}
uint64_t GetCodeSize() { assert(m_loaded); return m_code.getSize(); }
bool GetCode(uint8_t * buffer, uint64_t size);
private:
bool LoadSymbolTable();
bool LoadRelocations();
bool m_loaded;
llvm::object::OwningBinary<llvm::object::Binary> m_binary;
llvm::object::ObjectFile * m_obj;
const llvm::object::COFFObjectFile * m_coff;
llvm::object::SectionRef m_code;
std::map<std::string, uint64_t> m_symbolTable;
std::vector<VpuObjRelocation> m_relocations;
};