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