LinkUtils.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //===- tools/dsymutil/LinkUtils.h - Dwarf linker utilities ------*- C++ -*-===//
  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_LINKOPTIONS_H
  9. #define LLVM_TOOLS_DSYMUTIL_LINKOPTIONS_H
  10. #include "SymbolMap.h"
  11. #include "llvm/ADT/Twine.h"
  12. #include "llvm/Remarks/RemarkFormat.h"
  13. #include "llvm/Support/VirtualFileSystem.h"
  14. #include "llvm/Support/WithColor.h"
  15. #include "llvm/DWARFLinker/DWARFLinker.h"
  16. #include "llvm/DWARFLinker/DWARFStreamer.h"
  17. #include <string>
  18. namespace llvm {
  19. namespace dsymutil {
  20. enum class DsymutilAccelTableKind : uint8_t {
  21. None,
  22. Apple, ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc.
  23. Dwarf, ///< DWARF v5 .debug_names.
  24. Default, ///< Dwarf for DWARF5 or later, Apple otherwise.
  25. Pub, ///< .debug_pubnames, .debug_pubtypes
  26. };
  27. struct LinkOptions {
  28. /// Verbosity
  29. bool Verbose = false;
  30. /// Statistics
  31. bool Statistics = false;
  32. /// Verify the input DWARF.
  33. bool VerifyInputDWARF = false;
  34. /// Skip emitting output
  35. bool NoOutput = false;
  36. /// Do not unique types according to ODR
  37. bool NoODR = false;
  38. /// Update
  39. bool Update = false;
  40. /// Do not check swiftmodule timestamp
  41. bool NoTimestamp = false;
  42. /// Whether we want a static variable to force us to keep its enclosing
  43. /// function.
  44. bool KeepFunctionForStatic = false;
  45. /// Number of threads.
  46. unsigned Threads = 1;
  47. // Output file type.
  48. OutputFileType FileType = OutputFileType::Object;
  49. /// The accelerator table kind
  50. DsymutilAccelTableKind TheAccelTableKind;
  51. /// -oso-prepend-path
  52. std::string PrependPath;
  53. /// The -object-prefix-map.
  54. std::map<std::string, std::string> ObjectPrefixMap;
  55. /// The Resources directory in the .dSYM bundle.
  56. std::optional<std::string> ResourceDir;
  57. /// Symbol map translator.
  58. SymbolMapTranslator Translator;
  59. /// Virtual File System.
  60. llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
  61. vfs::getRealFileSystem();
  62. /// Fields used for linking and placing remarks into the .dSYM bundle.
  63. /// @{
  64. /// Number of debug maps processed in total.
  65. unsigned NumDebugMaps = 0;
  66. /// -remarks-prepend-path: prepend a path to all the external remark file
  67. /// paths found in remark metadata.
  68. std::string RemarksPrependPath;
  69. /// The output format of the remarks.
  70. remarks::Format RemarksFormat = remarks::Format::Bitstream;
  71. /// @}
  72. LinkOptions() = default;
  73. };
  74. inline void warn(Twine Warning, Twine Context = {}) {
  75. WithColor::warning() << Warning + "\n";
  76. if (!Context.isTriviallyEmpty())
  77. WithColor::note() << Twine("while processing ") + Context + "\n";
  78. }
  79. inline bool error(Twine Error, Twine Context = {}) {
  80. WithColor::error() << Error + "\n";
  81. if (!Context.isTriviallyEmpty())
  82. WithColor::note() << Twine("while processing ") + Context + "\n";
  83. return false;
  84. }
  85. } // end namespace dsymutil
  86. } // end namespace llvm
  87. #endif // LLVM_TOOLS_DSYMUTIL_LINKOPTIONS_H