This is still work in progress.
Compared to D102304, this implementation does not invoke lldMain twice. Instead, it tries to record the file names when lld touches any file and repackage them when lld recovered from CrashRecoveryContext. In test it generate the same reproducer tarball when compared to D102304.
The change still need more work. It currently require environment variable to make lld to invoke safeLldMain (ideally, lld should use safeLldMain when "--reproduce-on-crash") and the path of the crash reproducer can be customized. Let me know if this is the direction we want to go.
Do this check before instantiating the option parser which is a potentially expensive operation.