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"
10cdafe59fSSimon 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::
Initialize(MCContext & Ctx,const TargetMachine & TM)2022d40dcfSBill Schmidt Initialize(MCContext &Ctx, const TargetMachine &TM) {
2122d40dcfSBill Schmidt TargetLoweringObjectFileELF::Initialize(Ctx, TM);
2222d40dcfSBill Schmidt }
2322d40dcfSBill Schmidt
SelectSectionForGlobal(const GlobalObject * GO,SectionKind Kind,const TargetMachine & TM) const240709a7bdSRafael 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
43*c77659e5SLeonard Chan if (GVar && GVar->isConstant() &&
44*c77659e5SLeonard Chan GVar->getInitializer()->needsDynamicRelocation())
45f4453998SUlrich Weigand Kind = SectionKind::getReadOnlyWithRel();
46f4453998SUlrich Weigand }
4722d40dcfSBill Schmidt
486733564eSPeter Collingbourne return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM);
4922d40dcfSBill Schmidt }
500f039824SUlrich Weigand
510f039824SUlrich Weigand const MCExpr *PPC64LinuxTargetObjectFile::
getDebugThreadLocalSymbol(const MCSymbol * Sym) const520f039824SUlrich Weigand getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
530f039824SUlrich Weigand const MCExpr *Expr =
540e05192dSColin LeMahieu MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_DTPREL, getContext());
5513760bd1SJim Grosbach return MCBinaryExpr::createAdd(Expr,
5613760bd1SJim Grosbach MCConstantExpr::create(0x8000, getContext()),
570f039824SUlrich Weigand getContext());
580f039824SUlrich Weigand }
590f039824SUlrich Weigand
60