[PATCH] D77704: [LTO][gold] Add support for loading pass plugins

Dominic Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 8 23:12:57 PDT 2020


ddcc added a comment.

Sure. I've written some local optimizations in a loadable pass that uses one of the LTO extension points, `EP_FullLinkTimeOptimizationEarly`, but it seems that there's no way to actually load out-of-tree LTO passes into gold. This patch fixes that by modifying the gold plugin to support two additional arguments for loading external passes with the old/new pass manager, though I've only tested it with my local legacy pass.

However, I wasn't able to successfully load my pass until I rebuilt my local Clang/LLVM with `LLVM_LINK_LLVM_DYLIB` so that everything is dynamically linked to `libLLVM.so`. Otherwise, when both the loadable pass and the LLVM gold plugin are built statically, everything is initialized twice, which leads to an error at runtime about duplicate argument registration. Alternatively, when the loadable pass is built dynamically without an explicit dependency on `libLLVM.so`, it wasn't able to reuse the LLVM symbols provided by a statically-linked LLVM gold plugin that is already loaded, because gold doesn't call `dlopen` with `RTLD_GLOBAL` when it is loading gold plugins, and the LLVM gold plugin has a `LLVM_EXPORTED_SYMBOL_FILE` that restricts exported symbols. Furthermore, loadable passes can depend on other components of LLVM, e.g. my pass uses the Demangler, which isn't linked into the LLVM gold plugin anyway. I'm not too familiar with pass registration and this part of the LLVM codebase, so perhaps there's a better way to get things working.

Edit: lld might have a similar problem, but I didn't look into it since my local toolchain is only using gold.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77704





More information about the llvm-commits mailing list