LLVM  3.7.0
PPCTargetObjectFile.cpp
Go to the documentation of this file.
1 //===-- PPCTargetObjectFile.cpp - PPC Object Info -------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "PPCTargetObjectFile.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) {
23 }
24 
25 MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal(
26  const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
27  const TargetMachine &TM) const {
28  // Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI
29  // when we have a constant that contains global relocations. This is
30  // necessary because of this ABI's handling of pointers to functions in
31  // a shared library. The address of a function is actually the address
32  // of a function descriptor, which resides in the .opd section. Generated
33  // code uses the descriptor directly rather than going via the GOT as some
34  // other ABIs do, which means that initialized function pointers must
35  // reference the descriptor. The linker must convert copy relocs of
36  // pointers to functions in shared libraries into dynamic relocations,
37  // because of an ordering problem with initialization of copy relocs and
38  // PLT entries. The dynamic relocation will be initialized by the dynamic
39  // linker, so we must use DataRelROSection instead of ReadOnlySection.
40  // For more information, see the description of ELIMINATE_COPY_RELOCS in
41  // GNU ld.
42  if (Kind.isReadOnly()) {
43  const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
44 
45  if (GVar && GVar->isConstant() &&
46  (GVar->getInitializer()->getRelocationInfo() ==
49  }
50 
52  Mang, TM);
53 }
54 
55 const MCExpr *PPC64LinuxTargetObjectFile::
56 getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
57  const MCExpr *Expr =
59  return MCBinaryExpr::createAdd(Expr,
61  getContext());
62 }
63 
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:48
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:315
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
virtual void Initialize(MCContext &ctx, const TargetMachine &TM)
This method must be called before any actual lowering is done.
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:33
Context object for machine code objects.
Definition: MCContext.h:48
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:446
MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const override
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:28
PossibleRelocationsTy getRelocationInfo() const
getRelocationInfo - This method classifies the entry according to whether or not it may generate a re...
Definition: Constants.cpp:429
unsigned UseInitArray
UseInitArray - Use .init_array instead of .ctors for static constructors.
static SectionKind getReadOnlyWithRel()
Definition: SectionKind.h:230
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:285
const ARM::ArchExtKind Kind
Primary interface to the complete machine description for the target machine.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:150
bool isReadOnly() const
Definition: SectionKind.h:139