Relocate DWARF using .oat_patches.
The current solution is to hard-code knowledge of DWARF in the linker.
This works for simple use of DWARF, but breaks as soon as I try to do
anything more complex. Making the linker fully support DWARF would be
non-trivial task and would be essentially rewrite. Using .oat_patches
is much easier solution.
Relocating .debug_* sections required extending .oat_patches to support
more sections than just .text. I have encoded each section as
null-terminated section name followed by ULEB128 deltas.
The ULEB128 encoding shrinks .oat_patches for .text by factor of
about 6 with 64-bit compiler, and factor of 3 with 32-bit compiler.
On the other hand, it grows by the extra .oat_patches for DWARF which
were not present before (if debug symbols are included).
Overall, it is still a clear improvement even with the DWARF patches.
Change-Id: I78ffeda0f8a3da03341995a3b5ef15c954e16e9f
diff --git a/compiler/dwarf/debug_info_entry_writer.h b/compiler/dwarf/debug_info_entry_writer.h
index c0350b6..a2c9f5f 100644
--- a/compiler/dwarf/debug_info_entry_writer.h
+++ b/compiler/dwarf/debug_info_entry_writer.h
@@ -17,6 +17,7 @@
#ifndef ART_COMPILER_DWARF_DEBUG_INFO_ENTRY_WRITER_H_
#define ART_COMPILER_DWARF_DEBUG_INFO_ENTRY_WRITER_H_
+#include <cstdint>
#include <unordered_map>
#include "dwarf.h"
@@ -88,6 +89,7 @@
void WriteAddr(Attribute attrib, uint64_t value) {
AddAbbrevAttribute(attrib, DW_FORM_addr);
+ patch_locations_.push_back(this->data()->size());
if (is64bit_) {
this->PushUint64(value);
} else {
@@ -168,7 +170,11 @@
this->PushUint32(address);
}
- bool is64bit() const { return is64bit_; }
+ bool Is64bit() const { return is64bit_; }
+
+ const std::vector<uintptr_t>& GetPatchLocations() const {
+ return patch_locations_;
+ }
using Writer<Allocator>::data;
@@ -240,6 +246,7 @@
size_t abbrev_code_offset_ = 0; // Location to patch once we know the code.
bool inside_entry_ = false; // Entry ends at first child (if any).
bool has_children = true;
+ std::vector<uintptr_t> patch_locations_;
};
} // namespace dwarf