1*0b57cec5SDimitry Andric //===-- PPCTargetObjectFile.cpp - PPC Object Info -------------------------===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric 9*0b57cec5SDimitry Andric #include "PPCTargetObjectFile.h" 10*0b57cec5SDimitry Andric #include "llvm/IR/Mangler.h" 11*0b57cec5SDimitry Andric #include "llvm/MC/MCContext.h" 12*0b57cec5SDimitry Andric #include "llvm/MC/MCExpr.h" 13*0b57cec5SDimitry Andric #include "llvm/MC/MCSectionELF.h" 14*0b57cec5SDimitry Andric 15*0b57cec5SDimitry Andric using namespace llvm; 16*0b57cec5SDimitry Andric 17*0b57cec5SDimitry Andric void 18*0b57cec5SDimitry Andric PPC64LinuxTargetObjectFile:: 19*0b57cec5SDimitry Andric Initialize(MCContext &Ctx, const TargetMachine &TM) { 20*0b57cec5SDimitry Andric TargetLoweringObjectFileELF::Initialize(Ctx, TM); 21*0b57cec5SDimitry Andric InitializeELF(TM.Options.UseInitArray); 22*0b57cec5SDimitry Andric } 23*0b57cec5SDimitry Andric 24*0b57cec5SDimitry Andric MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal( 25*0b57cec5SDimitry Andric const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { 26*0b57cec5SDimitry Andric // Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI 27*0b57cec5SDimitry Andric // when we have a constant that contains global relocations. This is 28*0b57cec5SDimitry Andric // necessary because of this ABI's handling of pointers to functions in 29*0b57cec5SDimitry Andric // a shared library. The address of a function is actually the address 30*0b57cec5SDimitry Andric // of a function descriptor, which resides in the .opd section. Generated 31*0b57cec5SDimitry Andric // code uses the descriptor directly rather than going via the GOT as some 32*0b57cec5SDimitry Andric // other ABIs do, which means that initialized function pointers must 33*0b57cec5SDimitry Andric // reference the descriptor. The linker must convert copy relocs of 34*0b57cec5SDimitry Andric // pointers to functions in shared libraries into dynamic relocations, 35*0b57cec5SDimitry Andric // because of an ordering problem with initialization of copy relocs and 36*0b57cec5SDimitry Andric // PLT entries. The dynamic relocation will be initialized by the dynamic 37*0b57cec5SDimitry Andric // linker, so we must use DataRelROSection instead of ReadOnlySection. 38*0b57cec5SDimitry Andric // For more information, see the description of ELIMINATE_COPY_RELOCS in 39*0b57cec5SDimitry Andric // GNU ld. 40*0b57cec5SDimitry Andric if (Kind.isReadOnly()) { 41*0b57cec5SDimitry Andric const auto *GVar = dyn_cast<GlobalVariable>(GO); 42*0b57cec5SDimitry Andric 43*0b57cec5SDimitry Andric if (GVar && GVar->isConstant() && GVar->getInitializer()->needsRelocation()) 44*0b57cec5SDimitry Andric Kind = SectionKind::getReadOnlyWithRel(); 45*0b57cec5SDimitry Andric } 46*0b57cec5SDimitry Andric 47*0b57cec5SDimitry Andric return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM); 48*0b57cec5SDimitry Andric } 49*0b57cec5SDimitry Andric 50*0b57cec5SDimitry Andric const MCExpr *PPC64LinuxTargetObjectFile:: 51*0b57cec5SDimitry Andric getDebugThreadLocalSymbol(const MCSymbol *Sym) const { 52*0b57cec5SDimitry Andric const MCExpr *Expr = 53*0b57cec5SDimitry Andric MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_DTPREL, getContext()); 54*0b57cec5SDimitry Andric return MCBinaryExpr::createAdd(Expr, 55*0b57cec5SDimitry Andric MCConstantExpr::create(0x8000, getContext()), 56*0b57cec5SDimitry Andric getContext()); 57*0b57cec5SDimitry Andric } 58*0b57cec5SDimitry Andric 59