diff --git a/bolt/include/bolt/Rewrite/RewriteInstance.h b/bolt/include/bolt/Rewrite/RewriteInstance.h --- a/bolt/include/bolt/Rewrite/RewriteInstance.h +++ b/bolt/include/bolt/Rewrite/RewriteInstance.h @@ -260,9 +260,9 @@ void disassemblePLTSectionX86(BinarySection &Section, uint64_t EntrySize); /// ELF-specific part. TODO: refactor into new class. -#define ELF_FUNCTION(FUNC) \ - template void FUNC(object::ELFObjectFile *Obj); \ - void FUNC() { \ +#define ELF_FUNCTION(TYPE, FUNC) \ + template TYPE FUNC(object::ELFObjectFile *Obj); \ + TYPE FUNC() { \ if (auto *ELF32LE = dyn_cast(InputFile)) \ return FUNC(ELF32LE); \ if (auto *ELF64LE = dyn_cast(InputFile)) \ @@ -277,25 +277,25 @@ void patchELFPHDRTable(); /// Create section header table. - ELF_FUNCTION(patchELFSectionHeaderTable); + ELF_FUNCTION(void, patchELFSectionHeaderTable); /// Create the regular symbol table and patch dyn symbol tables. - ELF_FUNCTION(patchELFSymTabs); + ELF_FUNCTION(void, patchELFSymTabs); /// Read dynamic section/segment of ELF. - ELF_FUNCTION(readELFDynamic); + ELF_FUNCTION(Error, readELFDynamic); /// Patch dynamic section/segment of ELF. - ELF_FUNCTION(patchELFDynamic); + ELF_FUNCTION(void, patchELFDynamic); /// Patch .got - ELF_FUNCTION(patchELFGOT); + ELF_FUNCTION(void, patchELFGOT); /// Patch allocatable relocation sections. - ELF_FUNCTION(patchELFAllocatableRelaSections); + ELF_FUNCTION(void, patchELFAllocatableRelaSections); /// Finalize memory image of section header string table. - ELF_FUNCTION(finalizeSectionStringTable); + ELF_FUNCTION(void, finalizeSectionStringTable); /// Return a name of the input file section in the output file. template diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -1635,8 +1635,7 @@ parseSDTNotes(); // Read .dynamic/PT_DYNAMIC. - readELFDynamic(); - return Error::success(); + return readELFDynamic(); } void RewriteInstance::adjustCommandLineOptions() { @@ -5098,7 +5097,7 @@ } template -void RewriteInstance::readELFDynamic(ELFObjectFile *File) { +Error RewriteInstance::readELFDynamic(ELFObjectFile *File) { const ELFFile &Obj = File->getELFFile(); using Elf_Phdr = typename ELFFile::Elf_Phdr; @@ -5117,11 +5116,12 @@ outs() << "BOLT-INFO: static input executable detected\n"; // TODO: static PIE executable might have dynamic header BC->IsStaticExecutable = true; - return; + return Error::success(); } - assert(DynamicPhdr->p_memsz == DynamicPhdr->p_filesz && - "dynamic section sizes should match"); + if (DynamicPhdr->p_memsz != DynamicPhdr->p_filesz) + return createStringError(errc::executable_format_error, + "dynamic section sizes should match"); // Go through all dynamic entries to locate entries of interest. typename ELFT::DynRange DynamicEntries = @@ -5165,6 +5165,7 @@ PLTRelocationsAddress.reset(); PLTRelocationsSize = 0; } + return Error::success(); } uint64_t RewriteInstance::getNewFunctionAddress(uint64_t OldAddress) {