Path: blob/master/runtime/compiler/z/codegen/S390AOTRelocation.cpp
6004 views
/*******************************************************************************1* Copyright (c) 2000, 2021 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/2122#include "z/codegen/S390AOTRelocation.hpp"2324#include "env/CompilerEnv.hpp"25#include "env/IO.hpp"26#include "env/jittypes.h"27#include "il/Node.hpp"28#include "il/Node_inlines.hpp"29#include "il/StaticSymbol.hpp"30#include "z/codegen/S390Instruction.hpp"31#include "env/VMJ9.h"3233void TR::S390PairedRelocation::mapRelocation(TR::CodeGenerator *cg)34{35if (cg->comp()->compileRelocatableCode())36{37cg->addExternalRelocation(38new (cg->trHeapMemory()) TR::ExternalOrderedPair32BitRelocation(39getSourceInstruction()->getBinaryEncoding(),40getSource2Instruction()->getBinaryEncoding(),41getRelocationTarget(),42getKind(), cg),43__FILE__, __LINE__, getSourceInstruction()->getNode());44}45}4647void TR::S390EncodingRelocation::addRelocation(TR::CodeGenerator *cg, uint8_t *cursor, char* file, uintptr_t line, TR::Node* node)48{49TR::Compilation *comp = cg->comp();50TR_J9VMBase *fej9 = (TR_J9VMBase *)(comp->fe());5152if (_reloType==TR_ClassAddress)53{54AOTcgDiag2( comp, "TR_ClassAddress cursor=%x symbolReference=%x\n", cursor, _symbolReference);55if (comp->getOption(TR_UseSymbolValidationManager))56{57TR_OpaqueClassBlock *clazz = (TR_OpaqueClassBlock*)(*((uintptr_t*)cursor));58TR_ASSERT_FATAL(clazz, "TR_ClassAddress relocation : cursor = %x, clazz can not be null", cursor);59cg->addExternalRelocation(new (cg->trHeapMemory()) TR::ExternalRelocation(cursor,60(uint8_t *)clazz,61(uint8_t *) TR::SymbolType::typeClass,62TR_SymbolFromManager,63cg),64file, line, node);6566}67else68{69*((uintptr_t*)cursor)=fej9->getPersistentClassPointerFromClassPointer((TR_OpaqueClassBlock*)(*((uintptr_t*)cursor)));70cg->addExternalRelocation(new (cg->trHeapMemory()) TR::ExternalRelocation(cursor, (uint8_t *) _symbolReference, (uint8_t *)_inlinedSiteIndex, TR_ClassAddress, cg),71file, line, node);72}73}74else if (_reloType==TR_RamMethod)75{76AOTcgDiag1( comp, "TR_RamMethod cursor=%x\n", cursor);77if (comp->getOption(TR_UseSymbolValidationManager))78{79TR::ResolvedMethodSymbol *methodSym = (TR::ResolvedMethodSymbol*) _symbolReference->getSymbol();80uint8_t * j9Method = (uint8_t *) (reinterpret_cast<intptr_t>(methodSym->getResolvedMethod()->resolvedMethodAddress()));81TR_ASSERT_FATAL(j9Method, "TR_RamMethod relocation : cursor = %x, j9Method can not be null", cursor);82cg->addExternalRelocation(new (cg->trHeapMemory()) TR::ExternalRelocation(cursor,83j9Method,84(uint8_t *) TR::SymbolType::typeMethod,85TR_SymbolFromManager,86cg),87file, line, node);88}89else90{91cg->addExternalRelocation(new (cg->trHeapMemory()) TR::ExternalRelocation(cursor, NULL, TR_RamMethod, cg), file, line, node);92}93}94else if (_reloType==TR_HelperAddress)95{96AOTcgDiag1( comp, "TR_HelperAddress cursor=%x\n", cursor);97cg->addExternalRelocation(new (cg->trHeapMemory()) TR::ExternalRelocation(cursor, (uint8_t *) _symbolReference, TR_HelperAddress, cg),98file, line, node);99}100else if (_reloType==TR_AbsoluteHelperAddress)101{102AOTcgDiag1( comp, "TR_AbsoluteHelperAddress cursor=%x\n", cursor);103cg->addExternalRelocation(new (cg->trHeapMemory()) TR::ExternalRelocation(cursor, (uint8_t *) _symbolReference, TR_AbsoluteHelperAddress, cg),104file, line, node);105}106else if (_reloType==TR_ConstantPool)107{108AOTcgDiag1( comp, "TR_ConstantPool cursor=%x\n", cursor);109if (comp->target().is64Bit())110{111cg->addExternalRelocation(new (cg->trHeapMemory()) TR::ExternalRelocation(cursor, (uint8_t *) *((uint64_t*) cursor), (uint8_t *)_inlinedSiteIndex, TR_ConstantPool, cg),112file, line, node);113}114else115{116cg->addExternalRelocation(new (cg->trHeapMemory()) TR::ExternalRelocation(cursor, (uint8_t *)(intptr_t) *((uint32_t*) cursor), (uint8_t *)_inlinedSiteIndex, TR_ConstantPool, cg),117file, line, node);118}119}120else if (_reloType==TR_MethodObject)121{122AOTcgDiag1( comp, "TR_MethodObject cursor=%x\n", cursor);123cg->addExternalRelocation(new (cg->trHeapMemory()) TR::ExternalRelocation(cursor, (uint8_t *) _symbolReference, (uint8_t *)_inlinedSiteIndex, TR_MethodObject, cg),124file, line, node);125}126else if (_reloType==TR_DataAddress)127{128if (cg->needRelocationsForStatics())129{130AOTcgDiag1( comp, "TR_DataAddress cursor=%x\n", cursor);131cg->addExternalRelocation(new (cg->trHeapMemory()) TR::ExternalRelocation(cursor, (uint8_t *) _symbolReference, (uint8_t *)_inlinedSiteIndex, TR_DataAddress, cg),132file, line, node);133}134}135else if (_reloType==TR_BodyInfoAddress)136{137AOTcgDiag1( comp, "TR_BodyInfoAddress cursor=%x\n", cursor);138if (comp->target().is64Bit())139{140cg->addExternalRelocation(new (cg->trHeapMemory()) TR::ExternalRelocation(cursor, (uint8_t *) *((uint64_t*) cursor), TR_BodyInfoAddress, cg),141file, line, node);142}143else144{145cg->addExternalRelocation(new (cg->trHeapMemory()) TR::ExternalRelocation(cursor, (uint8_t *)(intptr_t) *((uint32_t*) cursor), TR_BodyInfoAddress, cg),146file, line, node);147}148}149else if (_reloType==TR_DebugCounter)150{151TR::DebugCounterBase *counter = comp->getCounterFromStaticAddress(_symbolReference);152if (counter == NULL)153{154comp->failCompilation<TR::CompilationException>("Could not generate relocation for debug counter in TR::S390EncodingRelocation::addRelocation\n");155}156TR::DebugCounter::generateRelocation(comp,157cursor,158node,159counter);160}161else162{163TR_ASSERT(0,"relocation type [%d] not handled yet", _reloType);164}165}166167168