Skip to content

Commit

Permalink
Check whether relocations are needed for debug counters
Browse files Browse the repository at this point in the history
Code was unconditionally adding relocation records for debug counters
without first checking that they are required.

Signed-off-by:  Henry Zongaro <zongaro@ca.ibm.com>
  • Loading branch information
hzongaro committed Aug 26, 2021
1 parent 1d0a329 commit cee45b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
17 changes: 10 additions & 7 deletions compiler/x/amd64/codegen/OMRMemoryReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,15 +500,18 @@ OMR::X86::AMD64::MemoryReference::addMetaDataForCodeAddressWithLoad(
}
else if (sr.getSymbol()->isDebugCounter())
{
TR::DebugCounterBase *counter = cg->comp()->getCounterFromStaticAddress(&sr);
if (counter == NULL)
if (cg->needRelocationsForStatics())
{
cg->comp()->failCompilation<TR::CompilationException>("Could not generate relocation for debug counter in OMR::X86::AMD64::MemoryReference::addMetaDataForCodeAddressWithLoad\n");
TR::DebugCounterBase *counter = cg->comp()->getCounterFromStaticAddress(&sr);
if (counter == NULL)
{
cg->comp()->failCompilation<TR::CompilationException>("Could not generate relocation for debug counter in OMR::X86::AMD64::MemoryReference::addMetaDataForCodeAddressWithLoad\n");
}
TR::DebugCounter::generateRelocation(cg->comp(),
displacementLocation,
containingInstruction->getNode(),
counter);
}
TR::DebugCounter::generateRelocation(cg->comp(),
displacementLocation,
containingInstruction->getNode(),
counter);
}
}
else
Expand Down
17 changes: 10 additions & 7 deletions compiler/x/codegen/X86BinaryEncoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2897,15 +2897,18 @@ TR::AMD64RegImm64SymInstruction::addMetaDataForCodeAddress(uint8_t *cursor)

case TR_DebugCounter:
{
TR::DebugCounterBase *counter = cg()->comp()->getCounterFromStaticAddress(getSymbolReference());
if (counter == NULL)
if (cg()->needRelocationsForStatics())
{
cg()->comp()->failCompilation<TR::CompilationException>("Could not generate relocation for debug counter in TR::AMD64RegImm64SymInstruction::addMetaDataForCodeAddress\n");
TR::DebugCounterBase *counter = cg()->comp()->getCounterFromStaticAddress(getSymbolReference());
if (counter == NULL)
{
cg()->comp()->failCompilation<TR::CompilationException>("Could not generate relocation for debug counter in TR::AMD64RegImm64SymInstruction::addMetaDataForCodeAddress\n");
}
TR::DebugCounter::generateRelocation(cg()->comp(),
cursor,
getNode(),
counter);
}
TR::DebugCounter::generateRelocation(cg()->comp(),
cursor,
getNode(),
counter);
}
break;
case TR_BlockFrequency:
Expand Down

0 comments on commit cee45b6

Please sign in to comment.