Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Unified Diff: tools/relocation_packer/src/delta_encoder.h

Issue 410933004: Extend relocation packing to cover arm64. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Script 'golden' test data generation Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/relocation_packer/src/delta_encoder.h
diff --git a/tools/relocation_packer/src/delta_encoder.h b/tools/relocation_packer/src/delta_encoder.h
new file mode 100644
index 0000000000000000000000000000000000000000..9c5a35fc450d2436d00d5a2f047872a4b7c6daf1
--- /dev/null
+++ b/tools/relocation_packer/src/delta_encoder.h
@@ -0,0 +1,79 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Delta encode and decode relative relocations with addends.
+//
+// Relative relocations are the bulk of dynamic relocations (the
+// .rel.dyn or .rela.dyn sections) in libchrome<version>.so, and the ELF
+// standard representation of them is wasteful. .rel.dyn contains
+// relocations without addends, .rela.dyn relocations with addends.
+//
+// A relocation with an addend is 12 bytes on 32 bit platforms and 24 bytes
+// on 64 bit plaforms. It is split into offset, info, and addend fields.
+// Offsets strictly increase, and each is commonly a few bytes different
+// from its predecessor. Addends are less well behaved. The info field is
+// constant. Example, from 'readelf -x4 libchrome.<version>.so' 64 bit:
+//
+// offset info
+// 80949303 00000000 03040000 00000000 ................
+// addend offset
+// fc015b00 00000000 88949303 00000000 ..[.............
+// info addend
+// 03040000 00000000 24025b00 00000000 ........$.[.....
+// offset info
+// 90949303 00000000 03040000 00000000 ................
+// addend offset
+// 3c025b00 00000000 98949303 00000000 <.[.............
+// info addend
+// 03040000 00000000 50025b00 00000000 ........P.[.....
+//
+// The offset strictly increases, but the addend is unpredictable, so run
+// length encoding will not work well with this data. We can however pack
+// with delta encoding. The difference between offsets is small, between
+// addends is sometimes small, four of eight bytes are almost always
rmcilroy 2014/07/28 10:08:44 "small - four of the eight bytes are almost always
simonb (inactive) 2014/07/28 12:20:56 Reworded for clarity.
+// unused, and the info is constant and so can be eliminated.
+//
+// Delta encoding reduces the size of the data modestly, so that the first
+// three relocations above can be represented as:
+//
+// initial offset initial addend offset delta addend delta
+// 00000000 03939480 00000000 005b01fc 00000000 00000008 00000000 00000028
+// offset delta addend delta ...
+// 00000000 00000008 00000000 0000009f
+//
+// The addend delta can be negative as well as positive, but overall the
+// deltas have a much smaller range than the input data. When encoded as
+// signed LEB128 the total data reduction becomes useful.
+
+#ifndef TOOLS_RELOCATION_PACKER_SRC_DELTA_ENCODER_H_
+#define TOOLS_RELOCATION_PACKER_SRC_DELTA_ENCODER_H_
+
+#include <vector>
+
+#include "elf.h"
+#include "elf_traits.h"
+
+namespace relocation_packer {
+
+// A RelocationDeltaCodec packs vectors of relative relocations with
+// addends into more compact forms, and unpacks them to reproduce the
+// pre-packed data.
+class RelocationDeltaCodec {
+ public:
+ // Encode relative relocations with addends into a more compact form.
+ // |relocations| is a vector of relative relocation with addend structs.
+ // |packed| is the vector of packed words into which relocations are packed.
+ static void Encode(const std::vector<ELF::Rela>& relocations,
+ std::vector<ELF::Sxword>* packed);
+
+ // Decode relative relocations with addends from their more compact form.
+ // |packed| is the vector of packed relocations.
+ // |relocations| is a vector of unpacked relative relocations.
+ static void Decode(const std::vector<ELF::Sxword>& packed,
+ std::vector<ELF::Rela>* relocations);
+};
+
+} // namespace relocation_packer
+
+#endif // TOOLS_RELOCATION_PACKER_SRC_DELTA_ENCODER_H_

Powered by Google App Engine
This is Rietveld 408576698