Check runtime lib format within archiver

Summary: We only support linking ELF runtime library right now. If the library is an archiver, we check that each individual library inside the archiver is an ELF library.

(cherry picked from FBD21388672)
This commit is contained in:
Xun Li 2020-05-04 13:57:21 -07:00 committed by Maksim Panchenko
parent 924d0bdb08
commit 7b61bdf8ea
1 changed files with 9 additions and 1 deletions

View File

@ -1295,7 +1295,7 @@ void RewriteInstance::disassemblePLT() {
<< Twine::utohexstr(InstrAddr) << '\n';
exit(1);
}
auto NI = RelAddrToNameMap.find(TargetAddress);
if (NI == RelAddrToNameMap.end())
continue;
@ -2762,6 +2762,14 @@ void RewriteInstance::linkRuntime() {
auto ChildKey = ES->allocateVModule();
auto ChildBuf =
MemoryBuffer::getMemBuffer(cantFail(C.getMemoryBufferRef()));
auto ChildMagic = identify_magic(ChildBuf->getBuffer());
if (ChildMagic != file_magic::elf_relocatable &&
ChildMagic != file_magic::elf_shared_object) {
errs() << "BOLT-ERROR: unrecognized instrumentation library format "
<< "inside the archiver: "
<< LibPath << "\n";
exit(1);
}
cantFail(OLT->addObject(ChildKey, std::move(ChildBuf)));
cantFail(OLT->emitAndFinalize(ChildKey));
}