blob: 90e4f1545250472819c118d42af6244bf36c20ce [file] [log] [blame]
Bill Schmidt240b9b62013-05-13 19:34:37 +00001//===-- 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
16using namespace llvm;
17
18void
19PPC64LinuxTargetObjectFile::
20Initialize(MCContext &Ctx, const TargetMachine &TM) {
21 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
22 InitializeELF(TM.Options.UseInitArray);
23}
24
25const MCSection * PPC64LinuxTargetObjectFile::
26SelectSectionForGlobal(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
Bill Schmidt59b078f2013-05-13 19:40:36 +000035 // Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI
Bill Schmidt240b9b62013-05-13 19:34:37 +000036 // 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
Bill Schmidt59b078f2013-05-13 19:40:36 +000046 // linker, so we must use DataRelROSection instead of ReadOnlySection.
Bill Schmidt240b9b62013-05-13 19:34:37 +000047 // 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}