When faced with command line options such as "crtbegin.o appmain.o -lsomelib crtend.o", GNU ld pulls in all necessary object files from somelib before proceeding to crtend.o.
LLD operates differently, only loading object files from any referenced static libraries after processing all input object files.
This uses a similar hack as in the ELF linker. Here, it moves crtend.o to the end of the vector of object files. This makes sure that terminator chunks for sections such as .eh_frame gets ordered last, fixing DWARF exception handling for libgcc and gcc's crtend.o.
I copied the function for identifying the crtend object file from the ELF linker - should that maybe be moved to some shared file?