It was easy to hang LLD when INCLUDE command including the same file.
Documentation says that nesting up to 10 levels is allowed:
INCLUDE filename
Include the linker script filename at this point. The file will be searched for in
the current directory, and in any directory specified with the ‘-L’ option. You
can nest calls to INCLUDE up to 10 levels deep.
Patch stores nesting level for each MemoryBufferRef we create,
so it is possible to error out when limit of 10 levels is reached.
getCurrentMB() is now returning <MemoryBuffer, depth> pair. In each of the cases where it is called only one of the two fields of the pair is used. Would it be better to have getCurrentMB() return first, and add a new function getCurrentMBDepth() that returns the second. That should allow the .firsts and .second from the calling code.