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 getCOFFConfig() const16f75da0c8SAlexey LapshinExpected<const COFFConfig &> ConfigManager::getCOFFConfig() const { 17f75da0c8SAlexey Lapshin if (!Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() || 18f75da0c8SAlexey Lapshin !Common.AllocSectionsPrefix.empty() || !Common.DumpSection.empty() || 19f75da0c8SAlexey Lapshin !Common.KeepSection.empty() || !Common.SymbolsToGlobalize.empty() || 20f75da0c8SAlexey Lapshin !Common.SymbolsToKeep.empty() || !Common.SymbolsToLocalize.empty() || 21f75da0c8SAlexey Lapshin !Common.SymbolsToWeaken.empty() || !Common.SymbolsToKeepGlobal.empty() || 22f75da0c8SAlexey Lapshin !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() || 23*b28412d5SFangrui Song !Common.SetSectionType.empty() || Common.ExtractDWO || 24*b28412d5SFangrui Song Common.PreserveDates || Common.StripDWO || Common.StripNonAlloc || 25*b28412d5SFangrui Song Common.StripSections || Common.Weaken || Common.DecompressDebugSections || 26f75da0c8SAlexey Lapshin Common.DiscardMode == DiscardType::Locals || !Common.SymbolsToAdd.empty()) 27f75da0c8SAlexey Lapshin return createStringError(llvm::errc::invalid_argument, 28f75da0c8SAlexey Lapshin "option is not supported for COFF"); 29f75da0c8SAlexey Lapshin 30f75da0c8SAlexey Lapshin return COFF; 31f75da0c8SAlexey Lapshin } 32f75da0c8SAlexey Lapshin getMachOConfig() const33f75da0c8SAlexey LapshinExpected<const MachOConfig &> ConfigManager::getMachOConfig() const { 34f75da0c8SAlexey Lapshin if (!Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() || 35f75da0c8SAlexey Lapshin !Common.AllocSectionsPrefix.empty() || !Common.KeepSection.empty() || 36f75da0c8SAlexey Lapshin !Common.SymbolsToGlobalize.empty() || !Common.SymbolsToKeep.empty() || 37f75da0c8SAlexey Lapshin !Common.SymbolsToLocalize.empty() || !Common.SymbolsToWeaken.empty() || 38f75da0c8SAlexey Lapshin !Common.SymbolsToKeepGlobal.empty() || !Common.SectionsToRename.empty() || 39f75da0c8SAlexey Lapshin !Common.UnneededSymbolsToRemove.empty() || 40f75da0c8SAlexey Lapshin !Common.SetSectionAlignment.empty() || !Common.SetSectionFlags.empty() || 41*b28412d5SFangrui Song !Common.SetSectionType.empty() || Common.ExtractDWO || 42*b28412d5SFangrui Song Common.PreserveDates || Common.StripAllGNU || Common.StripDWO || 43*b28412d5SFangrui Song Common.StripNonAlloc || Common.StripSections || Common.Weaken || 44*b28412d5SFangrui Song Common.DecompressDebugSections || Common.StripUnneeded || 45f75da0c8SAlexey Lapshin Common.DiscardMode == DiscardType::Locals || !Common.SymbolsToAdd.empty()) 46f75da0c8SAlexey Lapshin return createStringError(llvm::errc::invalid_argument, 47f75da0c8SAlexey Lapshin "option is not supported for MachO"); 48f75da0c8SAlexey Lapshin 49f75da0c8SAlexey Lapshin return MachO; 50f75da0c8SAlexey Lapshin } 51f75da0c8SAlexey Lapshin getWasmConfig() const52f75da0c8SAlexey LapshinExpected<const WasmConfig &> ConfigManager::getWasmConfig() const { 53f75da0c8SAlexey Lapshin if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition || 54f75da0c8SAlexey Lapshin !Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() || 55f75da0c8SAlexey Lapshin !Common.AllocSectionsPrefix.empty() || 56f75da0c8SAlexey Lapshin Common.DiscardMode != DiscardType::None || !Common.SymbolsToAdd.empty() || 57f75da0c8SAlexey Lapshin !Common.SymbolsToGlobalize.empty() || !Common.SymbolsToLocalize.empty() || 58f75da0c8SAlexey Lapshin !Common.SymbolsToKeep.empty() || !Common.SymbolsToRemove.empty() || 59f75da0c8SAlexey Lapshin !Common.UnneededSymbolsToRemove.empty() || 60f75da0c8SAlexey Lapshin !Common.SymbolsToWeaken.empty() || !Common.SymbolsToKeepGlobal.empty() || 61f75da0c8SAlexey Lapshin !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() || 62*b28412d5SFangrui Song !Common.SetSectionFlags.empty() || !Common.SetSectionType.empty() || 63*b28412d5SFangrui Song !Common.SymbolsToRename.empty()) 64f75da0c8SAlexey Lapshin return createStringError(llvm::errc::invalid_argument, 65f75da0c8SAlexey Lapshin "only flags for section dumping, removal, and " 66f75da0c8SAlexey Lapshin "addition are supported"); 67f75da0c8SAlexey Lapshin 68f75da0c8SAlexey Lapshin return Wasm; 69f75da0c8SAlexey Lapshin } 70f75da0c8SAlexey Lapshin getXCOFFConfig() const7161835d19SesmeyiExpected<const XCOFFConfig &> ConfigManager::getXCOFFConfig() const { 7261835d19Sesmeyi if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition || 7361835d19Sesmeyi !Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() || 7461835d19Sesmeyi !Common.AllocSectionsPrefix.empty() || 7561835d19Sesmeyi Common.DiscardMode != DiscardType::None || !Common.AddSection.empty() || 7661835d19Sesmeyi !Common.DumpSection.empty() || !Common.SymbolsToAdd.empty() || 7761835d19Sesmeyi !Common.KeepSection.empty() || !Common.OnlySection.empty() || 7861835d19Sesmeyi !Common.ToRemove.empty() || !Common.SymbolsToGlobalize.empty() || 7961835d19Sesmeyi !Common.SymbolsToKeep.empty() || !Common.SymbolsToLocalize.empty() || 8061835d19Sesmeyi !Common.SymbolsToRemove.empty() || 8161835d19Sesmeyi !Common.UnneededSymbolsToRemove.empty() || 8261835d19Sesmeyi !Common.SymbolsToWeaken.empty() || !Common.SymbolsToKeepGlobal.empty() || 8361835d19Sesmeyi !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() || 84*b28412d5SFangrui Song !Common.SetSectionFlags.empty() || !Common.SetSectionType.empty() || 85*b28412d5SFangrui Song !Common.SymbolsToRename.empty() || Common.ExtractDWO || 86*b28412d5SFangrui Song Common.ExtractMainPartition || Common.OnlyKeepDebug || 87*b28412d5SFangrui Song Common.PreserveDates || Common.StripAllGNU || Common.StripDWO || 88*b28412d5SFangrui Song Common.StripDebug || Common.StripNonAlloc || Common.StripSections || 89*b28412d5SFangrui Song Common.Weaken || Common.StripUnneeded || Common.DecompressDebugSections) { 9061835d19Sesmeyi return createStringError( 9161835d19Sesmeyi llvm::errc::invalid_argument, 9261835d19Sesmeyi "no flags are supported yet, only basic copying is allowed"); 9361835d19Sesmeyi } 9461835d19Sesmeyi 9561835d19Sesmeyi return XCOFF; 9661835d19Sesmeyi } 9761835d19Sesmeyi 98f75da0c8SAlexey Lapshin } // end namespace objcopy 99f75da0c8SAlexey Lapshin } // end namespace llvm 100