[JITLink][ELF][x86-64] Add support for R_X86_64_GOTPC32 relocation.
authorLang Hames <lhames@gmail.com>
Mon, 17 Apr 2023 01:22:52 +0000 (01:22 +0000)
committerLang Hames <lhames@gmail.com>
Mon, 17 Apr 2023 01:45:01 +0000 (01:45 +0000)
commite4b6e686b70529db2c6424bd4094545836fdcd99
treed39eb3e2a0a223b94d4e0a4c1b284cd0ba64d840
parentb63b77a1e087cd85ce770c3b6e32ffcef5ffaa49
[JITLink][ELF][x86-64] Add support for R_X86_64_GOTPC32 relocation.

Adds support for the R_X86_64_GOTPC32 relocation, which is a 32-bit delta to
the global offset table.

Since the delta to the GOT doesn't actually require any GOT entries to exist
this commit adds an extra fallback path to the getOrCreateGOTSymbol function:
If the symbol is in the extenal symbols list but no entry exists then the
symbol is turned into an absolute symbol pointing to an arbitrary address in
the current graph's allocation (accessing this address via the symbol would be
illegal, but any access should have triggered creation of a GOT entry which
would prevent this fallback path from being taken in the first place).

This commit also updates the llvm-jitlink tool to scrape the addresses of the
absolute symbols in the graph so that the testcase can see the now-absolute
_GLOBAL_OFFSET_TABLE_ symbol.
llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp
llvm/test/ExecutionEngine/JITLink/x86-64/ELF_R_X86_64_GOTPC32.s [new file with mode: 0644]
llvm/tools/llvm-jitlink/llvm-jitlink-elf.cpp