From f9ff21a0bc5d2ffce5f548191e3f81a39eee25c5 Mon Sep 17 00:00:00 2001 From: Antonio Flores Montoya Date: Fri, 4 Oct 2024 09:16:08 -0400 Subject: [PATCH 1/2] fix PE merge data section rule When trying to determine the extent of a merged data section do not consider data directories at the end of the text section. Also, remove assertion for failing to assign an entry point for PE binaries this can happen for dlls --- src/datalog/binary/pe/pe_binaries.dl | 4 +++- src/gtirb-builder/PeReader.cpp | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/datalog/binary/pe/pe_binaries.dl b/src/datalog/binary/pe/pe_binaries.dl index 3119382f..52067e25 100644 --- a/src/datalog/binary/pe/pe_binaries.dl +++ b/src/datalog/binary/pe/pe_binaries.dl @@ -213,6 +213,7 @@ incremental_linking(First,Last):- !incremental_linking_candidate(First,Next), Count = count : { incremental_linking_candidate(First,_) }, Count > 5. + /** Locate data directory and debug data merged with the text section. Note that this is used to splice merged .rdata and .text sections. @@ -228,7 +229,8 @@ merged_data_region(DataStart,DataStart+DataSize):- ), loaded_section(SectionStart,SectionEnd,".text"), DataStart > SectionStart, - DataStart < SectionEnd. + // Do not consider data directories at the end of the code section. + DataStart + DataSize < SectionEnd. // Infer prepended .rdata boundaries. data_region(Start,Size):- diff --git a/src/gtirb-builder/PeReader.cpp b/src/gtirb-builder/PeReader.cpp index 9b63be9c..ac5f370e 100644 --- a/src/gtirb-builder/PeReader.cpp +++ b/src/gtirb-builder/PeReader.cpp @@ -164,7 +164,6 @@ void PeReader::addEntryBlock() Module->setEntryPoint(Block); } } - assert(Module->getEntryPoint() && "Failed to set module entry point."); } void PeReader::addAuxData() From ec829e1a34b9525fa93517dc6c29f4ba0c91e18e Mon Sep 17 00:00:00 2001 From: Antonio Flores Montoya Date: Tue, 8 Oct 2024 10:01:20 -0400 Subject: [PATCH 2/2] add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87d99fc8..52a1f070 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ * Fix bug that led to string data blocks potentially overlapping code blocks. * Fix bug that resulted in integral symbols on ISAs other than x64 (ARM and x86). * Fix symbolization bug of ADR instructions in ARM32 that refer to code. +* Fix bug in PE code inference that could lead to the whole .text section being + declared invalid if a data directory was attached to the end of the section. # 1.9.0