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