Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/bolt
diff options
context:
space:
mode:
authorAmir Ayupov <aaupov@fb.com>2022-03-08 20:17:41 +0300
committerAmir Ayupov <aaupov@fb.com>2022-03-09 00:03:05 +0300
commit1e016c3bd532aa02b109a410ba0198aa49544fa6 (patch)
treec9f9bb5134c68219e9ff002856644b7646ba2f02 /bolt
parentcfb9e474ae360ce59ba9bf05167ba4922d58be5f (diff)
[BOLT][NFC] Handle "dynamic section sizes should match"
Address fuzzer crash on malformed input Reviewed By: rafauler Differential Revision: https://reviews.llvm.org/D121070
Diffstat (limited to 'bolt')
-rw-r--r--bolt/include/bolt/Rewrite/RewriteInstance.h20
-rw-r--r--bolt/lib/Rewrite/RewriteInstance.cpp13
2 files changed, 17 insertions, 16 deletions
diff --git a/bolt/include/bolt/Rewrite/RewriteInstance.h b/bolt/include/bolt/Rewrite/RewriteInstance.h
index 43049a4ee372..d94fc9c6e709 100644
--- a/bolt/include/bolt/Rewrite/RewriteInstance.h
+++ b/bolt/include/bolt/Rewrite/RewriteInstance.h
@@ -260,9 +260,9 @@ private:
void disassemblePLTSectionX86(BinarySection &Section, uint64_t EntrySize);
/// ELF-specific part. TODO: refactor into new class.
-#define ELF_FUNCTION(FUNC) \
- template <typename ELFT> void FUNC(object::ELFObjectFile<ELFT> *Obj); \
- void FUNC() { \
+#define ELF_FUNCTION(TYPE, FUNC) \
+ template <typename ELFT> TYPE FUNC(object::ELFObjectFile<ELFT> *Obj); \
+ TYPE FUNC() { \
if (auto *ELF32LE = dyn_cast<object::ELF32LEObjectFile>(InputFile)) \
return FUNC(ELF32LE); \
if (auto *ELF64LE = dyn_cast<object::ELF64LEObjectFile>(InputFile)) \
@@ -277,25 +277,25 @@ private:
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 <typename ELFObjType, typename ELFShdrTy>
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 8489caa9d90d..6c67eb3a87a2 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1635,8 +1635,7 @@ Error RewriteInstance::readSpecialSections() {
parseSDTNotes();
// Read .dynamic/PT_DYNAMIC.
- readELFDynamic();
- return Error::success();
+ return readELFDynamic();
}
void RewriteInstance::adjustCommandLineOptions() {
@@ -5098,7 +5097,7 @@ void RewriteInstance::patchELFDynamic(ELFObjectFile<ELFT> *File) {
}
template <typename ELFT>
-void RewriteInstance::readELFDynamic(ELFObjectFile<ELFT> *File) {
+Error RewriteInstance::readELFDynamic(ELFObjectFile<ELFT> *File) {
const ELFFile<ELFT> &Obj = File->getELFFile();
using Elf_Phdr = typename ELFFile<ELFT>::Elf_Phdr;
@@ -5117,11 +5116,12 @@ void RewriteInstance::readELFDynamic(ELFObjectFile<ELFT> *File) {
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 @@ void RewriteInstance::readELFDynamic(ELFObjectFile<ELFT> *File) {
PLTRelocationsAddress.reset();
PLTRelocationsSize = 0;
}
+ return Error::success();
}
uint64_t RewriteInstance::getNewFunctionAddress(uint64_t OldAddress) {