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