1*22d40dcfSBill Schmidt //===-- PPCTargetObjectFile.cpp - PPC Object Info -------------------------===//
2*22d40dcfSBill Schmidt //
3*22d40dcfSBill Schmidt //                     The LLVM Compiler Infrastructure
4*22d40dcfSBill Schmidt //
5*22d40dcfSBill Schmidt // This file is distributed under the University of Illinois Open Source
6*22d40dcfSBill Schmidt // License. See LICENSE.TXT for details.
7*22d40dcfSBill Schmidt //
8*22d40dcfSBill Schmidt //===----------------------------------------------------------------------===//
9*22d40dcfSBill Schmidt 
10*22d40dcfSBill Schmidt #include "PPCTargetObjectFile.h"
11*22d40dcfSBill Schmidt #include "llvm/MC/MCContext.h"
12*22d40dcfSBill Schmidt #include "llvm/MC/MCExpr.h"
13*22d40dcfSBill Schmidt #include "llvm/MC/MCSectionELF.h"
14*22d40dcfSBill Schmidt #include "llvm/Target/Mangler.h"
15*22d40dcfSBill Schmidt 
16*22d40dcfSBill Schmidt using namespace llvm;
17*22d40dcfSBill Schmidt 
18*22d40dcfSBill Schmidt void
19*22d40dcfSBill Schmidt PPC64LinuxTargetObjectFile::
20*22d40dcfSBill Schmidt Initialize(MCContext &Ctx, const TargetMachine &TM) {
21*22d40dcfSBill Schmidt   TargetLoweringObjectFileELF::Initialize(Ctx, TM);
22*22d40dcfSBill Schmidt   InitializeELF(TM.Options.UseInitArray);
23*22d40dcfSBill Schmidt }
24*22d40dcfSBill Schmidt 
25*22d40dcfSBill Schmidt const MCSection * PPC64LinuxTargetObjectFile::
26*22d40dcfSBill Schmidt SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
27*22d40dcfSBill Schmidt                        Mangler *Mang, const TargetMachine &TM) const {
28*22d40dcfSBill Schmidt 
29*22d40dcfSBill Schmidt   const MCSection *DefaultSection =
30*22d40dcfSBill Schmidt     TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang, TM);
31*22d40dcfSBill Schmidt 
32*22d40dcfSBill Schmidt   if (DefaultSection != ReadOnlySection)
33*22d40dcfSBill Schmidt     return DefaultSection;
34*22d40dcfSBill Schmidt 
35*22d40dcfSBill Schmidt   // Here override isReadOnly() to isReadOnlyWithRel() for PPC64 SVR4 ABI
36*22d40dcfSBill Schmidt   // when we have a constant that contains global relocations.  This is
37*22d40dcfSBill Schmidt   // necessary because of this ABI's handling of pointers to functions in
38*22d40dcfSBill Schmidt   // a shared library.  The address of a function is actually the address
39*22d40dcfSBill Schmidt   // of a function descriptor, which resides in the .opd section.  Generated
40*22d40dcfSBill Schmidt   // code uses the descriptor directly rather than going via the GOT as some
41*22d40dcfSBill Schmidt   // other ABIs do, which means that initialized function pointers must
42*22d40dcfSBill Schmidt   // reference the descriptor.  The linker must convert copy relocs of
43*22d40dcfSBill Schmidt   // pointers to functions in shared libraries into dynamic relocations,
44*22d40dcfSBill Schmidt   // because of an ordering problem with initialization of copy relocs and
45*22d40dcfSBill Schmidt   // PLT entries.  The dynamic relocation will be initialized by the dynamic
46*22d40dcfSBill Schmidt   // linker, so we must use the DataRelRO section instead of ReadOnlySection.
47*22d40dcfSBill Schmidt   // For more information, see the description of ELIMINATE_COPY_RELOCS in
48*22d40dcfSBill Schmidt   // GNU ld.
49*22d40dcfSBill Schmidt   const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
50*22d40dcfSBill Schmidt 
51*22d40dcfSBill Schmidt   if (GVar && GVar->isConstant() &&
52*22d40dcfSBill Schmidt       (GVar->getInitializer()->getRelocationInfo() ==
53*22d40dcfSBill Schmidt        Constant::GlobalRelocations))
54*22d40dcfSBill Schmidt     return DataRelROSection;
55*22d40dcfSBill Schmidt 
56*22d40dcfSBill Schmidt   return DefaultSection;
57*22d40dcfSBill Schmidt }
58