ConfigManager.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //===- ConfigManager.cpp --------------------------------------------------===//
  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 "llvm/ObjCopy/ConfigManager.h"
  9. #include "llvm/Support/Errc.h"
  10. #include "llvm/Support/Error.h"
  11. namespace llvm {
  12. namespace objcopy {
  13. Expected<const COFFConfig &> ConfigManager::getCOFFConfig() const {
  14. if (!Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
  15. !Common.AllocSectionsPrefix.empty() || !Common.DumpSection.empty() ||
  16. !Common.KeepSection.empty() || !Common.SymbolsToGlobalize.empty() ||
  17. !Common.SymbolsToKeep.empty() || !Common.SymbolsToLocalize.empty() ||
  18. !Common.SymbolsToWeaken.empty() || !Common.SymbolsToKeepGlobal.empty() ||
  19. !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() ||
  20. !Common.SetSectionType.empty() || Common.ExtractDWO ||
  21. Common.PreserveDates || Common.StripDWO || Common.StripNonAlloc ||
  22. Common.StripSections || Common.Weaken || Common.DecompressDebugSections ||
  23. Common.DiscardMode == DiscardType::Locals || !Common.SymbolsToAdd.empty())
  24. return createStringError(llvm::errc::invalid_argument,
  25. "option is not supported for COFF");
  26. return COFF;
  27. }
  28. Expected<const MachOConfig &> ConfigManager::getMachOConfig() const {
  29. if (!Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
  30. !Common.AllocSectionsPrefix.empty() || !Common.KeepSection.empty() ||
  31. !Common.SymbolsToGlobalize.empty() || !Common.SymbolsToKeep.empty() ||
  32. !Common.SymbolsToLocalize.empty() || !Common.SymbolsToWeaken.empty() ||
  33. !Common.SymbolsToKeepGlobal.empty() || !Common.SectionsToRename.empty() ||
  34. !Common.UnneededSymbolsToRemove.empty() ||
  35. !Common.SetSectionAlignment.empty() || !Common.SetSectionFlags.empty() ||
  36. !Common.SetSectionType.empty() || Common.ExtractDWO ||
  37. Common.PreserveDates || Common.StripAllGNU || Common.StripDWO ||
  38. Common.StripNonAlloc || Common.StripSections || Common.Weaken ||
  39. Common.DecompressDebugSections || Common.StripUnneeded ||
  40. Common.DiscardMode == DiscardType::Locals || !Common.SymbolsToAdd.empty())
  41. return createStringError(llvm::errc::invalid_argument,
  42. "option is not supported for MachO");
  43. return MachO;
  44. }
  45. Expected<const WasmConfig &> ConfigManager::getWasmConfig() const {
  46. if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition ||
  47. !Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
  48. !Common.AllocSectionsPrefix.empty() ||
  49. Common.DiscardMode != DiscardType::None || !Common.SymbolsToAdd.empty() ||
  50. !Common.SymbolsToGlobalize.empty() || !Common.SymbolsToLocalize.empty() ||
  51. !Common.SymbolsToKeep.empty() || !Common.SymbolsToRemove.empty() ||
  52. !Common.UnneededSymbolsToRemove.empty() ||
  53. !Common.SymbolsToWeaken.empty() || !Common.SymbolsToKeepGlobal.empty() ||
  54. !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() ||
  55. !Common.SetSectionFlags.empty() || !Common.SetSectionType.empty() ||
  56. !Common.SymbolsToRename.empty())
  57. return createStringError(llvm::errc::invalid_argument,
  58. "only flags for section dumping, removal, and "
  59. "addition are supported");
  60. return Wasm;
  61. }
  62. Expected<const XCOFFConfig &> ConfigManager::getXCOFFConfig() const {
  63. if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition ||
  64. !Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
  65. !Common.AllocSectionsPrefix.empty() ||
  66. Common.DiscardMode != DiscardType::None || !Common.AddSection.empty() ||
  67. !Common.DumpSection.empty() || !Common.SymbolsToAdd.empty() ||
  68. !Common.KeepSection.empty() || !Common.OnlySection.empty() ||
  69. !Common.ToRemove.empty() || !Common.SymbolsToGlobalize.empty() ||
  70. !Common.SymbolsToKeep.empty() || !Common.SymbolsToLocalize.empty() ||
  71. !Common.SymbolsToRemove.empty() ||
  72. !Common.UnneededSymbolsToRemove.empty() ||
  73. !Common.SymbolsToWeaken.empty() || !Common.SymbolsToKeepGlobal.empty() ||
  74. !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() ||
  75. !Common.SetSectionFlags.empty() || !Common.SetSectionType.empty() ||
  76. !Common.SymbolsToRename.empty() || Common.ExtractDWO ||
  77. Common.ExtractMainPartition || Common.OnlyKeepDebug ||
  78. Common.PreserveDates || Common.StripAllGNU || Common.StripDWO ||
  79. Common.StripDebug || Common.StripNonAlloc || Common.StripSections ||
  80. Common.Weaken || Common.StripUnneeded || Common.DecompressDebugSections) {
  81. return createStringError(
  82. llvm::errc::invalid_argument,
  83. "no flags are supported yet, only basic copying is allowed");
  84. }
  85. return XCOFF;
  86. }
  87. } // end namespace objcopy
  88. } // end namespace llvm