@@ -46,13 +46,26 @@ const coff_section* get_coff_section(const coff_obj &obj, const SectionRef &sec)
4646error_or<int > section_number (const coff_obj &obj, const SymbolRef &sym);
4747error_or<uint64_t > symbol_value (const coff_obj &obj, const SymbolRef &sym);
4848
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
4959const coff_section * get_coff_section (const coff_obj &obj, std::size_t index) {
5060 const coff_section *sec = nullptr ;
5161 bool fail = (index == COFF::IMAGE_SYM_UNDEFINED) || obj.getSection (index, sec);
5262 if (fail) return nullptr ;
5363 else return sec;
5464}
5565
66+ #endif
67+
68+
5669void emit_base_address (const coff_obj &obj, ogre_doc &s) {
5770 s.entry (" llvm:base-address" ) << obj.getImageBase ();
5871}
@@ -132,6 +145,17 @@ void emit_sections(const coff_obj &obj, ogre_doc &s) {
132145 emit_section (*get_coff_section (obj, sec), base, is_rel, s);
133146}
134147
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+
135159void emit_symbols (const coff_obj &obj, ogre_doc &s) {
136160 for (auto sized_sym : prim::get_symbols_sizes (obj)) {
137161 auto sym = sized_sym.first ;
@@ -144,7 +168,7 @@ void emit_symbols(const coff_obj &obj, ogre_doc &s) {
144168 << *addr
145169 << sized_sym.second
146170 << *offs
147- << sym. getValue ( );
171+ << get_symbol_value (sym );
148172 if (*type == SymbolRef::ST_Function)
149173 s.entry (" llvm:code-entry" ) << *name << *offs << sized_sym.second ;
150174 }
@@ -238,12 +262,26 @@ void emit_exported_symbols(const coff_obj &obj, exports &syms, ogre_doc &s) {
238262 }
239263}
240264
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+
241280void emit_exported_symbols (const coff_obj &obj, ogre_doc &s) {
242281
243- const data_directory *data_entry;
244282 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 ;
247285 uint32_t export_table_rva = data_entry->RelativeVirtualAddress ;
248286 if (!export_table_rva) return ;
249287 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)
295333 num == COFF::IMAGE_SYM_DEBUG)
296334 return success (coff_sym.getValue ());
297335
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" );
301342 }
302- uint64_t off = coff_sec->PointerToRawData + coff_sym.getValue ();
303- return success (off);
304343}
305344} // namespace coff_loader
306345
0 commit comments