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

Unified Diff: tools/relocation_packer/README.TXT

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/README.TXT
diff --git a/tools/relocation_packer/README.TXT b/tools/relocation_packer/README.TXT
index a81170abc0ca1ed7c8fbd1ed78e1dec5204a9d0a..acc0e4719f84229ac47d08febf00f644e150c3d2 100644
--- a/tools/relocation_packer/README.TXT
+++ b/tools/relocation_packer/README.TXT
@@ -1,12 +1,13 @@
Introduction:
-------------
-R_ARM_RELATIVE relocations are the bulk of dynamic relocations (the .rel.dyn
-section) in libchrome.<version>.so. The ELF standard representation of them
-is wasteful.
+Relative relocations are the bulk of dynamic relocations (the .rel.dyn
+or .rela.dyn sections) in libchrome.<version>.so. The ELF standard
+representation of them is wasteful.
-Packing uses run length encoding to store them more efficiently. Packed
-relocations are placed in a new .android.rel.dyn section. Packing reduces
+Packing uses combinations of run length encoding, delta encoding, and LEB128
rmcilroy 2014/07/28 10:08:44 nit - s/combinations/a combination
simonb (inactive) 2014/07/28 12:20:56 Done.
+encoding to store them more efficiently. Packed relocations are placed in
+a new .android.rel.dyn or .android.rela.dyn section. Packing reduces
the footprint of libchrome.<version>.so in the filesystem, in APK downloads,
and in memory when loaded on the device.
@@ -29,24 +30,36 @@ can be packed and will run, but may no longer be useful for debugging.
Unpacking on the device requires the explicit support of an extended crazy
linker. Adds the following new .dynamic tags, used by the crazy linker to
-find the packed .android.rel.dyn section data:
+find the packed .android.rel.dyn or .android.rela.dyn section data:
DT_ANDROID_ARM_REL_OFFSET = DT_LOPROC (Processor specific: 0x70000000)
rmcilroy 2014/07/28 10:08:44 /s/DT_ANDROID_ARM_REL_OFFSET/DT_ANDROID_REL_OFFSET
simonb (inactive) 2014/07/28 12:20:55 Updated in patch set 4 (you're commenting here on
- - The offset of .android.rel.dyn data in libchrome.<version>.so
+ - The offset of packed relocation data in libchrome.<version>.so
DT_ANDROID_ARM_REL_SIZE = DT_LOPROC + 1 (Processor Specific: 0x70000001)
- - The size of .android.rel.dyn data in bytes
+ - The size of packed relocation data in bytes
-The format of .android.rel.dyn data is:
+32 bit ARM libraries use relocations without addends. 64 bit ARM libraries
+use relocations with addends. The packing strategy necessarily differs for
+the two relocation types.
+
+Where libchrome.<version>.so contains relocations without addends, the format
+of .android.rel.dyn data is:
"APR1" identifier
N: the number of count-delta pairs in the encoding
A: the initial offset
N * C,D: N count-delta pairs
+Where libchrome.<version>.so contains relocations with addends, the format
+of .android.rela.dyn data is:
+
+ "APA1" identifier
+ N: the number of addr-addend delta pairs in the encoding
+ N * A,V: N addr-addend delta pairs
+
All numbers in the encoding stream are stored as LEB128 values. For details
see http://en.wikipedia.org/wiki/LEB128.
-The streaming unpacking algorithm is:
+The streaming unpacking algorithm for 32 bit ARM is:
skip over "APR1"
pairs, addr = next leb128 value, next leb128 value
@@ -59,16 +72,34 @@ The streaming unpacking algorithm is:
count--
pairs--;
+The streaming unpacking algorithm for 64 bit ARM is:
+
+ skip over "APA1"
+ pairs = next signed leb128 value
+ addr, addend = 0, 0
+ while pairs:
+ addr += next signed leb128 value
+ addend += next signed leb128 value
+ emit R_ARM_RELATIVE relocation with r_offset = addr, r_addend = addend
rmcilroy 2014/07/28 10:08:44 R_AARCH64_RELATIVE
simonb (inactive) 2014/07/28 12:20:55 Done. Good catch, thanks.
+ pairs--;
+
Usage instructions:
-------------------
-To pack relocations, add an empty .android.rel.dyn and then run the tool:
+To pack relocations, add an empty .android.rel.dyn or .android.rela.dyn and
+then run the tool:
echo -n 'NULL' >/tmp/small
- arm-linux-gnueabi-objcopy \
- --add-section .android.rel.dyn=/tmp/small \
- libchrome.<version>.so libchrome.<version>.so.packed
+ if file libchrome.<version>.so | grep -q 'ELF 32'; then
+ arm-linux-androideabi-objcopy
+ --add-section .android.rel.dyn=/tmp/small
+ libchrome.<version>.so libchrome.<version>.so.packed
+ else
+ aarch64-linux-android-objcopy
+ --add-section .android.rela.dyn=/tmp/small
+ libchrome.<version>.so libchrome.<version>.so.packed
+ fi
rm /tmp/small
relocation_packer libchrome.<version>.so.packed
@@ -76,19 +107,21 @@ To unpack and restore the shared library to its original state:
cp libchrome.<version>.so.packed unpackable
relocation_packer -u unpackable
- arm-linux-gnueabi-objcopy \
- --remove-section=.android.rel.dyn unpackable libchrome.<version>.so
+ if file libchrome.<version>.so | grep -q 'ELF 32'; then
+ arm-linux-androideabi-objcopy \
+ --remove-section=.android.rel.dyn unpackable libchrome.<version>.so
+ else
+ aarch64-linux-android-objcopy \
+ --remove-section=.android.rela.dyn unpackable libchrome.<version>.so
+ endif
rm unpackable
Bugs & TODOs:
-------------
-Currently only supports arm32. Support for arm64 requires some extension
-and modification.
-
Requires two free slots in the .dynamic section. Uses these to add data that
-tells the crazy linker where to find the packed .android.rel.dyn data. Fails
+tells the crazy linker where to find the packed relocation data. Fails
if insufficient free slots exist (use gold --spare-dynamic-slots to increase
the allocation).
« no previous file with comments | « no previous file | tools/relocation_packer/relocation_packer.gyp » ('j') | tools/relocation_packer/src/delta_encoder.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698