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