[Lldb-commits] [PATCH] D147627: [lldb][ObjectFileELF] Improve error output for unsupported arch/relocations
Stefan Gränitz via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Wed Apr 5 09:23:03 PDT 2023
sgraenitz created this revision.
sgraenitz added reviewers: DavidSpickett, SixWeining.
Herald added a subscriber: emaste.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: LLDB.
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).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D147627
Files:
lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -2666,38 +2666,48 @@
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_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 +2753,8 @@
}
break;
default:
- assert(false && "unsupported machine");
+ GetModule()->ReportError("unsupported 64-bit ELF machine arch: {0}", hdr->e_machine);
+ break;
}
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147627.511127.patch
Type: text/x-patch
Size: 3677 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230405/8df6d134/attachment.bin>
More information about the lldb-commits
mailing list