Skip to content

Commit

Permalink
Fix for functions in different segments.
Browse files Browse the repository at this point in the history
Summary:
In a test binary some functions are placed in a segment
preceding the segment containing .text section. As a result,
we were miscalculating maximum function size as the calculation
was based on addresses only.

This diff fixes the calculation by checking if symbol after function
belongs to the same section.  If it does not, then we set the maximum
function size based on the size of the containing section and not
on the address distance to the next symbol.

(cherry picked from FBD3229205)
  • Loading branch information
maksfb committed Apr 27, 2016
1 parent 3811673 commit 1258903
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion bolt/RewriteInstance.cpp
Expand Up @@ -853,7 +853,25 @@ void RewriteInstance::disassembleFunctions() {
// has been processed.
auto SymRefI = FileSymRefs.upper_bound(Function.getAddress());
if (SymRefI != FileSymRefs.end()) {
auto MaxSize = SymRefI->first - Function.getAddress();
uint64_t MaxSize;
auto SectionIter = *SymRefI->second.getSection();
if (SectionIter != InputFile->section_end() &&
*SectionIter == Function.getSection()) {
MaxSize = SymRefI->first - Function.getAddress();
} else {
// Function runs till the end of the containing section assuming
// the section does not run over the next symbol.
uint64_t SectionEnd = Function.getSection().getAddress() +
Function.getSection().getSize();
if (SectionEnd > SymRefI->first) {
errs() << "BOLT-WARNING: symbol after " << Function.getName()
<< " should not be in the same section.\n";
MaxSize = 0;
} else {
MaxSize = SectionEnd - Function.getAddress();
}
}

if (MaxSize < Function.getSize()) {
errs() << "BOLT-WARNING: symbol seen in the middle of the function "
<< Function.getName() << ". Skipping.\n";
Expand Down

0 comments on commit 1258903

Please sign in to comment.