13090e1790da7e04c33a7d795a4f144306549b2a
explain/rtld.md
... | ... | @@ -97,3 +97,25 @@ read the hashtables. |
97 | 97 | |
98 | 98 | Smol uses these two tricks to achieve an even smaller binary size. |
99 | 99 | |
100 | +### ARM |
|
101 | + |
|
102 | +Most of the tricks presented here don't depend on the processor architecture. |
|
103 | +Getting hold of the `link_map`, however, needs yet another hack to get it to work. |
|
104 | + |
|
105 | +[glibc does the following](https://code.woboq.org/userspace/glibc/sysdeps/arm/dl-machine.h.html#153): |
|
106 | + |
|
107 | + @ call internal init stuff w/ link_map pointer |
|
108 | + ldr r0, .L_LOADED |
|
109 | + ldr r0, [sl, r0] |
|
110 | + bl _dl_init(PLT) |
|
111 | + |
|
112 | + @ load _dl_fini, jump to entrypoint |
|
113 | + ldr r0, .L_FINI_PROC |
|
114 | + add r0, sl, r0 |
|
115 | + mov pc, r6 |
|
116 | + |
|
117 | +This has a few problems: |
|
118 | +* `r0` (containing the `link_map` struct) always gets overwritten |
|
119 | +* The return address is saved to `lr` instead of being written to the stack. This means we can't use the stack trick as in x86_64 |
|
120 | + |
|
121 | +The only useful thing that gets passed to our entrypoint is the `sl` register. The address to `.L_LOADED` would still be needed, though. |