122d40dcfSBill Schmidt //===-- PPCTargetObjectFile.cpp - PPC Object Info -------------------------===// 222d40dcfSBill Schmidt // 322d40dcfSBill Schmidt // The LLVM Compiler Infrastructure 422d40dcfSBill Schmidt // 522d40dcfSBill Schmidt // This file is distributed under the University of Illinois Open Source 622d40dcfSBill Schmidt // License. See LICENSE.TXT for details. 722d40dcfSBill Schmidt // 822d40dcfSBill Schmidt //===----------------------------------------------------------------------===// 922d40dcfSBill Schmidt 1022d40dcfSBill Schmidt #include "PPCTargetObjectFile.h" 11894843cbSRafael Espindola #include "llvm/IR/Mangler.h" 1222d40dcfSBill Schmidt #include "llvm/MC/MCContext.h" 1322d40dcfSBill Schmidt #include "llvm/MC/MCExpr.h" 1422d40dcfSBill Schmidt #include "llvm/MC/MCSectionELF.h" 1522d40dcfSBill Schmidt 1622d40dcfSBill Schmidt using namespace llvm; 1722d40dcfSBill Schmidt 1822d40dcfSBill Schmidt void 1922d40dcfSBill Schmidt PPC64LinuxTargetObjectFile:: 2022d40dcfSBill Schmidt Initialize(MCContext &Ctx, const TargetMachine &TM) { 2122d40dcfSBill Schmidt TargetLoweringObjectFileELF::Initialize(Ctx, TM); 2222d40dcfSBill Schmidt InitializeELF(TM.Options.UseInitArray); 2322d40dcfSBill Schmidt } 2422d40dcfSBill Schmidt 25*fa0f7283SRafael Espindola const MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal( 26*fa0f7283SRafael Espindola const GlobalValue *GV, SectionKind Kind, Mangler &Mang, 27*fa0f7283SRafael Espindola const TargetMachine &TM) const { 2822d40dcfSBill Schmidt 2922d40dcfSBill Schmidt const MCSection *DefaultSection = 3022d40dcfSBill Schmidt TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang, TM); 3122d40dcfSBill Schmidt 3222d40dcfSBill Schmidt if (DefaultSection != ReadOnlySection) 3322d40dcfSBill Schmidt return DefaultSection; 3422d40dcfSBill Schmidt 356cda22a3SBill Schmidt // Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI 3622d40dcfSBill Schmidt // when we have a constant that contains global relocations. This is 3722d40dcfSBill Schmidt // necessary because of this ABI's handling of pointers to functions in 3822d40dcfSBill Schmidt // a shared library. The address of a function is actually the address 3922d40dcfSBill Schmidt // of a function descriptor, which resides in the .opd section. Generated 4022d40dcfSBill Schmidt // code uses the descriptor directly rather than going via the GOT as some 4122d40dcfSBill Schmidt // other ABIs do, which means that initialized function pointers must 4222d40dcfSBill Schmidt // reference the descriptor. The linker must convert copy relocs of 4322d40dcfSBill Schmidt // pointers to functions in shared libraries into dynamic relocations, 4422d40dcfSBill Schmidt // because of an ordering problem with initialization of copy relocs and 4522d40dcfSBill Schmidt // PLT entries. The dynamic relocation will be initialized by the dynamic 466cda22a3SBill Schmidt // linker, so we must use DataRelROSection instead of ReadOnlySection. 4722d40dcfSBill Schmidt // For more information, see the description of ELIMINATE_COPY_RELOCS in 4822d40dcfSBill Schmidt // GNU ld. 4922d40dcfSBill Schmidt const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV); 5022d40dcfSBill Schmidt 5122d40dcfSBill Schmidt if (GVar && GVar->isConstant() && 5222d40dcfSBill Schmidt (GVar->getInitializer()->getRelocationInfo() == 5322d40dcfSBill Schmidt Constant::GlobalRelocations)) 5422d40dcfSBill Schmidt return DataRelROSection; 5522d40dcfSBill Schmidt 5622d40dcfSBill Schmidt return DefaultSection; 5722d40dcfSBill Schmidt } 580f039824SUlrich Weigand 590f039824SUlrich Weigand const MCExpr *PPC64LinuxTargetObjectFile:: 600f039824SUlrich Weigand getDebugThreadLocalSymbol(const MCSymbol *Sym) const { 610f039824SUlrich Weigand const MCExpr *Expr = 620f039824SUlrich Weigand MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_PPC_DTPREL, getContext()); 630f039824SUlrich Weigand return MCBinaryExpr::CreateAdd(Expr, 640f039824SUlrich Weigand MCConstantExpr::Create(0x8000, getContext()), 650f039824SUlrich Weigand getContext()); 660f039824SUlrich Weigand } 670f039824SUlrich Weigand 68