LLVM 19.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
22#include "llvm/Object/COFF.h"
24#include "llvm/Object/Error.h"
25#include "llvm/Object/MachO.h"
27#include "llvm/Object/Wasm.h"
30
31namespace llvm {
32namespace objcopy {
33
34using namespace llvm::object;
35
36/// The function executeObjcopyOnBinary does the dispatch based on the format
37/// of the input binary (ELF, MachO or COFF).
39 object::Binary &In, raw_ostream &Out) {
40 if (auto *ELFBinary = dyn_cast<object::ELFObjectFileBase>(&In)) {
42 if (!ELFConfig)
43 return ELFConfig.takeError();
44
45 return elf::executeObjcopyOnBinary(Config.getCommonConfig(), *ELFConfig,
46 *ELFBinary, Out);
47 }
48 if (auto *COFFBinary = dyn_cast<object::COFFObjectFile>(&In)) {
50 if (!COFFConfig)
51 return COFFConfig.takeError();
52
53 return coff::executeObjcopyOnBinary(Config.getCommonConfig(), *COFFConfig,
54 *COFFBinary, Out);
55 }
56 if (auto *MachOBinary = dyn_cast<object::MachOObjectFile>(&In)) {
58 if (!MachOConfig)
59 return MachOConfig.takeError();
60
61 return macho::executeObjcopyOnBinary(Config.getCommonConfig(), *MachOConfig,
62 *MachOBinary, Out);
63 }
64 if (auto *MachOUniversalBinary =
65 dyn_cast<object::MachOUniversalBinary>(&In)) {
68 }
69 if (auto *WasmBinary = dyn_cast<object::WasmObjectFile>(&In)) {
71 if (!WasmConfig)
72 return WasmConfig.takeError();
73
74 return objcopy::wasm::executeObjcopyOnBinary(Config.getCommonConfig(),
75 *WasmConfig, *WasmBinary, Out);
76 }
77 if (auto *XCOFFBinary = dyn_cast<object::XCOFFObjectFile>(&In)) {
79 if (!XCOFFConfig)
80 return XCOFFConfig.takeError();
81
82 return xcoff::executeObjcopyOnBinary(Config.getCommonConfig(), *XCOFFConfig,
83 *XCOFFBinary, Out);
84 }
85 return createStringError(object_error::invalid_file_type,
86 "unsupported object file format");
87}
88
89} // end namespace objcopy
90} // end namespace llvm
RelaxConfig Config
Definition: ELF_riscv.cpp:506
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Tagged union holding either a T or a Error.
Definition: Error.h:474
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
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 ELFConfig &ELFConfig, object::ELFObjectFileBase &In, raw_ostream &Out)
Apply the transformations described by Config and ELFConfig to In and writes the result into Out.
Definition: ELFObjcopy.cpp:839
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.
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.
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.
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:38
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:1258