@@ -46,13 +46,26 @@ const coff_section* get_coff_section(const coff_obj &obj, const SectionRef &sec)
46
46
error_or<int > section_number (const coff_obj &obj, const SymbolRef &sym);
47
47
error_or<uint64_t > symbol_value (const coff_obj &obj, const SymbolRef &sym);
48
48
49
+ #if LLVM_VERSION_MAJOR >= 11
50
+ const coff_section * get_coff_section (const coff_obj &obj, std::size_t index) {
51
+ if (index != COFF::IMAGE_SYM_UNDEFINED) {
52
+ auto sec = obj.getSection (index);
53
+ return sec ? *sec : nullptr ;
54
+ } else {
55
+ return nullptr ;
56
+ }
57
+ }
58
+ #else
49
59
const coff_section * get_coff_section (const coff_obj &obj, std::size_t index) {
50
60
const coff_section *sec = nullptr ;
51
61
bool fail = (index == COFF::IMAGE_SYM_UNDEFINED) || obj.getSection (index, sec);
52
62
if (fail) return nullptr ;
53
63
else return sec;
54
64
}
55
65
66
+ #endif
67
+
68
+
56
69
void emit_base_address (const coff_obj &obj, ogre_doc &s) {
57
70
s.entry (" llvm:base-address" ) << obj.getImageBase ();
58
71
}
@@ -132,6 +145,17 @@ void emit_sections(const coff_obj &obj, ogre_doc &s) {
132
145
emit_section (*get_coff_section (obj, sec), base, is_rel, s);
133
146
}
134
147
148
+ #if LLVM_VERSION_MAJOR >= 11
149
+ uint64_t get_symbol_value (const SymbolRef &sym) {
150
+ auto value = sym.getValue ();
151
+ return value ? *value : 0 ;
152
+ }
153
+ #else
154
+ uint64_t get_symbol_value (const SymbolRef &sym) {
155
+ return sym.getValue ();
156
+ }
157
+ #endif
158
+
135
159
void emit_symbols (const coff_obj &obj, ogre_doc &s) {
136
160
for (auto sized_sym : prim::get_symbols_sizes (obj)) {
137
161
auto sym = sized_sym.first ;
@@ -144,7 +168,7 @@ void emit_symbols(const coff_obj &obj, ogre_doc &s) {
144
168
<< *addr
145
169
<< sized_sym.second
146
170
<< *offs
147
- << sym. getValue ( );
171
+ << get_symbol_value (sym );
148
172
if (*type == SymbolRef::ST_Function)
149
173
s.entry (" llvm:code-entry" ) << *name << *offs << sized_sym.second ;
150
174
}
@@ -238,12 +262,26 @@ void emit_exported_symbols(const coff_obj &obj, exports &syms, ogre_doc &s) {
238
262
}
239
263
}
240
264
265
+ #if LLVM_VERSION_MAJOR >= 11
266
+ const data_directory *get_export_table (const coff_obj &obj) {
267
+ return obj.getDataDirectory (COFF::EXPORT_TABLE);
268
+ }
269
+ #else
270
+ const data_directory *get_export_table (const coff_obj &obj) {
271
+ const data_directory *data_entry;
272
+ if (obj.getDataDirectory (COFF::EXPORT_TABLE, data_entry)) {
273
+ return nullptr ;
274
+ } else {
275
+ return data_entry;
276
+ }
277
+ }
278
+ #endif // llvm >= 11
279
+
241
280
void emit_exported_symbols (const coff_obj &obj, ogre_doc &s) {
242
281
243
- const data_directory *data_entry;
244
282
uintptr_t ptr = 0 ;
245
-
246
- if (obj. getDataDirectory (COFF::EXPORT_TABLE, data_entry) ) return ;
283
+ const data_directory *data_entry = get_export_table (obj);
284
+ if (! data_entry) return ;
247
285
uint32_t export_table_rva = data_entry->RelativeVirtualAddress ;
248
286
if (!export_table_rva) return ;
249
287
if (obj.getRvaPtr (export_table_rva, ptr)) return ;
@@ -295,12 +333,13 @@ error_or<uint64_t> symbol_file_offset(const coff_obj &obj, const SymbolRef &sym)
295
333
num == COFF::IMAGE_SYM_DEBUG)
296
334
return success (coff_sym.getValue ());
297
335
298
- const coff_section *coff_sec;
299
- if (auto er = obj.getSection (num, coff_sec)) {
300
- return failure (er.message ());
336
+ const coff_section *coff_sec = get_coff_section (obj, num);
337
+ if (coff_sec) {
338
+ uint64_t off = coff_sec->PointerToRawData + coff_sym.getValue ();
339
+ return success (off);
340
+ } else {
341
+ return failure (" failed to get the section" );
301
342
}
302
- uint64_t off = coff_sec->PointerToRawData + coff_sym.getValue ();
303
- return success (off);
304
343
}
305
344
} // namespace coff_loader
306
345
0 commit comments