xref: /llvm-project/llvm/lib/ObjCopy/ConfigManager.cpp (revision 334a5766d7591bfaadf6990b3d8568c9688e22a5)
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.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() ||
19       !Common.AllocSectionsPrefix.empty() || !Common.KeepSection.empty() ||
20       !Common.SymbolsToGlobalize.empty() || !Common.SymbolsToKeep.empty() ||
21       !Common.SymbolsToLocalize.empty() || !Common.SymbolsToWeaken.empty() ||
22       !Common.SymbolsToKeepGlobal.empty() || !Common.SectionsToRename.empty() ||
23       !Common.SetSectionAlignment.empty() || !Common.SetSectionType.empty() ||
24       Common.ExtractDWO || Common.PreserveDates || Common.StripDWO ||
25       Common.StripNonAlloc || Common.StripSections || Common.Weaken ||
26       Common.DecompressDebugSections ||
27       Common.DiscardMode == DiscardType::Locals ||
28       !Common.SymbolsToAdd.empty() || Common.GapFill != 0 ||
29       Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 ||
30       !Common.ChangeSectionAddress.empty())
31     return createStringError(llvm::errc::invalid_argument,
32                              "option is not supported for COFF");
33 
34   return COFF;
35 }
36 
37 Expected<const MachOConfig &> ConfigManager::getMachOConfig() const {
38   if (!Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
39       !Common.SymbolsPrefixRemove.empty() ||
40       !Common.AllocSectionsPrefix.empty() || !Common.KeepSection.empty() ||
41       !Common.SymbolsToKeep.empty() || !Common.SectionsToRename.empty() ||
42       !Common.UnneededSymbolsToRemove.empty() ||
43       !Common.SetSectionAlignment.empty() || !Common.SetSectionFlags.empty() ||
44       !Common.SetSectionType.empty() || Common.ExtractDWO ||
45       Common.PreserveDates || Common.StripAllGNU || Common.StripDWO ||
46       Common.StripNonAlloc || Common.StripSections ||
47       Common.DecompressDebugSections || Common.StripUnneeded ||
48       Common.DiscardMode == DiscardType::Locals ||
49       !Common.SymbolsToAdd.empty() || Common.GapFill != 0 ||
50       Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 ||
51       !Common.ChangeSectionAddress.empty())
52     return createStringError(llvm::errc::invalid_argument,
53                              "option is not supported for MachO");
54 
55   return MachO;
56 }
57 
58 Expected<const WasmConfig &> ConfigManager::getWasmConfig() const {
59   if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition ||
60       !Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
61       !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() ||
62       !Common.AllocSectionsPrefix.empty() ||
63       Common.DiscardMode != DiscardType::None || !Common.SymbolsToAdd.empty() ||
64       !Common.SymbolsToGlobalize.empty() || !Common.SymbolsToLocalize.empty() ||
65       !Common.SymbolsToKeep.empty() || !Common.SymbolsToRemove.empty() ||
66       !Common.UnneededSymbolsToRemove.empty() ||
67       !Common.SymbolsToWeaken.empty() || !Common.SymbolsToKeepGlobal.empty() ||
68       !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() ||
69       !Common.SetSectionFlags.empty() || !Common.SetSectionType.empty() ||
70       !Common.SymbolsToRename.empty() || Common.GapFill != 0 ||
71       Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 ||
72       !Common.ChangeSectionAddress.empty())
73     return createStringError(llvm::errc::invalid_argument,
74                              "only flags for section dumping, removal, and "
75                              "addition are supported");
76 
77   return Wasm;
78 }
79 
80 Expected<const XCOFFConfig &> ConfigManager::getXCOFFConfig() const {
81   if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition ||
82       !Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
83       !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() ||
84       !Common.AllocSectionsPrefix.empty() ||
85       Common.DiscardMode != DiscardType::None || !Common.AddSection.empty() ||
86       !Common.DumpSection.empty() || !Common.SymbolsToAdd.empty() ||
87       !Common.KeepSection.empty() || !Common.OnlySection.empty() ||
88       !Common.ToRemove.empty() || !Common.SymbolsToGlobalize.empty() ||
89       !Common.SymbolsToKeep.empty() || !Common.SymbolsToLocalize.empty() ||
90       !Common.SymbolsToRemove.empty() ||
91       !Common.UnneededSymbolsToRemove.empty() ||
92       !Common.SymbolsToWeaken.empty() || !Common.SymbolsToKeepGlobal.empty() ||
93       !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() ||
94       !Common.SetSectionFlags.empty() || !Common.SetSectionType.empty() ||
95       !Common.SymbolsToRename.empty() || Common.ExtractDWO ||
96       Common.ExtractMainPartition || Common.OnlyKeepDebug ||
97       Common.PreserveDates || Common.StripAllGNU || Common.StripDWO ||
98       Common.StripDebug || Common.StripNonAlloc || Common.StripSections ||
99       Common.Weaken || Common.StripUnneeded || Common.DecompressDebugSections ||
100       Common.GapFill != 0 || Common.PadTo != 0 ||
101       Common.ChangeSectionLMAValAll != 0 ||
102       !Common.ChangeSectionAddress.empty()) {
103     return createStringError(
104         llvm::errc::invalid_argument,
105         "no flags are supported yet, only basic copying is allowed");
106   }
107 
108   return XCOFF;
109 }
110 
111 } // end namespace objcopy
112 } // end namespace llvm
113