This refactors a bit of duplicated code and fixes an assertion failure on ELF. llvm-svn: 306035
llvm-svn: 199765