Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update JNI Target relocation record to have offset to the reloLocation. #6331

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 59 additions & 9 deletions compiler/x/codegen/X86BinaryEncoding.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2021 IBM Corp. and others
* Copyright (c) 2000, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -1094,10 +1094,27 @@ TR::X86ImmSymInstruction::addMetaDataForCodeAddress(uint8_t *cursor)
int rType = methodSym->getMethodKind()-1; //method kinds are 1-based
TR_ASSERT(reloTypes[rType], "There shouldn't be direct JNI interface calls!");

cg()->addExternalRelocation(new (cg()->trHeapMemory()) TR::ExternalRelocation(cursor, (uint8_t *)getNode()->getSymbolReference(),
getNode() ? (uint8_t *)(intptr_t)getNode()->getInlinedSiteIndex() : (uint8_t *)-1,
(TR_ExternalRelocationTargetKind) reloTypes [rType], cg()),
__FILE__, __LINE__, getNode());
uint8_t *startOfInstruction = self()->getBinaryEncoding();
uint8_t *startOfImmediate = cursor;
intptr_t diff = reinterpret_cast<intptr_t>(startOfImmediate) - reinterpret_cast<intptr_t>(startOfInstruction);
TR_ASSERT_FATAL(diff > 0, "Address of immediate %p less than address of instruction %p\n",
startOfImmediate, startOfInstruction);

TR_RelocationRecordInformation *info =
reinterpret_cast<TR_RelocationRecordInformation *>(
comp->trMemory()->allocateHeapMemory(sizeof(TR_RelocationRecordInformation)));
info->data1 = static_cast<uintptr_t>(diff);
info->data2 = reinterpret_cast<uintptr_t>(getNode()->getSymbolReference());
int16_t inlinedSiteIndex = getNode() ? getNode()->getInlinedSiteIndex() : -1;
info->data3 = static_cast<uintptr_t>(inlinedSiteIndex);

cg()->addExternalRelocation(
new (cg()->trHeapMemory()) TR::ExternalRelocation(
startOfInstruction,
reinterpret_cast<uint8_t *>(info),
static_cast<TR_ExternalRelocationTargetKind>(reloTypes[rType]),
cg()),
__FILE__, __LINE__, getNode());
}
else if (resolvedMethod)
{
Expand Down Expand Up @@ -2767,13 +2784,46 @@ TR::AMD64RegImm64Instruction::addMetaDataForCodeAddress(uint8_t *cursor)
__FILE__, __LINE__, getNode());
}
break;
case TR_JNIStaticTargetAddress:
case TR_JNISpecialTargetAddress:
case TR_JNIVirtualTargetAddress:
case TR_StaticRamMethodConst:
case TR_VirtualRamMethodConst:
case TR_SpecialRamMethodConst:
cg()->addExternalRelocation(new (cg()->trHeapMemory()) TR::ExternalRelocation(cursor, (uint8_t *) getNode()->getSymbolReference(), getNode() ? (uint8_t *)(intptr_t)getNode()->getInlinedSiteIndex() : (uint8_t *)-1, (TR_ExternalRelocationTargetKind) _reloKind, cg()), __FILE__,__LINE__, getNode());
cg()->addExternalRelocation(
new (cg()->trHeapMemory()) TR::ExternalRelocation(
cursor,
(uint8_t *) getNode()->getSymbolReference(),
getNode()
? (uint8_t *)(intptr_t)getNode()->getInlinedSiteIndex()
: (uint8_t *)-1,
(TR_ExternalRelocationTargetKind) _reloKind,
cg()),
__FILE__,__LINE__, getNode());
break;
case TR_JNIStaticTargetAddress:
case TR_JNISpecialTargetAddress:
case TR_JNIVirtualTargetAddress:
{
uint8_t *startOfInstruction = self()->getBinaryEncoding();
uint8_t *startOfImmediate = cursor;
intptr_t diff = reinterpret_cast<intptr_t>(startOfImmediate) - reinterpret_cast<intptr_t>(startOfInstruction);
TR_ASSERT_FATAL(diff > 0, "Address of immediate %p less than address of instruction %p\n",
startOfImmediate, startOfInstruction);

TR_RelocationRecordInformation *info =
reinterpret_cast<TR_RelocationRecordInformation *>(
comp->trMemory()->allocateHeapMemory(sizeof(TR_RelocationRecordInformation)));
info->data1 = static_cast<uintptr_t>(diff);
info->data2 = reinterpret_cast<uintptr_t>(getNode()->getSymbolReference());
int16_t inlinedSiteIndex = getNode() ? getNode()->getInlinedSiteIndex() : -1;
info->data3 = static_cast<uintptr_t>(inlinedSiteIndex);

cg()->addExternalRelocation(
new (cg()->trHeapMemory()) TR::ExternalRelocation(
startOfInstruction,
reinterpret_cast<uint8_t *>(info),
static_cast<TR_ExternalRelocationTargetKind>(_reloKind),
cg()),
__FILE__,__LINE__, getNode());
}
break;
}
}
Expand Down
20 changes: 15 additions & 5 deletions compiler/z/codegen/ConstantDataSnippet.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2021 IBM Corp. and others
* Copyright (c) 2000, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -135,10 +135,20 @@ TR::S390ConstantDataSnippet::addMetaDataForCodeAddress(uint8_t *cursor)
case TR_JNIVirtualTargetAddress:
{
AOTcgDiag3(comp, "add relocation (%d) cursor=%x symbolReference=%x\n", reloType, cursor, getSymbolReference());
cg()->addExternalRelocation(new (cg()->trHeapMemory()) TR::ExternalRelocation(cursor, (uint8_t *)getNode()->getSymbolReference(),
getNode() ? (uint8_t *)(intptr_t)getNode()->getInlinedSiteIndex() : (uint8_t *)-1,
(TR_ExternalRelocationTargetKind) reloType, cg()),
__FILE__, __LINE__, getNode());

TR_RelocationRecordInformation *info = new (comp->trHeapMemory()) TR_RelocationRecordInformation();
info->data1 = 0;
info->data2 = reinterpret_cast<uintptr_t>(getNode()->getSymbolReference());
int16_t inlinedSiteIndex = getNode() ? getNode()->getInlinedSiteIndex() : -1;
info->data3 = static_cast<uintptr_t>(inlinedSiteIndex);

cg()->addExternalRelocation(
new (cg()->trHeapMemory()) TR::ExternalRelocation(
cursor,
reinterpret_cast<uint8_t *>(info),
static_cast<TR_ExternalRelocationTargetKind>(reloType),
cg()),
__FILE__, __LINE__, getNode());
}
break;

Expand Down