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
44 return elf::executeObjcopyOnBinary(Config.getCommonConfig(), *ELFConfig,
45 *ELFBinary, Out);
46 }
47 if (auto *COFFBinary = dyn_cast<object::COFFObjectFile>(&In)) {
49 if (!COFFConfig)
50 return COFFConfig.takeError();
51
52 return coff::executeObjcopyOnBinary(Config.getCommonConfig(), *COFFConfig,
53 *COFFBinary, Out);
54 }
55 if (auto *MachOBinary = dyn_cast<object::MachOObjectFile>(&In)) {
57 if (!MachOConfig)
58 return MachOConfig.takeError();
59
60 return macho::executeObjcopyOnBinary(Config.getCommonConfig(), *MachOConfig,
61 *MachOBinary, Out);
62 }
63 if (auto *MachOUniversalBinary =
64 dyn_cast<object::MachOUniversalBinary>(&In)) {
65 return macho::executeObjcopyOnMachOUniversalBinary(
67 }
68 if (auto *WasmBinary = dyn_cast<object::WasmObjectFile>(&In)) {
70 if (!WasmConfig)
71 return WasmConfig.takeError();
72
73 return objcopy::wasm::executeObjcopyOnBinary(Config.getCommonConfig(),
74 *WasmConfig, *WasmBinary, Out);
75 }
76 if (auto *XCOFFBinary = dyn_cast<object::XCOFFObjectFile>(&In)) {
78 if (!XCOFFConfig)
79 return XCOFFConfig.takeError();
80
81 return xcoff::executeObjcopyOnBinary(Config.getCommonConfig(), *XCOFFConfig,
82 *XCOFFBinary, Out);
83 }
84 if (auto *DXContainerBinary = dyn_cast<object::DXContainerObjectFile>(&In)) {
86 Config.getDXContainerConfig();
88 return DXContainerConfig.takeError();
89
90 return dxbc::executeObjcopyOnBinary(
91 Config.getCommonConfig(), *DXContainerConfig, *DXContainerBinary, Out);
92 }
93 return createStringError(object_error::invalid_file_type,
94 "unsupported object file format");
95}
RelaxConfig Config
Definition: ELF_riscv.cpp:506
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
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 WasmConfig &, object::WasmObjectFile &In, raw_ostream &Out)
Apply the transformations described by Config and WasmConfig 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.
Definition: AddressRanges.h:18
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1305