xref: /freebsd/contrib/llvm-project/llvm/lib/ObjCopy/ConfigManager.cpp (revision 5036d9652a5701d00e9e40ea942c278e9f77d33d)
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     return createStringError(llvm::errc::invalid_argument,
31                              "option is not supported for COFF");
32 
33   return COFF;
34 }
35 
36 Expected<const MachOConfig &> ConfigManager::getMachOConfig() const {
37   if (!Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
38       !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() ||
39       !Common.AllocSectionsPrefix.empty() || !Common.KeepSection.empty() ||
40       !Common.SymbolsToGlobalize.empty() || !Common.SymbolsToKeep.empty() ||
41       !Common.SymbolsToLocalize.empty() ||
42       !Common.SymbolsToKeepGlobal.empty() || !Common.SectionsToRename.empty() ||
43       !Common.UnneededSymbolsToRemove.empty() ||
44       !Common.SetSectionAlignment.empty() || !Common.SetSectionFlags.empty() ||
45       !Common.SetSectionType.empty() || Common.ExtractDWO ||
46       Common.PreserveDates || Common.StripAllGNU || Common.StripDWO ||
47       Common.StripNonAlloc || Common.StripSections ||
48       Common.DecompressDebugSections || Common.StripUnneeded ||
49       Common.DiscardMode == DiscardType::Locals ||
50       !Common.SymbolsToAdd.empty() || Common.GapFill != 0 ||
51       Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0)
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     return createStringError(llvm::errc::invalid_argument,
73                              "only flags for section dumping, removal, and "
74                              "addition are supported");
75 
76   return Wasm;
77 }
78 
79 Expected<const XCOFFConfig &> ConfigManager::getXCOFFConfig() const {
80   if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition ||
81       !Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
82       !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() ||
83       !Common.AllocSectionsPrefix.empty() ||
84       Common.DiscardMode != DiscardType::None || !Common.AddSection.empty() ||
85       !Common.DumpSection.empty() || !Common.SymbolsToAdd.empty() ||
86       !Common.KeepSection.empty() || !Common.OnlySection.empty() ||
87       !Common.ToRemove.empty() || !Common.SymbolsToGlobalize.empty() ||
88       !Common.SymbolsToKeep.empty() || !Common.SymbolsToLocalize.empty() ||
89       !Common.SymbolsToRemove.empty() ||
90       !Common.UnneededSymbolsToRemove.empty() ||
91       !Common.SymbolsToWeaken.empty() || !Common.SymbolsToKeepGlobal.empty() ||
92       !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() ||
93       !Common.SetSectionFlags.empty() || !Common.SetSectionType.empty() ||
94       !Common.SymbolsToRename.empty() || Common.ExtractDWO ||
95       Common.ExtractMainPartition || Common.OnlyKeepDebug ||
96       Common.PreserveDates || Common.StripAllGNU || Common.StripDWO ||
97       Common.StripDebug || Common.StripNonAlloc || Common.StripSections ||
98       Common.Weaken || Common.StripUnneeded || Common.DecompressDebugSections ||
99       Common.GapFill != 0 || Common.PadTo != 0 ||
100       Common.ChangeSectionLMAValAll != 0) {
101     return createStringError(
102         llvm::errc::invalid_argument,
103         "no flags are supported yet, only basic copying is allowed");
104   }
105 
106   return XCOFF;
107 }
108 
109 } // end namespace objcopy
110 } // end namespace llvm
111