Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 819f1311 authored by Christopher Ferris's avatar Christopher Ferris
Browse files

Handle when bias is different in elf headers.

The original code assumed that the load bias in the program headers
would be exactly the same as in eh_frame/eh_frame_hdr/debug_frame.

This isn't guaranteed, so add a section bias for use when creating
a DwarfSection. In addtion, make the load bias and section bias
a signed value. There is no reason that this value needs to be positive,
so don't force it to be.

Add a new offline test that has a different load bias in eh_frame than
in the executable load.

Add additional unit tests to verify the load bias values are set properly.

Clean up the tests in ElfInterfaceTest, making all tests names follow the
same convention.

Bug: 141888859
Bug: 142094469

Test: New units and old unit tests pass on host and taimen.
Change-Id: Ib878123ab5545f0f315c749cfe0d27b012d873ee
parent 6c1668d6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -245,6 +245,7 @@ cc_defaults {
        "tests/files/offline/jit_debug_x86/*",
        "tests/files/offline/jit_map_arm/*",
        "tests/files/offline/gnu_debugdata_arm/*",
        "tests/files/offline/load_bias_different_section_bias_arm64/*",
        "tests/files/offline/load_bias_ro_rx_x86_64/*",
        "tests/files/offline/offset_arm/*",
        "tests/files/offline/shared_lib_in_apk_arm64/*",
+3 −3
Original line number Diff line number Diff line
@@ -32,8 +32,8 @@ static inline bool IsEncodingRelative(uint8_t encoding) {
}

template <typename AddressType>
bool DwarfEhFrameWithHdr<AddressType>::Init(uint64_t offset, uint64_t size, uint64_t load_bias) {
  load_bias_ = load_bias;
bool DwarfEhFrameWithHdr<AddressType>::Init(uint64_t offset, uint64_t size, int64_t section_bias) {
  section_bias_ = section_bias;

  memory_.clear_func_offset();
  memory_.clear_text_offset();
@@ -138,7 +138,7 @@ DwarfEhFrameWithHdr<AddressType>::GetFdeInfoFromIndex(size_t index) {

  // Relative encodings require adding in the load bias.
  if (IsEncodingRelative(table_encoding_)) {
    value += load_bias_;
    value += section_bias_;
  }
  info->pc = value;
  return info;
+2 −2
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ class DwarfEhFrameWithHdr : public DwarfSectionImpl<AddressType> {
  using DwarfSectionImpl<AddressType>::entries_offset_;
  using DwarfSectionImpl<AddressType>::entries_end_;
  using DwarfSectionImpl<AddressType>::last_error_;
  using DwarfSectionImpl<AddressType>::load_bias_;
  using DwarfSectionImpl<AddressType>::section_bias_;

  struct FdeInfo {
    AddressType pc;
@@ -61,7 +61,7 @@ class DwarfEhFrameWithHdr : public DwarfSectionImpl<AddressType> {
    return pc + this->memory_.cur_offset() - 4;
  }

  bool Init(uint64_t offset, uint64_t size, uint64_t load_bias) override;
  bool Init(uint64_t offset, uint64_t size, int64_t section_bias) override;

  const DwarfFde* GetFdeFromPc(uint64_t pc) override;

+1 −1
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ bool DwarfMemory::AdjustEncodedValue(uint8_t encoding, uint64_t* value) {
      // Nothing to do.
      break;
    case DW_EH_PE_pcrel:
      if (pc_offset_ == static_cast<uint64_t>(-1)) {
      if (pc_offset_ == INT64_MAX) {
        // Unsupported encoding.
        return false;
      }
+4 −3
Original line number Diff line number Diff line
@@ -333,7 +333,7 @@ bool DwarfSectionImpl<AddressType>::FillInFde(DwarfFde* fde) {
  memory_.set_cur_offset(cur_offset);

  // The load bias only applies to the start.
  memory_.set_pc_offset(load_bias_);
  memory_.set_pc_offset(section_bias_);
  bool valid = memory_.ReadEncodedValue<AddressType>(cie->fde_address_encoding, &fde->pc_start);
  fde->pc_start = AdjustPcFromFde(fde->pc_start);

@@ -591,8 +591,9 @@ bool DwarfSectionImpl<AddressType>::Log(uint8_t indent, uint64_t pc, const Dwarf
}

template <typename AddressType>
bool DwarfSectionImplNoHdr<AddressType>::Init(uint64_t offset, uint64_t size, uint64_t load_bias) {
  load_bias_ = load_bias;
bool DwarfSectionImplNoHdr<AddressType>::Init(uint64_t offset, uint64_t size,
                                              int64_t section_bias) {
  section_bias_ = section_bias;
  entries_offset_ = offset;
  next_entries_offset_ = offset;
  entries_end_ = offset + size;
Loading