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" 1136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/IR/Mangler.h" 12240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt#include "llvm/MC/MCContext.h" 13240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt#include "llvm/MC/MCExpr.h" 14240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt#include "llvm/MC/MCSectionELF.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 256948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga NainarMCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal( 2636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines const GlobalValue *GV, SectionKind Kind, Mangler &Mang, 2736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines const TargetMachine &TM) const { 2859b078fc56e64b9b2d13521670648034cd870c0fBill Schmidt // Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI 29240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // when we have a constant that contains global relocations. This is 30240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // necessary because of this ABI's handling of pointers to functions in 31240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // a shared library. The address of a function is actually the address 32240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // of a function descriptor, which resides in the .opd section. Generated 33240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // code uses the descriptor directly rather than going via the GOT as some 34240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // other ABIs do, which means that initialized function pointers must 35240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // reference the descriptor. The linker must convert copy relocs of 36240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // pointers to functions in shared libraries into dynamic relocations, 37240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // because of an ordering problem with initialization of copy relocs and 38240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // PLT entries. The dynamic relocation will be initialized by the dynamic 3959b078fc56e64b9b2d13521670648034cd870c0fBill Schmidt // linker, so we must use DataRelROSection instead of ReadOnlySection. 40240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // For more information, see the description of ELIMINATE_COPY_RELOCS in 41240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt // GNU ld. 4236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines if (Kind.isReadOnly()) { 4336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV); 44240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt 45f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar if (GVar && GVar->isConstant() && GVar->getInitializer()->needsRelocation()) 4636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Kind = SectionKind::getReadOnlyWithRel(); 4736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 48240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt 4936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, 5036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Mang, TM); 51240b9b6078cdf8048945107b4ff7d517729dab96Bill Schmidt} 52b843060ecfa29efb5f896350f6530fa81184e420Ulrich Weigand 53b843060ecfa29efb5f896350f6530fa81184e420Ulrich Weigandconst MCExpr *PPC64LinuxTargetObjectFile:: 54b843060ecfa29efb5f896350f6530fa81184e420Ulrich WeigandgetDebugThreadLocalSymbol(const MCSymbol *Sym) const { 55b843060ecfa29efb5f896350f6530fa81184e420Ulrich Weigand const MCExpr *Expr = 56de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_DTPREL, getContext()); 576948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar return MCBinaryExpr::createAdd(Expr, 586948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar MCConstantExpr::create(0x8000, getContext()), 59b843060ecfa29efb5f896350f6530fa81184e420Ulrich Weigand getContext()); 60b843060ecfa29efb5f896350f6530fa81184e420Ulrich Weigand} 61b843060ecfa29efb5f896350f6530fa81184e420Ulrich Weigand 62