xref: /llvm-project/llvm/lib/ObjCopy/ConfigManager.cpp (revision 334a5766d7591bfaadf6990b3d8568c9688e22a5)
1f75da0c8SAlexey Lapshin //===- ConfigManager.cpp --------------------------------------------------===//
2f75da0c8SAlexey Lapshin //
3f75da0c8SAlexey Lapshin // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4f75da0c8SAlexey Lapshin // See https://llvm.org/LICENSE.txt for license information.
5f75da0c8SAlexey Lapshin // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f75da0c8SAlexey Lapshin //
7f75da0c8SAlexey Lapshin //===----------------------------------------------------------------------===//
8f75da0c8SAlexey Lapshin 
9f75da0c8SAlexey Lapshin #include "llvm/ObjCopy/ConfigManager.h"
10f75da0c8SAlexey Lapshin #include "llvm/Support/Errc.h"
11f75da0c8SAlexey Lapshin #include "llvm/Support/Error.h"
12f75da0c8SAlexey Lapshin 
13f75da0c8SAlexey Lapshin namespace llvm {
14f75da0c8SAlexey Lapshin namespace objcopy {
15f75da0c8SAlexey Lapshin 
16f75da0c8SAlexey Lapshin Expected<const COFFConfig &> ConfigManager::getCOFFConfig() const {
17f75da0c8SAlexey Lapshin   if (!Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
184946cc37SIlia Kuklin       !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() ||
1900e6d0e9SSaleem Abdulrasool       !Common.AllocSectionsPrefix.empty() || !Common.KeepSection.empty() ||
2000e6d0e9SSaleem Abdulrasool       !Common.SymbolsToGlobalize.empty() || !Common.SymbolsToKeep.empty() ||
2100e6d0e9SSaleem Abdulrasool       !Common.SymbolsToLocalize.empty() || !Common.SymbolsToWeaken.empty() ||
2200e6d0e9SSaleem Abdulrasool       !Common.SymbolsToKeepGlobal.empty() || !Common.SectionsToRename.empty() ||
2300e6d0e9SSaleem Abdulrasool       !Common.SetSectionAlignment.empty() || !Common.SetSectionType.empty() ||
2400e6d0e9SSaleem Abdulrasool       Common.ExtractDWO || Common.PreserveDates || Common.StripDWO ||
2500e6d0e9SSaleem Abdulrasool       Common.StripNonAlloc || Common.StripSections || Common.Weaken ||
2600e6d0e9SSaleem Abdulrasool       Common.DecompressDebugSections ||
274070dffdSquic-akaryaki       Common.DiscardMode == DiscardType::Locals ||
2833200363SEleanor Bonnici       !Common.SymbolsToAdd.empty() || Common.GapFill != 0 ||
292b2f4ae0SEleanor Bonnici       Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 ||
302b2f4ae0SEleanor Bonnici       !Common.ChangeSectionAddress.empty())
31f75da0c8SAlexey Lapshin     return createStringError(llvm::errc::invalid_argument,
32f75da0c8SAlexey Lapshin                              "option is not supported for COFF");
33f75da0c8SAlexey Lapshin 
34f75da0c8SAlexey Lapshin   return COFF;
35f75da0c8SAlexey Lapshin }
36f75da0c8SAlexey Lapshin 
37f75da0c8SAlexey Lapshin Expected<const MachOConfig &> ConfigManager::getMachOConfig() const {
38f75da0c8SAlexey Lapshin   if (!Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
39*334a5766SRichard Dzenis       !Common.SymbolsPrefixRemove.empty() ||
40f75da0c8SAlexey Lapshin       !Common.AllocSectionsPrefix.empty() || !Common.KeepSection.empty() ||
41*334a5766SRichard Dzenis       !Common.SymbolsToKeep.empty() || !Common.SectionsToRename.empty() ||
42f75da0c8SAlexey Lapshin       !Common.UnneededSymbolsToRemove.empty() ||
43f75da0c8SAlexey Lapshin       !Common.SetSectionAlignment.empty() || !Common.SetSectionFlags.empty() ||
44b28412d5SFangrui Song       !Common.SetSectionType.empty() || Common.ExtractDWO ||
45b28412d5SFangrui Song       Common.PreserveDates || Common.StripAllGNU || Common.StripDWO ||
460807846aSDan Zimmerman       Common.StripNonAlloc || Common.StripSections ||
47b28412d5SFangrui Song       Common.DecompressDebugSections || Common.StripUnneeded ||
484070dffdSquic-akaryaki       Common.DiscardMode == DiscardType::Locals ||
4933200363SEleanor Bonnici       !Common.SymbolsToAdd.empty() || Common.GapFill != 0 ||
502b2f4ae0SEleanor Bonnici       Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 ||
512b2f4ae0SEleanor Bonnici       !Common.ChangeSectionAddress.empty())
52f75da0c8SAlexey Lapshin     return createStringError(llvm::errc::invalid_argument,
53f75da0c8SAlexey Lapshin                              "option is not supported for MachO");
54f75da0c8SAlexey Lapshin 
55f75da0c8SAlexey Lapshin   return MachO;
56f75da0c8SAlexey Lapshin }
57f75da0c8SAlexey Lapshin 
58f75da0c8SAlexey Lapshin Expected<const WasmConfig &> ConfigManager::getWasmConfig() const {
59f75da0c8SAlexey Lapshin   if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition ||
60f75da0c8SAlexey Lapshin       !Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
614946cc37SIlia Kuklin       !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() ||
62f75da0c8SAlexey Lapshin       !Common.AllocSectionsPrefix.empty() ||
63f75da0c8SAlexey Lapshin       Common.DiscardMode != DiscardType::None || !Common.SymbolsToAdd.empty() ||
64f75da0c8SAlexey Lapshin       !Common.SymbolsToGlobalize.empty() || !Common.SymbolsToLocalize.empty() ||
65f75da0c8SAlexey Lapshin       !Common.SymbolsToKeep.empty() || !Common.SymbolsToRemove.empty() ||
66f75da0c8SAlexey Lapshin       !Common.UnneededSymbolsToRemove.empty() ||
67f75da0c8SAlexey Lapshin       !Common.SymbolsToWeaken.empty() || !Common.SymbolsToKeepGlobal.empty() ||
68f75da0c8SAlexey Lapshin       !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() ||
69b28412d5SFangrui Song       !Common.SetSectionFlags.empty() || !Common.SetSectionType.empty() ||
704070dffdSquic-akaryaki       !Common.SymbolsToRename.empty() || Common.GapFill != 0 ||
712b2f4ae0SEleanor Bonnici       Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 ||
722b2f4ae0SEleanor Bonnici       !Common.ChangeSectionAddress.empty())
73f75da0c8SAlexey Lapshin     return createStringError(llvm::errc::invalid_argument,
74f75da0c8SAlexey Lapshin                              "only flags for section dumping, removal, and "
75f75da0c8SAlexey Lapshin                              "addition are supported");
76f75da0c8SAlexey Lapshin 
77f75da0c8SAlexey Lapshin   return Wasm;
78f75da0c8SAlexey Lapshin }
79f75da0c8SAlexey Lapshin 
8061835d19Sesmeyi Expected<const XCOFFConfig &> ConfigManager::getXCOFFConfig() const {
8161835d19Sesmeyi   if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition ||
8261835d19Sesmeyi       !Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||
834946cc37SIlia Kuklin       !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() ||
8461835d19Sesmeyi       !Common.AllocSectionsPrefix.empty() ||
8561835d19Sesmeyi       Common.DiscardMode != DiscardType::None || !Common.AddSection.empty() ||
8661835d19Sesmeyi       !Common.DumpSection.empty() || !Common.SymbolsToAdd.empty() ||
8761835d19Sesmeyi       !Common.KeepSection.empty() || !Common.OnlySection.empty() ||
8861835d19Sesmeyi       !Common.ToRemove.empty() || !Common.SymbolsToGlobalize.empty() ||
8961835d19Sesmeyi       !Common.SymbolsToKeep.empty() || !Common.SymbolsToLocalize.empty() ||
9061835d19Sesmeyi       !Common.SymbolsToRemove.empty() ||
9161835d19Sesmeyi       !Common.UnneededSymbolsToRemove.empty() ||
9261835d19Sesmeyi       !Common.SymbolsToWeaken.empty() || !Common.SymbolsToKeepGlobal.empty() ||
9361835d19Sesmeyi       !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() ||
94b28412d5SFangrui Song       !Common.SetSectionFlags.empty() || !Common.SetSectionType.empty() ||
95b28412d5SFangrui Song       !Common.SymbolsToRename.empty() || Common.ExtractDWO ||
96b28412d5SFangrui Song       Common.ExtractMainPartition || Common.OnlyKeepDebug ||
97b28412d5SFangrui Song       Common.PreserveDates || Common.StripAllGNU || Common.StripDWO ||
98b28412d5SFangrui Song       Common.StripDebug || Common.StripNonAlloc || Common.StripSections ||
994070dffdSquic-akaryaki       Common.Weaken || Common.StripUnneeded || Common.DecompressDebugSections ||
10033200363SEleanor Bonnici       Common.GapFill != 0 || Common.PadTo != 0 ||
1012b2f4ae0SEleanor Bonnici       Common.ChangeSectionLMAValAll != 0 ||
1022b2f4ae0SEleanor Bonnici       !Common.ChangeSectionAddress.empty()) {
10361835d19Sesmeyi     return createStringError(
10461835d19Sesmeyi         llvm::errc::invalid_argument,
10561835d19Sesmeyi         "no flags are supported yet, only basic copying is allowed");
10661835d19Sesmeyi   }
10761835d19Sesmeyi 
10861835d19Sesmeyi   return XCOFF;
10961835d19Sesmeyi }
11061835d19Sesmeyi 
111f75da0c8SAlexey Lapshin } // end namespace objcopy
112f75da0c8SAlexey Lapshin } // end namespace llvm
113