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

source code of llvm/lib/ObjCopy/ConfigManager.cpp