PPCTargetObjectFile.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //===-- PPCTargetObjectFile.cpp - PPC Object Info -------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "PPCTargetObjectFile.h"
  9. #include "llvm/IR/GlobalVariable.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. }
  20. MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal(
  21. const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
  22. // Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI
  23. // when we have a constant that contains global relocations. This is
  24. // necessary because of this ABI's handling of pointers to functions in
  25. // a shared library. The address of a function is actually the address
  26. // of a function descriptor, which resides in the .opd section. Generated
  27. // code uses the descriptor directly rather than going via the GOT as some
  28. // other ABIs do, which means that initialized function pointers must
  29. // reference the descriptor. The linker must convert copy relocs of
  30. // pointers to functions in shared libraries into dynamic relocations,
  31. // because of an ordering problem with initialization of copy relocs and
  32. // PLT entries. The dynamic relocation will be initialized by the dynamic
  33. // linker, so we must use DataRelROSection instead of ReadOnlySection.
  34. // For more information, see the description of ELIMINATE_COPY_RELOCS in
  35. // GNU ld.
  36. if (Kind.isReadOnly()) {
  37. const auto *GVar = dyn_cast<GlobalVariable>(GO);
  38. if (GVar && GVar->isConstant() &&
  39. GVar->getInitializer()->needsDynamicRelocation())
  40. Kind = SectionKind::getReadOnlyWithRel();
  41. }
  42. return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, 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. }