LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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/MC/MCContext.h"
12 #include "llvm/MC/MCExpr.h"
13 #include "llvm/MC/MCSectionELF.h"
14 #include "llvm/Target/Mangler.h"
15 
16 using namespace llvm;
17 
18 void
19 PPC64LinuxTargetObjectFile::
20 Initialize(MCContext &Ctx, const TargetMachine &TM) {
23 }
24 
25 const MCSection * PPC64LinuxTargetObjectFile::
26 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
27  Mangler *Mang, const TargetMachine &TM) const {
28 
29  const MCSection *DefaultSection =
31 
32  if (DefaultSection != ReadOnlySection)
33  return DefaultSection;
34 
35  // Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI
36  // when we have a constant that contains global relocations. This is
37  // necessary because of this ABI's handling of pointers to functions in
38  // a shared library. The address of a function is actually the address
39  // of a function descriptor, which resides in the .opd section. Generated
40  // code uses the descriptor directly rather than going via the GOT as some
41  // other ABIs do, which means that initialized function pointers must
42  // reference the descriptor. The linker must convert copy relocs of
43  // pointers to functions in shared libraries into dynamic relocations,
44  // because of an ordering problem with initialization of copy relocs and
45  // PLT entries. The dynamic relocation will be initialized by the dynamic
46  // linker, so we must use DataRelROSection instead of ReadOnlySection.
47  // For more information, see the description of ELIMINATE_COPY_RELOCS in
48  // GNU ld.
49  const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
50 
51  if (GVar && GVar->isConstant() &&
52  (GVar->getInitializer()->getRelocationInfo() ==
54  return DataRelROSection;
55 
56  return DefaultSection;
57 }
58 
59 const MCExpr *PPC64LinuxTargetObjectFile::
60 getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
61  const MCExpr *Expr =
63  return MCBinaryExpr::CreateAdd(Expr,
65  getContext());
66 }
67 
const MCSection * DataRelROSection
static const MCConstantExpr * Create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:152
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:266
const Constant * getInitializer() const
virtual void Initialize(MCContext &ctx, const TargetMachine &TM)
static const MCSymbolRefExpr * Create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:270
PossibleRelocationsTy getRelocationInfo() const
Definition: Constants.cpp:337
const MCSection * ReadOnlySection
bool isConstant() const
static const MCBinaryExpr * CreateAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:396
virtual const MCSection * SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, const TargetMachine &TM) const