diff options
author | David Srbecky <dsrbecky@google.com> | 2021-04-28 23:10:40 +0100 |
---|---|---|
committer | David Srbecky <dsrbecky@google.com> | 2021-05-06 10:43:05 +0000 |
commit | 2d3354ac96f587e74178dfbf94098f4e7cf96e58 (patch) | |
tree | 5f93811238fb3b6369b7f03e7faa3bb680a1e440 /compiler | |
parent | af30bf7fb48741f126db1b8316afde6d11b1db69 (diff) |
Fix .debug_frame_hdr generation.
Minor fixes (keep the generation still disabled/unused).
Bug: 110133331
Test: art/test.py -b --host
Change-Id: I82a104d36afd68ef3133f345991ab3888bdcdc8e
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/debug/elf_debug_frame_writer.h | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/compiler/debug/elf_debug_frame_writer.h b/compiler/debug/elf_debug_frame_writer.h index f41db07439..094e8871b9 100644 --- a/compiler/debug/elf_debug_frame_writer.h +++ b/compiler/debug/elf_debug_frame_writer.h @@ -150,8 +150,6 @@ static void WriteCIE(InstructionSet isa, /*inout*/ std::vector<uint8_t>* buffer) template<typename ElfTypes> void WriteCFISection(ElfBuilder<ElfTypes>* builder, const ArrayRef<const MethodDebugInfo>& method_infos) { - typedef typename ElfTypes::Addr Elf_Addr; - // The methods can be written in any order. // Let's therefore sort them in the lexicographical order of the opcodes. // This has no effect on its own. However, if the final .debug_frame section is @@ -176,7 +174,8 @@ void WriteCFISection(ElfBuilder<ElfTypes>* builder, }); std::vector<uint32_t> binary_search_table; - if (kWriteDebugFrameHdr) { + bool binary_search_table_is_valid = kWriteDebugFrameHdr; + if (binary_search_table_is_valid) { binary_search_table.reserve(2 * sorted_method_infos.size()); } @@ -192,10 +191,13 @@ void WriteCFISection(ElfBuilder<ElfTypes>* builder, for (const MethodDebugInfo* mi : sorted_method_infos) { DCHECK(!mi->deduped); DCHECK(!mi->cfi.empty()); - const Elf_Addr code_address = mi->code_address + + uint64_t code_address = mi->code_address + (mi->is_code_address_text_relative ? builder->GetText()->GetAddress() : 0); if (kWriteDebugFrameHdr) { - binary_search_table.push_back(dchecked_integral_cast<uint32_t>(code_address)); + // Defensively check that the code address really fits. + DCHECK_LE(code_address, std::numeric_limits<uint32_t>::max()); + binary_search_table_is_valid &= code_address <= std::numeric_limits<uint32_t>::max(); + binary_search_table.push_back(static_cast<uint32_t>(code_address)); binary_search_table.push_back(cfi_section->GetPosition()); } dwarf::WriteFDE(is64bit, @@ -210,7 +212,7 @@ void WriteCFISection(ElfBuilder<ElfTypes>* builder, cfi_section->End(); } - if (kWriteDebugFrameHdr && method_infos.size() > kMinDebugFrameHdrEntries) { + if (binary_search_table_is_valid && method_infos.size() >= kMinDebugFrameHdrEntries) { std::sort(binary_search_table.begin(), binary_search_table.end()); // Custom Android section. It is very similar to the official .eh_frame_hdr format. @@ -225,7 +227,8 @@ void WriteCFISection(ElfBuilder<ElfTypes>* builder, auto* header_section = builder->GetDebugFrameHdr(); header_section->Start(); header_section->WriteFully(header_buffer.data(), header_buffer.size()); - header_section->WriteFully(binary_search_table.data(), binary_search_table.size()); + header_section->WriteFully(binary_search_table.data(), + binary_search_table.size() * sizeof(binary_search_table[0])); header_section->End(); } } |