139 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/ObjCopy/ConfigManager.h"10#include "llvm/Support/Errc.h"11#include "llvm/Support/Error.h"12 13using namespace llvm;14using namespace llvm::objcopy;15 16Expected<const ELFConfig &> ConfigManager::getELFConfig() const {17 if (!Common.ExtractSection.empty())18 return createStringError(llvm::errc::invalid_argument,19 "option is not supported for ELF");20 return ELF;21}22 23Expected<const COFFConfig &> ConfigManager::getCOFFConfig() const {24 if (!Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||25 !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() ||26 !Common.AllocSectionsPrefix.empty() || !Common.KeepSection.empty() ||27 !Common.SymbolsToGlobalize.empty() || !Common.SymbolsToKeep.empty() ||28 !Common.SymbolsToLocalize.empty() || !Common.SymbolsToWeaken.empty() ||29 !Common.SymbolsToKeepGlobal.empty() || !Common.SectionsToRename.empty() ||30 !Common.SetSectionAlignment.empty() || !Common.SetSectionType.empty() ||31 Common.ExtractDWO || Common.PreserveDates || Common.StripDWO ||32 Common.StripNonAlloc || Common.StripSections || Common.Weaken ||33 Common.DecompressDebugSections ||34 Common.DiscardMode == DiscardType::Locals ||35 !Common.SymbolsToAdd.empty() || Common.GapFill != 0 ||36 Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 ||37 !Common.ChangeSectionAddress.empty() || !Common.ExtractSection.empty())38 return createStringError(llvm::errc::invalid_argument,39 "option is not supported for COFF");40 41 return COFF;42}43 44Expected<const MachOConfig &> ConfigManager::getMachOConfig() const {45 if (!Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||46 !Common.SymbolsPrefixRemove.empty() ||47 !Common.AllocSectionsPrefix.empty() || !Common.KeepSection.empty() ||48 !Common.SymbolsToKeep.empty() || !Common.SectionsToRename.empty() ||49 !Common.UnneededSymbolsToRemove.empty() ||50 !Common.SetSectionAlignment.empty() || !Common.SetSectionFlags.empty() ||51 !Common.SetSectionType.empty() || Common.ExtractDWO ||52 Common.PreserveDates || Common.StripAllGNU || Common.StripDWO ||53 Common.StripNonAlloc || Common.StripSections ||54 Common.DecompressDebugSections || Common.StripUnneeded ||55 Common.DiscardMode == DiscardType::Locals ||56 !Common.SymbolsToAdd.empty() || Common.GapFill != 0 ||57 Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 ||58 !Common.ChangeSectionAddress.empty() || !Common.ExtractSection.empty())59 return createStringError(llvm::errc::invalid_argument,60 "option is not supported for MachO");61 62 return MachO;63}64 65Expected<const WasmConfig &> ConfigManager::getWasmConfig() const {66 if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition ||67 !Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||68 !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() ||69 !Common.AllocSectionsPrefix.empty() ||70 Common.DiscardMode != DiscardType::None || !Common.SymbolsToAdd.empty() ||71 !Common.SymbolsToGlobalize.empty() || !Common.SymbolsToLocalize.empty() ||72 !Common.SymbolsToKeep.empty() || !Common.SymbolsToRemove.empty() ||73 !Common.UnneededSymbolsToRemove.empty() ||74 !Common.SymbolsToWeaken.empty() || !Common.SymbolsToKeepGlobal.empty() ||75 !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() ||76 !Common.SetSectionFlags.empty() || !Common.SetSectionType.empty() ||77 !Common.SymbolsToRename.empty() || Common.GapFill != 0 ||78 Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 ||79 !Common.ChangeSectionAddress.empty() || !Common.ExtractSection.empty())80 return createStringError(llvm::errc::invalid_argument,81 "only flags for section dumping, removal, and "82 "addition are supported");83 84 return Wasm;85}86 87Expected<const XCOFFConfig &> ConfigManager::getXCOFFConfig() const {88 if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition ||89 !Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() ||90 !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() ||91 !Common.AllocSectionsPrefix.empty() ||92 Common.DiscardMode != DiscardType::None || !Common.AddSection.empty() ||93 !Common.DumpSection.empty() || !Common.SymbolsToAdd.empty() ||94 !Common.KeepSection.empty() || !Common.OnlySection.empty() ||95 !Common.ToRemove.empty() || !Common.SymbolsToGlobalize.empty() ||96 !Common.SymbolsToKeep.empty() || !Common.SymbolsToLocalize.empty() ||97 !Common.SymbolsToRemove.empty() ||98 !Common.UnneededSymbolsToRemove.empty() ||99 !Common.SymbolsToWeaken.empty() || !Common.SymbolsToKeepGlobal.empty() ||100 !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() ||101 !Common.SetSectionFlags.empty() || !Common.SetSectionType.empty() ||102 !Common.SymbolsToRename.empty() || Common.ExtractDWO ||103 Common.ExtractMainPartition || Common.OnlyKeepDebug ||104 Common.PreserveDates || Common.StripAllGNU || Common.StripDWO ||105 Common.StripDebug || Common.StripNonAlloc || Common.StripSections ||106 Common.Weaken || Common.StripUnneeded || Common.DecompressDebugSections ||107 Common.GapFill != 0 || Common.PadTo != 0 ||108 Common.ChangeSectionLMAValAll != 0 ||109 !Common.ChangeSectionAddress.empty() || !Common.ExtractSection.empty()) {110 return createStringError(111 llvm::errc::invalid_argument,112 "no flags are supported yet, only basic copying is allowed");113 }114 115 return XCOFF;116}117 118Expected<const DXContainerConfig &>119ConfigManager::getDXContainerConfig() const {120 // All other flags are either supported or not applicable for DXContainer121 // object files and will be silently ignored.122 if (!Common.AddGnuDebugLink.empty() || !Common.SplitDWO.empty() ||123 !Common.AllocSectionsPrefix.empty() ||124 Common.DiscardMode != DiscardType::None || !Common.AddSection.empty() ||125 !Common.KeepSection.empty() || !Common.SectionsToRename.empty() ||126 !Common.SetSectionAlignment.empty() || !Common.SetSectionFlags.empty() ||127 !Common.SetSectionType.empty() || Common.ExtractDWO ||128 Common.OnlyKeepDebug || Common.StripAllGNU || Common.StripDWO ||129 Common.StripDebug || Common.StripNonAlloc || Common.StripSections ||130 Common.StripUnneeded || Common.DecompressDebugSections ||131 Common.GapFill != 0 || Common.PadTo != 0 ||132 Common.ChangeSectionLMAValAll != 0 ||133 !Common.ChangeSectionAddress.empty()) {134 return createStringError(llvm::errc::invalid_argument,135 "option is not supported for DXContainer");136 }137 return DXContainer;138}139