PPCTargetObjectFile.cpp revision b843060ecfa29efb5f896350f6530fa81184e420
1240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt//===-- PPCTargetObjectFile.cpp - PPC Object Info -------------------------===// 2240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt// 3240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt// The LLVM Compiler Infrastructure 4240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt// 5240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt// This file is distributed under the University of Illinois Open Source 6240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt// License. See LICENSE.TXT for details. 7240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt// 8240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt//===----------------------------------------------------------------------===// 9240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt 10240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt#include "PPCTargetObjectFile.h" 11240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt#include "llvm/MC/MCContext.h" 12240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt#include "llvm/MC/MCExpr.h" 13240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt#include "llvm/MC/MCSectionELF.h" 14240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt#include "llvm/Target/Mangler.h" 15240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt 16240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidtusing namespace llvm; 17240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt 18240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidtvoid 19240b9b6078cdf8048945107b4ff7d517729dab96Bill SchmidtPPC64LinuxTargetObjectFile:: 20240b9b6078cdf8048945107b4ff7d517729dab96Bill SchmidtInitialize(MCContext &Ctx, const TargetMachine &TM) { 21240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt TargetLoweringObjectFileELF::Initialize(Ctx, TM); 22240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt InitializeELF(TM.Options.UseInitArray); 23240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt} 24240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt 25240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidtconst MCSection * PPC64LinuxTargetObjectFile:: 26240b9b6078cdf8048945107b4ff7d517729dab96Bill SchmidtSelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, 27240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt Mangler *Mang, const TargetMachine &TM) const { 28240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt 29240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt const MCSection *DefaultSection = 30240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, Mang, TM); 31240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt 32240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt if (DefaultSection != ReadOnlySection) 33240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt return DefaultSection; 34240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt 3559b078fc56e64b9b2d13521670648034cd870c0fBill Schmidt // Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI 36240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // when we have a constant that contains global relocations. This is 37240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // necessary because of this ABI's handling of pointers to functions in 38240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // a shared library. The address of a function is actually the address 39240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // of a function descriptor, which resides in the .opd section. Generated 40240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // code uses the descriptor directly rather than going via the GOT as some 41240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // other ABIs do, which means that initialized function pointers must 42240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // reference the descriptor. The linker must convert copy relocs of 43240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // pointers to functions in shared libraries into dynamic relocations, 44240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // because of an ordering problem with initialization of copy relocs and 45240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // PLT entries. The dynamic relocation will be initialized by the dynamic 4659b078fc56e64b9b2d13521670648034cd870c0fBill Schmidt // linker, so we must use DataRelROSection instead of ReadOnlySection. 47240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // For more information, see the description of ELIMINATE_COPY_RELOCS in 48240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // GNU ld. 49240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV); 50240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt 51240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt if (GVar && GVar->isConstant() && 52240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt (GVar->getInitializer()->getRelocationInfo() == 53240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt Constant::GlobalRelocations)) 54240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt return DataRelROSection; 55240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt 56240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt return DefaultSection; 57240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt} 58b843060ecfa29efb5f896350f6530fa81184e420Ulrich Weigand 59b843060ecfa29efb5f896350f6530fa81184e420Ulrich Weigandconst MCExpr *PPC64LinuxTargetObjectFile:: 60b843060ecfa29efb5f896350f6530fa81184e420Ulrich WeigandgetDebugThreadLocalSymbol(const MCSymbol *Sym) const { 61b843060ecfa29efb5f896350f6530fa81184e420Ulrich Weigand const MCExpr *Expr = 62b843060ecfa29efb5f896350f6530fa81184e420Ulrich Weigand MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_PPC_DTPREL, getContext()); 63b843060ecfa29efb5f896350f6530fa81184e420Ulrich Weigand return MCBinaryExpr::CreateAdd(Expr, 64b843060ecfa29efb5f896350f6530fa81184e420Ulrich Weigand MCConstantExpr::Create(0x8000, getContext()), 65b843060ecfa29efb5f896350f6530fa81184e420Ulrich Weigand getContext()); 66b843060ecfa29efb5f896350f6530fa81184e420Ulrich Weigand} 67b843060ecfa29efb5f896350f6530fa81184e420Ulrich Weigand 68