AArch64TargetObjectFile.cpp 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //===-- AArch64TargetObjectFile.cpp - AArch64 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 "AArch64TargetObjectFile.h"
  9. #include "AArch64TargetMachine.h"
  10. #include "llvm/BinaryFormat/Dwarf.h"
  11. #include "llvm/IR/Mangler.h"
  12. #include "llvm/MC/MCContext.h"
  13. #include "llvm/MC/MCExpr.h"
  14. #include "llvm/MC/MCStreamer.h"
  15. #include "llvm/MC/MCValue.h"
  16. using namespace llvm;
  17. using namespace dwarf;
  18. void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx,
  19. const TargetMachine &TM) {
  20. TargetLoweringObjectFileELF::Initialize(Ctx, TM);
  21. // AARCH64 ELF ABI does not define static relocation type for TLS offset
  22. // within a module. Do not generate AT_location for TLS variables.
  23. SupportDebugThreadLocalLocation = false;
  24. }
  25. AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile() {
  26. SupportGOTPCRelWithOffset = false;
  27. }
  28. const MCExpr *AArch64_MachoTargetObjectFile::getTTypeGlobalReference(
  29. const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
  30. MachineModuleInfo *MMI, MCStreamer &Streamer) const {
  31. // On Darwin, we can reference dwarf symbols with foo@GOT-., which
  32. // is an indirect pc-relative reference. The default implementation
  33. // won't reference using the GOT, so we need this target-specific
  34. // version.
  35. if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
  36. const MCSymbol *Sym = TM.getSymbol(GV);
  37. const MCExpr *Res =
  38. MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
  39. MCSymbol *PCSym = getContext().createTempSymbol();
  40. Streamer.emitLabel(PCSym);
  41. const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
  42. return MCBinaryExpr::createSub(Res, PC, getContext());
  43. }
  44. return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
  45. GV, Encoding, TM, MMI, Streamer);
  46. }
  47. MCSymbol *AArch64_MachoTargetObjectFile::getCFIPersonalitySymbol(
  48. const GlobalValue *GV, const TargetMachine &TM,
  49. MachineModuleInfo *MMI) const {
  50. return TM.getSymbol(GV);
  51. }
  52. const MCExpr *AArch64_MachoTargetObjectFile::getIndirectSymViaGOTPCRel(
  53. const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
  54. int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
  55. assert((Offset+MV.getConstant() == 0) &&
  56. "Arch64 does not support GOT PC rel with extra offset");
  57. // On ARM64 Darwin, we can reference symbols with foo@GOT-., which
  58. // is an indirect pc-relative reference.
  59. const MCExpr *Res =
  60. MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
  61. MCSymbol *PCSym = getContext().createTempSymbol();
  62. Streamer.emitLabel(PCSym);
  63. const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
  64. return MCBinaryExpr::createSub(Res, PC, getContext());
  65. }
  66. void AArch64_MachoTargetObjectFile::getNameWithPrefix(
  67. SmallVectorImpl<char> &OutName, const GlobalValue *GV,
  68. const TargetMachine &TM) const {
  69. // AArch64 does not use section-relative relocations so any global symbol must
  70. // be accessed via at least a linker-private symbol.
  71. getMangler().getNameWithPrefix(OutName, GV, /* CannotUsePrivateLabel */ true);
  72. }