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