Fixes: https://github.com/llvm/llvm-project/issues/59874
Initially after the first invocation of the linker() the symbol table is not cleared and this causes issues with the second invocation when linking a new shared library due to a conflict in the presence of a previously existing _DYNAMIC symbol tripping a runtime assertion.
The linker already had a cleanup lambda registered in an error handler. This patch just declares that lambda up front, and calls it before registering in the error handler. This way the linker can be called multiple times. This is necessary when JIT-ing e.g. AMDGCN kernels.