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

Side by Side Diff: tools/relocation_packer/README.TXT

Issue 310483003: Add a host tool to pack R_ARM_RELATIVE relocations in libchrome.<ver>.so. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 Introduction:
2 -------------
3
4 R_ARM_RELATIVE relocations are the bulk of dynamic relocations (the .rel.dyn
5 section) in libchrome.<version>.so. The ELF standard representation of them
6 is wasteful.
7
8 Packing uses run length encoding to store them more efficiently. Packed
9 relocations are placed in a new .android.rel.dyn section. Packing reduces
rmcilroy 2014/06/02 15:16:35 Would it be safer to put this in a section called
simonb (inactive) 2014/06/04 16:40:35 The idea (or at least the hope) is that this will
rmcilroy 2014/06/07 11:49:06 Should be fine as is.
simonb (inactive) 2014/06/09 14:39:19 Okay.
10 the footprint of libchrome.<version>.so in the filesystem, in APK downloads,
11 and in memory when loaded on the device.
rmcilroy 2014/06/02 15:16:35 "in memory when loaded on the device" - is this tr
simonb (inactive) 2014/06/04 16:40:35 This should be true. The current relocations are
12
13 A packed libchrome.<version>.so is designed so that it can be loaded directly
14 on Android, but requires the explicit support of a crazy linker that has been
15 extended to understand packed relocations.
rmcilroy 2014/06/02 15:16:35 nit - mention there is only Arm support currently
simonb (inactive) 2014/06/04 16:40:35 Done.
16
17 A packed libchrome.<version>.so cannot currently be used with the standard
18 Android runtime linker.
19
20 See src/*.h for design and implementation notes.
21
22
23 Notes:
24 ------
25
26 Packing does not adjust debug data. An unstripped libchrome.<version>.so
27 can be packed and will run, but may no longer be useful for debugging.
28
29 Requires the explicit support of an extended crazy linker. Adds the
rmcilroy 2014/06/02 15:16:35 nit - Unpacking requires the...
simonb (inactive) 2014/06/04 16:40:35 Done.
30 following new .dynamic tags, used by the crazy linker to find the packed
31 .android.rel.dyn section data:
32
33 DT_ANDROID_ARM_REL_OFFSET = DT_LOPROC (Processor specific: 0x70000000)
34 - The offset of .android.rel.dyn data in libchrome.<version>.so
35 DT_ANDROID_ARM_REL_SIZE = DT_LOPROC + 1 (Processor Specific: 0x70000001)
36 - The size of .android.rel.dyn data in bytes
37
38 The format of .android.rel.dyn data is:
39
40 "APR1" identifier
41 N: the number of count-delta pairs in the encoding
42 A: the initial offset
43 N * C,D: N count-delta pairs
44
45 All numbers in the encoding stream are stored as LEB128 values. For details
46 see http://en.wikipedia.org/wiki/LEB128.
47
48 The streaming unpacking algorithm is:
49
50 skip over "APR1"
51 pairs, addr = next leb128 value, next leb128 value
52 emit R_ARM_RELATIVE relocation with r_offset = addr
53 while pairs:
54 count, delta = next leb128 value, next leb128 value
55 while count:
56 addr += delta
57 emit R_ARM_RELATIVE relocation with r_offset = addr
58 count--
59 pairs--;
60
61
62 Usage instructions:
63 -------------------
64
65 To pack relocations, add an empty .android.rel.dyn and then run the tool:
66
67 echo -n 'NULL' >/tmp/small
68 arm-linux-gnueabi-objcopy \
69 --add-section .android.rel.dyn=/tmp/small \
70 libchrome.<version>.so libchrome.<version>.so.packed
71 rm /tmp/small
72 pack-relocations libchrome.<version>.so.packed
rmcilroy 2014/06/02 15:16:35 Could the tool do the adding and removing of secti
simonb (inactive) 2014/06/04 16:40:35 It's icky work that it is better to avoid. Adding
73
74 To unpack and restore the shared library to its original state:
75
76 cp libchrome.<version>.so.packed unpackable
77 pack-relocations -u unpackable
rmcilroy 2014/06/02 15:16:35 From the gyp file, looks like the executable is "r
simonb (inactive) 2014/06/04 16:40:35 Done. (Resulted from a last-minute change to the
rmcilroy 2014/06/07 11:49:06 relocation_packer (not relocations_packer) ;)
simonb (inactive) 2014/06/09 14:39:19 Done.
78 arm-linux-gnueabi-objcopy \
79 --remove-section=.android.rel.dyn unpackable libchrome.<version>.so
80 rm unpackable
81
82
83 Bugs & TODOs:
84 -------------
85
86 Currently only supports arm32. Support for arm64 requires some extension
87 and modification.
88
89 Expects to find at least two free slots in the .dynamic section. Uses
90 these to add data that tells the crazy linker where to find the packed
91 .android.rel.dyn data.
rmcilroy 2014/06/02 15:16:35 What if there are not two free slots? Can we forc
simonb (inactive) 2014/06/04 16:40:35 We can, but... growing the table means resizing it
92
93 Requires libelf 0.158 or later. Earlier libelf releases may be buggy in
94 ways that prevent the packer from working correctly.
95
96
97 Testing:
98 --------
99
100 Unittests run under gtest, on the host system.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698