[PATCH] D142949: [lld] Destroy CommonLinkerContext inside lld::*::link after D108850

Alexandre Ganea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 31 04:45:08 PST 2023


aganea added a comment.

The OP in PR59874 could use `safeLldMain` instead of `lld::elf::link` and that will solve their issue (but `lld.cpp.obj` has to be linked in). With D119049 <https://reviews.llvm.org/D119049> we should probably decide if we want to expose the naked `lld::*::link` functions outside of LLD, or if users should always use `safeLldMain`, or something else.

The reason for //not// allocating `ctx` on the stack is to survive calls to `lld::error()` in LLD-as-lib scenarios. `lld::error()` calls `lld::exitLld()` which calls `llvm::Process::Exit(),` which, if a `llvm::CrashRecoveryContext` exists on the stack, restores the flow back in `lld::safeLldMain`. As soon as `longjmp` jumps back into `safeLldMain`, the stack below it becomes invalid in theory. At that point it is not safe anymore to call `CommonLinkerContext::destroy()`, right? (even if that could work in some implementations).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142949



More information about the llvm-commits mailing list