]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / lib / Target / PowerPC / PPCTargetObjectFile.cpp
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) {
21   TargetLoweringObjectFileELF::Initialize(Ctx, TM);
22   InitializeELF(TM.Options.UseInitArray);
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 = 
30     TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang, TM);
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() ==
53        Constant::GlobalRelocations))
54     return DataRelROSection;
55
56   return DefaultSection;
57 }
58
59 const MCExpr *PPC64LinuxTargetObjectFile::
60 getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
61   const MCExpr *Expr =
62     MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_PPC_DTPREL, getContext());
63   return MCBinaryExpr::CreateAdd(Expr,
64                                  MCConstantExpr::Create(0x8000, getContext()),
65                                  getContext());
66 }
67