122d40dcfSBill Schmidt //===-- PPCTargetObjectFile.cpp - PPC Object Info -------------------------===// 222d40dcfSBill Schmidt // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 622d40dcfSBill Schmidt // 722d40dcfSBill Schmidt //===----------------------------------------------------------------------===// 822d40dcfSBill Schmidt 922d40dcfSBill Schmidt #include "PPCTargetObjectFile.h" 10*cdafe59fSSimon Pilgrim #include "llvm/IR/GlobalVariable.h" 11894843cbSRafael Espindola #include "llvm/IR/Mangler.h" 1222d40dcfSBill Schmidt #include "llvm/MC/MCContext.h" 1322d40dcfSBill Schmidt #include "llvm/MC/MCExpr.h" 1422d40dcfSBill Schmidt #include "llvm/MC/MCSectionELF.h" 1522d40dcfSBill Schmidt 1622d40dcfSBill Schmidt using namespace llvm; 1722d40dcfSBill Schmidt 1822d40dcfSBill Schmidt void 1922d40dcfSBill Schmidt PPC64LinuxTargetObjectFile:: 2022d40dcfSBill Schmidt Initialize(MCContext &Ctx, const TargetMachine &TM) { 2122d40dcfSBill Schmidt TargetLoweringObjectFileELF::Initialize(Ctx, TM); 2222d40dcfSBill Schmidt } 2322d40dcfSBill Schmidt 240709a7bdSRafael Espindola MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal( 256733564eSPeter Collingbourne const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { 266cda22a3SBill Schmidt // Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI 2722d40dcfSBill Schmidt // when we have a constant that contains global relocations. This is 2822d40dcfSBill Schmidt // necessary because of this ABI's handling of pointers to functions in 2922d40dcfSBill Schmidt // a shared library. The address of a function is actually the address 3022d40dcfSBill Schmidt // of a function descriptor, which resides in the .opd section. Generated 3122d40dcfSBill Schmidt // code uses the descriptor directly rather than going via the GOT as some 3222d40dcfSBill Schmidt // other ABIs do, which means that initialized function pointers must 3322d40dcfSBill Schmidt // reference the descriptor. The linker must convert copy relocs of 3422d40dcfSBill Schmidt // pointers to functions in shared libraries into dynamic relocations, 3522d40dcfSBill Schmidt // because of an ordering problem with initialization of copy relocs and 3622d40dcfSBill Schmidt // PLT entries. The dynamic relocation will be initialized by the dynamic 376cda22a3SBill Schmidt // linker, so we must use DataRelROSection instead of ReadOnlySection. 3822d40dcfSBill Schmidt // For more information, see the description of ELIMINATE_COPY_RELOCS in 3922d40dcfSBill Schmidt // GNU ld. 40f4453998SUlrich Weigand if (Kind.isReadOnly()) { 416733564eSPeter Collingbourne const auto *GVar = dyn_cast<GlobalVariable>(GO); 4222d40dcfSBill Schmidt 4365e49021SRafael Espindola if (GVar && GVar->isConstant() && GVar->getInitializer()->needsRelocation()) 44f4453998SUlrich Weigand Kind = SectionKind::getReadOnlyWithRel(); 45f4453998SUlrich Weigand } 4622d40dcfSBill Schmidt 476733564eSPeter Collingbourne return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM); 4822d40dcfSBill Schmidt } 490f039824SUlrich Weigand 500f039824SUlrich Weigand const MCExpr *PPC64LinuxTargetObjectFile:: 510f039824SUlrich Weigand getDebugThreadLocalSymbol(const MCSymbol *Sym) const { 520f039824SUlrich Weigand const MCExpr *Expr = 530e05192dSColin LeMahieu MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_DTPREL, getContext()); 5413760bd1SJim Grosbach return MCBinaryExpr::createAdd(Expr, 5513760bd1SJim Grosbach MCConstantExpr::create(0x8000, getContext()), 560f039824SUlrich Weigand getContext()); 570f039824SUlrich Weigand } 580f039824SUlrich Weigand 59