X86TargetObjectFile.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //===-- X86TargetObjectFile.cpp - X86 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 "X86TargetObjectFile.h"
  9. #include "llvm/BinaryFormat/Dwarf.h"
  10. #include "llvm/MC/MCExpr.h"
  11. #include "llvm/MC/MCValue.h"
  12. #include "llvm/Target/TargetMachine.h"
  13. using namespace llvm;
  14. using namespace dwarf;
  15. const MCExpr *X86_64MachoTargetObjectFile::getTTypeGlobalReference(
  16. const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
  17. MachineModuleInfo *MMI, MCStreamer &Streamer) const {
  18. // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
  19. // is an indirect pc-relative reference.
  20. if ((Encoding & DW_EH_PE_indirect) && (Encoding & DW_EH_PE_pcrel)) {
  21. const MCSymbol *Sym = TM.getSymbol(GV);
  22. const MCExpr *Res =
  23. MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
  24. const MCExpr *Four = MCConstantExpr::create(4, getContext());
  25. return MCBinaryExpr::createAdd(Res, Four, getContext());
  26. }
  27. return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
  28. GV, Encoding, TM, MMI, Streamer);
  29. }
  30. MCSymbol *X86_64MachoTargetObjectFile::getCFIPersonalitySymbol(
  31. const GlobalValue *GV, const TargetMachine &TM,
  32. MachineModuleInfo *MMI) const {
  33. return TM.getSymbol(GV);
  34. }
  35. const MCExpr *X86_64MachoTargetObjectFile::getIndirectSymViaGOTPCRel(
  36. const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
  37. int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
  38. // On Darwin/X86-64, we need to use foo@GOTPCREL+4 to access the got entry
  39. // from a data section. In case there's an additional offset, then use
  40. // foo@GOTPCREL+4+<offset>.
  41. unsigned FinalOff = Offset+MV.getConstant()+4;
  42. const MCExpr *Res =
  43. MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
  44. const MCExpr *Off = MCConstantExpr::create(FinalOff, getContext());
  45. return MCBinaryExpr::createAdd(Res, Off, getContext());
  46. }
  47. const MCExpr *X86ELFTargetObjectFile::getDebugThreadLocalSymbol(
  48. const MCSymbol *Sym) const {
  49. return MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_DTPOFF, getContext());
  50. }