1 //===-- PPCTargetObjectFile.cpp - PPC Object Info -------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
19 PPC64LinuxTargetObjectFile::
20 Initialize(MCContext &Ctx, const TargetMachine &TM) {
21 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
22 InitializeELF(TM.Options.UseInitArray);
25 const MCSection * PPC64LinuxTargetObjectFile::
26 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
27 Mangler *Mang, const TargetMachine &TM) const {
29 const MCSection *DefaultSection =
30 TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang, TM);
32 if (DefaultSection != ReadOnlySection)
33 return DefaultSection;
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
49 const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
51 if (GVar && GVar->isConstant() &&
52 (GVar->getInitializer()->getRelocationInfo() ==
53 Constant::GlobalRelocations))
54 return DataRelROSection;
56 return DefaultSection;