Skip to content

Commit e245af6

Browse files
committed
Add relocation iterators to the libObject C API.
llvm-svn: 143107
1 parent 2aed439 commit e245af6

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

llvm/include/llvm-c/Object.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extern "C" {
3232
typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef;
3333
typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef;
3434
typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef;
35+
typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef;
3536

3637
// ObjectFile creation
3738
LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf);
@@ -61,6 +62,14 @@ uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI);
6162
LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,
6263
LLVMSymbolIteratorRef Sym);
6364

65+
// Section Relocation iterators
66+
LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section);
67+
void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef RI);
68+
LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section,
69+
LLVMRelocationIteratorRef RI);
70+
void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI);
71+
72+
6473
// SymbolRef accessors
6574
const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI);
6675
uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);
@@ -99,6 +108,17 @@ namespace llvm {
99108
return reinterpret_cast<LLVMSymbolIteratorRef>
100109
(const_cast<symbol_iterator*>(SI));
101110
}
111+
112+
inline relocation_iterator *unwrap(LLVMRelocationIteratorRef SI) {
113+
return reinterpret_cast<relocation_iterator*>(SI);
114+
}
115+
116+
inline LLVMRelocationIteratorRef
117+
wrap(const relocation_iterator *SI) {
118+
return reinterpret_cast<LLVMRelocationIteratorRef>
119+
(const_cast<relocation_iterator*>(SI));
120+
}
121+
102122
}
103123
}
104124

llvm/lib/Object/Object.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,29 @@ LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,
112112
return ret;
113113
}
114114

115+
// Section Relocation iterators
116+
LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section) {
117+
relocation_iterator SI = (*unwrap(Section))->begin_relocations();
118+
return wrap(new relocation_iterator(SI));
119+
}
120+
121+
void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef SI) {
122+
delete unwrap(SI);
123+
}
124+
125+
LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section,
126+
LLVMRelocationIteratorRef SI) {
127+
return (*unwrap(SI) == (*unwrap(Section))->end_relocations()) ? 1 : 0;
128+
}
129+
130+
void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef SI) {
131+
error_code ec;
132+
unwrap(SI)->increment(ec);
133+
if (ec) report_fatal_error("LLVMMoveToNextRelocation failed: " +
134+
ec.message());
135+
}
136+
137+
115138
// SymbolRef accessors
116139
const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) {
117140
StringRef ret;

0 commit comments

Comments
 (0)