In the process of migrating from old lld ELF linker to new (previously ELF2) I noticed the interface lost several important features (ordered by importance for my use case):
Detecting errors in the first place. New linker seems to call exit(1) for any error.
Reporting messages to non-stderr outputs. Previously all link functions had a raw_ostream argument so it was possible to delay the error output, aggregate it for multiple linked files, output via a different format, etc.
Linking multiple outputs in parallel (useful for test drivers) in a single process. Not really an interface issue but there are at least two global pointers (Config & Driver) that refer to stack variables and are used in various places in the code.
All of this seems to indicate a departure from the linker being useable as a library. To maintain the previous behavior you’d have to use a linker binary & popen.
Is this a conscious design decision or a temporary limitation?
If it’s a limitation, how would one go about fixing this? I’m not too familiar with the idiomatical error handling in LLVM. Normally in this situation I’d just throw from error() but lld is probably compiled without exceptions. Is ErrorOr the established practice? How does LLVM generally deal with error handling for parsers (like linker script parser) where it’s a lot of mutually recursive functions where every single one can fail?