Skip to content

Commit

Permalink
A block can be split between it is just recorded in the block end
Browse files Browse the repository at this point in the history
map and adding out-going edge work elements. This means Block::end()
and Block::last() are not reliable when adding parsing work elements.
Change them to use IA_IAPI::getAddr(), which is a local object.
  • Loading branch information
mxz297 committed Oct 16, 2018
1 parent e48c167 commit c6cf5ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
22 changes: 16 additions & 6 deletions parseAPI/src/Parser.C
Expand Up @@ -1705,7 +1705,7 @@ Parser::parse_frame_one_iteration(ParseFrame &frame, bool recursive) {
frame.mkWork(
NULL,
newedge,
cur->last(),
ahPtr->getAddr(),
nextBlockAddr,
true,
false)
Expand All @@ -1726,7 +1726,7 @@ Parser::parse_frame_one_iteration(ParseFrame &frame, bool recursive) {
ah->retreat();
end_block(cur, ah);
if (!set_edge_parsing_status(frame ,cur->last(), cur)) break;
add_edge(frame, frame.func, cur, cur->last(), curAddr, FALLTHROUGH, NULL);
add_edge(frame, frame.func, cur, ah->getAddr(), curAddr, FALLTHROUGH, NULL);
// We break from this loop because no need more stright-line parsing
break;
}
Expand Down Expand Up @@ -1771,7 +1771,7 @@ Parser::parse_frame_one_iteration(ParseFrame &frame, bool recursive) {
frame.mkWork(
NULL,
newedge,
cur->last(),
ah->getAddr(),
curAddr,
true,
false)
Expand Down Expand Up @@ -1823,7 +1823,7 @@ Parser::parse_frame_one_iteration(ParseFrame &frame, bool recursive) {
frame.mkWork(
NULL,
newedge,
cur->last(),
ahPtr->getAddr(),
curAddr,
true,
false)
Expand Down Expand Up @@ -2065,6 +2065,12 @@ Parser::add_edge(
retpair.second = newedge;
} else {
assert(src->last() == src_addr);
if (exist->type() == FALLTHROUGH || exist->type() == COND_NOT_TAKEN || exist->type() == CALL_FT) {
if (src->end() != ret->start()) {
fprintf(stderr, "src_addr %lx, src: [%lx, %lx), dst [%lx, %lx), target %lx, edge type %d\n", src_addr, src->start(), src->end(), ret->start(), src->end(), dst, et);
}
}

relink(exist,src,ret);
retpair.second = exist;
}
Expand Down Expand Up @@ -2320,8 +2326,12 @@ Parser::link_tempsink(Block *src, EdgeTypeEnum et)
void
Parser::relink(ParseAPI::Edge * e, Block *src, Block *dst)
{
if (e->type() == FALLTHROUGH || e->type() == COND_NOT_TAKEN)
assert(src->end() == dst->start());
if (e->type() == FALLTHROUGH || e->type() == COND_NOT_TAKEN || e->type() == CALL_FT) {
if (src->end() != dst->start()) {
fprintf(stderr, "In relink : src [%lx, %lx) dst [%lx, %lx)\n", src->start(), src->end(), dst->start(), dst->end());
assert(src->end() == dst->start());
}
}
unsigned long srcOut = 0, dstIn = 0, oldDstIn = 0;
Block* oldDst = NULL;
if(e->trg() && e->trg_addr() != std::numeric_limits<Address>::max()) {
Expand Down
6 changes: 5 additions & 1 deletion parseAPI/src/ParserDetails.C
Expand Up @@ -406,6 +406,10 @@ void Parser::ProcessCFInsn(
parsing_printf("Returned %d edges\n", edges_out.size());
if (unlikely(_obj.defensiveMode() && !ah->isCall() && edges_out.size())) {
// only parse branch edges that align with existing blocks
//
// Xiaozhu: The person who works on defensive mode needs to
// revisit this code. In parallel parsing, the block boundary (cur->end())
// is not reliable because it can be split by another thread
bool hasUnalignedEdge = false;
set<CodeRegion *> tregs;
set<Block *> tblocks;
Expand Down Expand Up @@ -552,7 +556,7 @@ void Parser::ProcessCFInsn(
new ParseWorkElem(
bundle,
newedge,
cur->last(),
ah->getAddr(),
curEdge->first,
resolvable_edge,
tailcall)
Expand Down

0 comments on commit c6cf5ab

Please sign in to comment.