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