0

static_initializers.md: Improve "Manual Verification" docs

Change-Id: I75325594beb814b78dd0af3f8757e3b6ee90e276
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3557791
Reviewed-by: Adenilson Cavalcanti <cavalcantii@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/main@{#995012}
This commit is contained in:
Andrew Grieve
2022-04-22 02:00:10 +00:00
committed by Chromium LUCI CQ
parent a1f0e8c1c1
commit 7c58e2e72f

@ -68,24 +68,55 @@ More details in [crbug/1136086](https://bugs.chromium.org/p/chromium/issues/deta
* For more information about `diagnose_bloat.py`, refer to its [README.md](/tools/binary_size/README.md#diagnose_bloat.py)
* List of existing static initializers documented in [static_initializers.gni](/chrome/android/static_initializers.gni)
### Step 3 - Manual verification
### Step 3 - Manual Verification
If the source of the new initializers is not revealed with
`dump-static-initializers.py` (e.g. for static initializers introduced in
compiler-rt), there's a manual option.
1. Locate the address range of the .init_array section with
`llvm-readelf --hex-dump=.init_array ./lib.unstripped/libmonochrome_64.so`.
It will yield an address range like 0x0917fd40 to 0x0918fd78.
2. Each .init_array slot may be zero if the contents are relocatable. To translate,
use a command like `llvm-readelf --relocations ./lib/unstripped | grep 0x0917fd40`
to obtain a result mapping each .init_array slot to a function address.
1. Locate the address range of the .init_array section with:
```
000000000918fd40 0000000000000403 R_AARCH64_RELATIVE 51732f0
$ third_party/llvm-build/Release+Asserts/bin/llvm-readelf \
--hex-dump=.init_array out/Release/lib.unstripped/libmonochrome.so
Hex dump of section '.init_array':
0x04064624 294a1a02 154acb00 79d3be01 894c1a02 )J...J..y....L..
```
3. Finally, convert the address into a function name with
`llvm-addr2line --functions -e ./lib.unstripped/libmonochrome_64.so 51732f0`
* `0x04064624` is the location of `.init_array`.
* The other four entries are addresses of functions **in little endian**.
2. Convert the address into a function name with:
```
__cxx_global_var_init
./../../buildtools/third_party/libc++/trunk/src/iostream.cpp:80
# Reverse hex pairs to account for endianness.
$ third_party/llvm-build/Release+Asserts/bin/llvm-symbolizer \
--functions -e out/Release/lib.unstripped/libmonochrome.so 0x021a4a29
_GLOBAL__I_000101
./../../buildtools/third_party/libc++/trunk/src/iostream.cpp:0:0
```
3. If any `.init_array` slots are zero, that means they their address is exists
within the relocation table. To find the address:
```
# Use the location of ".init_array" printed in step 1, plus an offset for subsequent slots.
$ third_party/llvm-build/Release+Asserts/bin/llvm-readelf \
--relocations out/Release/lib.unstripped/libmonochrome.so | grep 0x04064624
03dfb7b0 00000017 R_ARM_RELATIVE 0
```
### Step 4 - Compiler Naming Heuristics
You might be able to find the static initialzer functions by listing symbols:
```sh
nm out/Release/lib.unstripped/libmonochrome.so | grep " _GLOBAL__"
```
This currently yields:
```
0214ea45 t _GLOBAL__I_000101
00cb2315 t _GLOBAL__sub_I_base_logging.cc
0214eca5 t _GLOBAL__sub_I_iostream.cpp
01c01219 t _GLOBAL__sub_I_token.cc
```