LLVM 22.0.0git
ObjCopy.cpp
Go to the documentation of this file.
1//===- Objcopy.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
23#include "llvm/Object/COFF.h"
26#include "llvm/Object/Error.h"
27#include "llvm/Object/MachO.h"
29#include "llvm/Object/Wasm.h"
31
32using namespace llvm;
33using namespace llvm::object;
34
35/// The function executeObjcopyOnBinary does the dispatch based on the format
36/// of the input binary (ELF, MachO or COFF).
38 object::Binary &In, raw_ostream &Out) {
39 if (auto *ELFBinary = dyn_cast<object::ELFObjectFileBase>(&In)) {
41 if (!ELFConfig)
42 return ELFConfig.takeError();
43
45 *ELFBinary, Out);
46 }
47 if (auto *COFFBinary = dyn_cast<object::COFFObjectFile>(&In)) {
49 if (!COFFConfig)
50 return COFFConfig.takeError();
51
53 *COFFBinary, Out);
54 }
55 if (auto *MachOBinary = dyn_cast<object::MachOObjectFile>(&In)) {
57 if (!MachOConfig)
58 return MachOConfig.takeError();
59
61 *MachOBinary, Out);
62 }
63 if (auto *MachOUniversalBinary =
66 Config, *MachOUniversalBinary, Out);
67 }
68 if (auto *WasmBinary = dyn_cast<object::WasmObjectFile>(&In)) {
70 if (!WasmConfig)
71 return WasmConfig.takeError();
72
74 *WasmConfig, *WasmBinary, Out);
75 }
76 if (auto *XCOFFBinary = dyn_cast<object::XCOFFObjectFile>(&In)) {
78 if (!XCOFFConfig)
79 return XCOFFConfig.takeError();
80
82 *XCOFFBinary, Out);
83 }
84 if (auto *DXContainerBinary = dyn_cast<object::DXContainerObjectFile>(&In)) {
86 Config.getDXContainerConfig();
88 return DXContainerConfig.takeError();
89
91 Config.getCommonConfig(), *DXContainerConfig, *DXContainerBinary, Out);
92 }
94 "unsupported object file format");
95}
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
virtual Expected< const XCOFFConfig & > getXCOFFConfig() const =0
virtual Expected< const WasmConfig & > getWasmConfig() const =0
virtual Expected< const ELFConfig & > getELFConfig() const =0
virtual Expected< const COFFConfig & > getCOFFConfig() const =0
virtual Expected< const MachOConfig & > getMachOConfig() const =0
virtual const CommonConfig & getCommonConfig() const =0
virtual Expected< const DXContainerConfig & > getDXContainerConfig() const =0
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
LLVM_ABI Error executeObjcopyOnBinary(const CommonConfig &Config, const COFFConfig &, object::COFFObjectFile &In, raw_ostream &Out)
Apply the transformations described by Config and COFFConfig to In and writes the result into Out.
Error executeObjcopyOnBinary(const CommonConfig &Config, const DXContainerConfig &, object::DXContainerObjectFile &In, raw_ostream &Out)
Apply the transformations described by Config and DXContainerConfig to In and writes the result into ...
LLVM_ABI Error executeObjcopyOnBinary(const CommonConfig &Config, const ELFConfig &ELFConfig, object::ELFObjectFileBase &In, raw_ostream &Out)
Apply the transformations described by Config and ELFConfig to In and writes the result into Out.
LLVM_ABI Error executeObjcopyOnBinary(const CommonConfig &Config, const MachOConfig &MachOConfig, object::MachOObjectFile &In, raw_ostream &Out)
Apply the transformations described by Config and MachOConfig to In and writes the result into Out.
LLVM_ABI Error executeObjcopyOnMachOUniversalBinary(const MultiFormatConfig &Config, const object::MachOUniversalBinary &In, raw_ostream &Out)
Apply the transformations described by Config and MachOConfig to In and writes the result into Out.
LLVM_ABI Error executeObjcopyOnBinary(const CommonConfig &Config, const WasmConfig &, object::WasmObjectFile &In, raw_ostream &Out)
Apply the transformations described by Config and WasmConfig to In and writes the result into Out.
Error executeObjcopyOnBinary(const CommonConfig &Config, const XCOFFConfig &, object::XCOFFObjectFile &In, raw_ostream &Out)
Apply the transformations described by Config and XCOFFConfig to In and writes the result into Out.
LLVM_ABI Error executeObjcopyOnBinary(const MultiFormatConfig &Config, object::Binary &In, raw_ostream &Out)
Applies the transformations described by Config to In and writes the result into Out.
Definition ObjCopy.cpp:37
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1305