aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
diff options
context:
space:
mode:
authorStefan Gränitz <stefan.graenitz@gmail.com>2023-04-13 14:21:20 +0200
committerStefan Gränitz <stefan.graenitz@gmail.com>2023-04-13 14:32:15 +0200
commitcc6ab268d89b27723f62517a07e86df85e999c89 (patch)
tree991fd09c07a590bcd71a137883405519f1192b84 /lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
parentdf3f1e2f31300f95845c39a76a45c95dab64cd12 (diff)
downloadllvm-cc6ab268d89b27723f62517a07e86df85e999c89.zip
llvm-cc6ab268d89b27723f62517a07e86df85e999c89.tar.gz
llvm-cc6ab268d89b27723f62517a07e86df85e999c89.tar.bz2
[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
Diffstat (limited to 'lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp')
-rw-r--r--lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp66
1 files changed, 39 insertions, 27 deletions
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 5b75738..0c39a4f 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;
}
}
}