Author: Stefan Gränitz Date: 2023-04-13T14:32:15+02:00 New Revision: cc6ab268d89b27723f62517a07e86df85e999c89
URL: https://github.com/llvm/llvm-project/commit/cc6ab268d89b27723f62517a07e86df85e999c89 DIFF: https://github.com/llvm/llvm-project/commit/cc6ab268d89b27723f62517a07e86df85e999c89.diff LOG: [lldb][ObjectFileELF] Improve error output for unsupported arch/relocations ObjectFileELF::ApplyRelocations() considered all 32-bit input objects to be i386 and didn't provide good error messages for AArch32 objects. Please find an example in https://github.com/llvm/llvm-project/issues/61948 While we are here, let' improve the situation for unsupported architectures as well. I think we should report the error here too and not silently fail (or crash with assertions enabled). Reviewed By: SixWeining Differential Revision: https://reviews.llvm.org/D147627 Added: Modified: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Removed: ################################################################################ diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index 5b75738e070c3..0c39a4f68e878 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -2666,38 +2666,49 @@ unsigned ObjectFileELF::ApplyRelocations( Symbol *symbol = nullptr; if (hdr->Is32Bit()) { - switch (reloc_type(rel)) { - case R_386_32: - symbol = symtab->FindSymbolByID(reloc_symbol(rel)); - if (symbol) { - addr_t f_offset = - rel_section->GetFileOffset() + ELFRelocation::RelocOffset32(rel); - DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer(); - // ObjectFileELF creates a WritableDataBuffer in CreateInstance. - WritableDataBuffer *data_buffer = - llvm::cast<WritableDataBuffer>(data_buffer_sp.get()); - uint32_t *dst = reinterpret_cast<uint32_t *>( - data_buffer->GetBytes() + f_offset); - - addr_t value = symbol->GetAddressRef().GetFileAddress(); - if (rel.IsRela()) { - value += ELFRelocation::RelocAddend32(rel); + switch (hdr->e_machine) { + case llvm::ELF::EM_386: + switch (reloc_type(rel)) { + case R_386_32: + symbol = symtab->FindSymbolByID(reloc_symbol(rel)); + if (symbol) { + addr_t f_offset = + rel_section->GetFileOffset() + ELFRelocation::RelocOffset32(rel); + DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer(); + // ObjectFileELF creates a WritableDataBuffer in CreateInstance. + WritableDataBuffer *data_buffer = + llvm::cast<WritableDataBuffer>(data_buffer_sp.get()); + uint32_t *dst = reinterpret_cast<uint32_t *>( + data_buffer->GetBytes() + f_offset); + + addr_t value = symbol->GetAddressRef().GetFileAddress(); + if (rel.IsRela()) { + value += ELFRelocation::RelocAddend32(rel); + } else { + value += *dst; + } + *dst = value; } else { - value += *dst; + GetModule()->ReportError(".rel{0}[{1}] unknown symbol id: {2:d}", + rel_section->GetName().AsCString(), i, + reloc_symbol(rel)); } - *dst = value; - } else { - GetModule()->ReportError(".rel{0}[{1}] unknown symbol id: {2:d}", + break; + case R_386_NONE: + case R_386_PC32: + GetModule()->ReportError("unsupported i386 relocation:" + " .rel{0}[{1}], type {2}", rel_section->GetName().AsCString(), i, - reloc_symbol(rel)); + reloc_type(rel)); + break; + default: + assert(false && "unexpected relocation type"); + break; } break; - case R_386_PC32: default: - GetModule()->ReportError("unsupported 32-bit relocation:" - " .rel{0}[{1}], type {2}", - rel_section->GetName().AsCString(), i, - reloc_type(rel)); + GetModule()->ReportError("unsupported 32-bit ELF machine arch: {0}", hdr->e_machine); + break; } } else { switch (hdr->e_machine) { @@ -2743,7 +2754,8 @@ unsigned ObjectFileELF::ApplyRelocations( } break; default: - assert(false && "unsupported machine"); + GetModule()->ReportError("unsupported 64-bit ELF machine arch: {0}", hdr->e_machine); + break; } } } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits