MachOUtils.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //===-- MachOUtils.h - Mach-o specific helpers for dsymutil --------------===//
  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. #ifndef LLVM_TOOLS_DSYMUTIL_MACHOUTILS_H
  9. #define LLVM_TOOLS_DSYMUTIL_MACHOUTILS_H
  10. #include "SymbolMap.h"
  11. #include "llvm/ADT/StringRef.h"
  12. #include "llvm/Support/FileSystem.h"
  13. #include "llvm/Support/VirtualFileSystem.h"
  14. #include <string>
  15. namespace llvm {
  16. class MCStreamer;
  17. class raw_fd_ostream;
  18. namespace dsymutil {
  19. class DebugMap;
  20. struct LinkOptions;
  21. namespace MachOUtils {
  22. struct ArchAndFile {
  23. std::string Arch;
  24. std::unique_ptr<llvm::sys::fs::TempFile> File;
  25. llvm::Error createTempFile();
  26. llvm::StringRef path() const;
  27. ArchAndFile(StringRef Arch) : Arch(std::string(Arch)) {}
  28. ArchAndFile(ArchAndFile &&A) = default;
  29. ArchAndFile &operator=(ArchAndFile &&A) = default;
  30. ~ArchAndFile();
  31. };
  32. struct DwarfRelocationApplicationInfo {
  33. // The position in the stream that should be patched, starting from the
  34. // Dwarf's segment file address.
  35. uint64_t AddressFromDwarfStart;
  36. int32_t Value;
  37. // If we should subtract the Dwarf segment's VM address from value before
  38. // writing it.
  39. bool ShouldSubtractDwarfVM;
  40. DwarfRelocationApplicationInfo(uint64_t AddressFromDwarfVM, uint32_t Value,
  41. bool ShouldSubtractDwarfVM)
  42. : AddressFromDwarfStart(AddressFromDwarfVM), Value(Value),
  43. ShouldSubtractDwarfVM(ShouldSubtractDwarfVM) {}
  44. };
  45. bool generateUniversalBinary(SmallVectorImpl<ArchAndFile> &ArchFiles,
  46. StringRef OutputFileName, const LinkOptions &,
  47. StringRef SDKPath);
  48. bool generateDsymCompanion(
  49. llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, const DebugMap &DM,
  50. SymbolMapTranslator &Translator, MCStreamer &MS, raw_fd_ostream &OutFile,
  51. const std::vector<MachOUtils::DwarfRelocationApplicationInfo>
  52. &RelocationsToApply);
  53. std::string getArchName(StringRef Arch);
  54. } // namespace MachOUtils
  55. } // namespace dsymutil
  56. } // namespace llvm
  57. #endif // LLVM_TOOLS_DSYMUTIL_MACHOUTILS_H