PPCTargetObjectFile.cpp 2.4 KB

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