LLVM API Documentation
00001 //===-- PPCTargetObjectFile.cpp - PPC Object Info -------------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #include "PPCTargetObjectFile.h" 00011 #include "llvm/IR/Mangler.h" 00012 #include "llvm/MC/MCContext.h" 00013 #include "llvm/MC/MCExpr.h" 00014 #include "llvm/MC/MCSectionELF.h" 00015 00016 using namespace llvm; 00017 00018 void 00019 PPC64LinuxTargetObjectFile:: 00020 Initialize(MCContext &Ctx, const TargetMachine &TM) { 00021 TargetLoweringObjectFileELF::Initialize(Ctx, TM); 00022 InitializeELF(TM.Options.UseInitArray); 00023 } 00024 00025 const MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal( 00026 const GlobalValue *GV, SectionKind Kind, Mangler &Mang, 00027 const TargetMachine &TM) const { 00028 // Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI 00029 // when we have a constant that contains global relocations. This is 00030 // necessary because of this ABI's handling of pointers to functions in 00031 // a shared library. The address of a function is actually the address 00032 // of a function descriptor, which resides in the .opd section. Generated 00033 // code uses the descriptor directly rather than going via the GOT as some 00034 // other ABIs do, which means that initialized function pointers must 00035 // reference the descriptor. The linker must convert copy relocs of 00036 // pointers to functions in shared libraries into dynamic relocations, 00037 // because of an ordering problem with initialization of copy relocs and 00038 // PLT entries. The dynamic relocation will be initialized by the dynamic 00039 // linker, so we must use DataRelROSection instead of ReadOnlySection. 00040 // For more information, see the description of ELIMINATE_COPY_RELOCS in 00041 // GNU ld. 00042 if (Kind.isReadOnly()) { 00043 const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV); 00044 00045 if (GVar && GVar->isConstant() && 00046 (GVar->getInitializer()->getRelocationInfo() == 00047 Constant::GlobalRelocations)) 00048 Kind = SectionKind::getReadOnlyWithRel(); 00049 } 00050 00051 return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, 00052 Mang, TM); 00053 } 00054 00055 const MCExpr *PPC64LinuxTargetObjectFile:: 00056 getDebugThreadLocalSymbol(const MCSymbol *Sym) const { 00057 const MCExpr *Expr = 00058 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_PPC_DTPREL, getContext()); 00059 return MCBinaryExpr::CreateAdd(Expr, 00060 MCConstantExpr::Create(0x8000, getContext()), 00061 getContext()); 00062 } 00063