[ELFLOADER] Initialize the x86-64 PLT resolver before relocation - #4373
Conversation
|
I meeted this issue while debugging the QQ app. A simplified test case is shown below. Support for Build command: gcc -O2 -fno-builtin-strlen -fplt -Wl,-z,lazy test.c -o test |
|
Previously, the PltResolver was injected only when needed, now this is systematic, I don't like that. Also the |
GOT[0] and GOT[1] are initialized only after the `RelocateElfRELA` function
returns. However, `GOT[0]` and `GOT[1]` may already be required while processing
`R_X86_64_IRELATIVE` inside `RelocateElfRELA`.
This patch always initialize GOT[1] and GOT[2] before processing x86-64 dynamic
relocations, so PLT0 has valid elf header and resolver during IFUNC and IRELATIVE
handling.
Before:
```
|_ RelocateElf64
|_ RelocateElfPlt64
| |_ JUMP_SLOT strlen
| | |_ *need_resolv = 1
│ |_ ifunc resolver
│ | |_ ifunc resolver call strcmp
│ | |_ strcmp call PLT -> GOT[x] not filled -> fallback → PLT[0]
│ | |_ PLT[0]: push [GOT[1]] = 0
│ | jmp [GOT[2]] = 0
| | |_ ERROR
| |_ SeedPltResolver64: GOT[1] = head, GOT[2] = pltResolver64
```
After:
```
|_ RelocateElf64
| |_ SeedPltResolver64: GOT[1] = head, GOT[2] = pltResolver64
|_ RelocateElfPlt64
│ |_ ifunc resolver
│ |_ ifunc resolver call strcmp
│ |_ strcmp call PLT -> GOT[x] not filled -> fallback → PLT[0]
│ |_ PLT[0]: push [GOT[1]] = head
│ jmp [GOT[2]] = pltResolver64
```
I removed the useless parameter. I think if the GOT[0] and GOT[1] are initialized only upon first need, every time we hit a From the perspective of the |
|
Ok, LGTM |
GOT[0] and GOT[1] are initialized only after the
RelocateElfRELAfunction returns. However,GOT[0]andGOT[1]may already be required while processingR_X86_64_IRELATIVEinsideRelocateElfRELA.This patch always initialize GOT[1] and GOT[2] before processing x86-64 dynamic relocations, so PLT0 has valid elf header and resolver during IFUNC and IRELATIVE handling.
Before:
After: