LLVM  14.0.0git
PPCTargetObjectFile.cpp
Go to the documentation of this file.
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "PPCTargetObjectFile.h"
10 #include "llvm/IR/GlobalVariable.h"
11 #include "llvm/IR/Mangler.h"
12 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCExpr.h"
14 #include "llvm/MC/MCSectionELF.h"
15 
16 using namespace llvm;
17 
18 void
19 PPC64LinuxTargetObjectFile::
20 Initialize(MCContext &Ctx, const TargetMachine &TM) {
22 }
23 
24 MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal(
25  const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
26  // Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI
27  // when we have a constant that contains global relocations. This is
28  // necessary because of this ABI's handling of pointers to functions in
29  // a shared library. The address of a function is actually the address
30  // of a function descriptor, which resides in the .opd section. Generated
31  // code uses the descriptor directly rather than going via the GOT as some
32  // other ABIs do, which means that initialized function pointers must
33  // reference the descriptor. The linker must convert copy relocs of
34  // pointers to functions in shared libraries into dynamic relocations,
35  // because of an ordering problem with initialization of copy relocs and
36  // PLT entries. The dynamic relocation will be initialized by the dynamic
37  // linker, so we must use DataRelROSection instead of ReadOnlySection.
38  // For more information, see the description of ELIMINATE_COPY_RELOCS in
39  // GNU ld.
40  if (Kind.isReadOnly()) {
41  const auto *GVar = dyn_cast<GlobalVariable>(GO);
42 
43  if (GVar && GVar->isConstant() &&
44  GVar->getInitializer()->needsDynamicRelocation())
46  }
47 
49 }
50 
51 const MCExpr *PPC64LinuxTargetObjectFile::
52 getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
53  const MCExpr *Expr =
55  return MCBinaryExpr::createAdd(Expr,
57  getContext());
58 }
59 
llvm::SectionKind::getReadOnlyWithRel
static SectionKind getReadOnlyWithRel()
Definition: SectionKind.h:207
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::TargetLoweringObjectFileELF::SelectSectionForGlobal
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Definition: TargetLoweringObjectFileImpl.cpp:874
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::MCConstantExpr::create
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
MCSectionELF.h
llvm::MCObjectFileInfo::getContext
MCContext & getContext() const
Definition: MCObjectFileInfo.h:235
llvm::GlobalObject
Definition: GlobalObject.h:28
MCContext.h
llvm::MCSymbolRefExpr::VK_DTPREL
@ VK_DTPREL
Definition: MCExpr.h:357
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
PPCTargetObjectFile.h
llvm::TargetLoweringObjectFile::TM
const TargetMachine * TM
Definition: TargetLoweringObjectFile.h:67
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:79
Mangler.h
llvm::MCBinaryExpr::createAdd
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:524
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
GlobalVariable.h
llvm::TargetLoweringObjectFileELF::Initialize
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Definition: TargetLoweringObjectFileImpl.cpp:116
llvm::MCSymbolRefExpr::create
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:385
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
MCExpr.h
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35