[PATCH] D147544: [BOLT] Move from RuntimeDyld to JITLink

Rafael Auler via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 5 08:54:29 PDT 2023


rafauler added a comment.

> My assessment might be a bit off, though, and maybe there are good reasons for BOLT to use a JIT linker. I'd be very interested in hearing the opinions of the BOLT devs on this.

I agree, I'll speak for myself, maybe later Maksim can give his view, since he originally wrote the code that uses RuntimeDyld (he's on vacation at the moment). I don't think lld was written to be (easily) used as library. The way to communicate with lld would be writing stuff to disk / abusing linker scripts/ trying to do all sorts of hacks to make the linker stop doing linker stuff. I'll try to make myself more clear below.

The reason BOLT used RuntimeDyld is because final linking already took place in the binary, and BOLT just needed to patch a few references without doing any other classic linker jobs, and RuntimeDyld was a simple component that provided exactly that with few changes (such as mapping sections to the addresses seen in the input binary, instead of mapping them to a random page of JIT memory). BOLT would never require generating PLT tables, for example, because this is already done in the input. The only feature that BOLT requires from the linker is actually patching the relocations to addresses from the BOLT symbol table. It does NOT need to:   combine multiple sections into one, generate extra code, generate extra data structures, understand ELF symbol versioning, consider weak symbols, generate TLS/GOT/etc.

Given this unique use case to just run a tiny bit of the functionality of a linker, which is precisely a for loop going through all relocations and patching them, it was way easier to just use RuntimeDyld as directly as possible. We actually considered just writing this code to patch relocations inside BOLT, but it seemed silly to duplicate code already written in RuntimeDyld.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147544/new/

https://reviews.llvm.org/D147544



More information about the llvm-commits mailing list