The allocateHeaders() function is called at the end of assignAddresses(), it decides whether the ELF header and program header table can be allocated to
a PT_LOAD program header. As the function alters state, it prevents assignAddresses() from being called multiple times. This change splits out the call to allocateHeaders() from assignAddresses() this will permit assignAddresses() to be called while processing range extension thunks without trying to allocateHeaders().
This change on its own is insufficient to allow assignAddresses() to be called multiple times in all cases, I'll send a follow up patch that resets the state accumulated during the assignAddresses().