MCELFObjectTargetWriter.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //===-- MCELFObjectTargetWriter.cpp - ELF Target Writer Subclass ----------===//
  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 "llvm/ADT/STLExtras.h"
  10. #include "llvm/MC/MCELFObjectWriter.h"
  11. #include "llvm/MC/MCExpr.h"
  12. #include "llvm/MC/MCValue.h"
  13. using namespace llvm;
  14. MCELFObjectTargetWriter::MCELFObjectTargetWriter(bool Is64Bit_,
  15. uint8_t OSABI_,
  16. uint16_t EMachine_,
  17. bool HasRelocationAddend_,
  18. bool IsN64_)
  19. : OSABI(OSABI_), EMachine(EMachine_),
  20. HasRelocationAddend(HasRelocationAddend_), Is64Bit(Is64Bit_),
  21. IsN64(IsN64_){
  22. }
  23. bool MCELFObjectTargetWriter::needsRelocateWithSymbol(const MCSymbol &Sym,
  24. unsigned Type) const {
  25. return false;
  26. }
  27. // ELF doesn't require relocations to be in any order. We sort by the Offset,
  28. // just to match gnu as for easier comparison. The use type is an arbitrary way
  29. // of making the sort deterministic.
  30. // HLSL Change: changed calling convention to __cdecl
  31. static int __cdecl cmpRel(const ELFRelocationEntry *AP, const ELFRelocationEntry *BP) {
  32. const ELFRelocationEntry &A = *AP;
  33. const ELFRelocationEntry &B = *BP;
  34. if (A.Offset != B.Offset)
  35. return B.Offset - A.Offset;
  36. if (B.Type != A.Type)
  37. return A.Type - B.Type;
  38. //llvm_unreachable("ELFRelocs might be unstable!");
  39. return 0;
  40. }
  41. void
  42. MCELFObjectTargetWriter::sortRelocs(const MCAssembler &Asm,
  43. std::vector<ELFRelocationEntry> &Relocs) {
  44. array_pod_sort(Relocs.begin(), Relocs.end(), cmpRel);
  45. }