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