LLVM 20.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
21#include "llvm/Object/COFF.h"
23#include "llvm/Object/Error.h"
24#include "llvm/Object/MachO.h"
26#include "llvm/Object/Wasm.h"
28
29namespace llvm {
30namespace objcopy {
31
32using namespace llvm::object;
33
34/// The function executeObjcopyOnBinary does the dispatch based on the format
35/// of the input binary (ELF, MachO or COFF).
37 object::Binary &In, raw_ostream &Out) {
38 if (auto *ELFBinary = dyn_cast<object::ELFObjectFileBase>(&In)) {
40 if (!ELFConfig)
41 return ELFConfig.takeError();
42
43 return elf::executeObjcopyOnBinary(Config.getCommonConfig(), *ELFConfig,
44 *ELFBinary, Out);
45 }
46 if (auto *COFFBinary = dyn_cast<object::COFFObjectFile>(&In)) {
48 if (!COFFConfig)
49 return COFFConfig.takeError();
50
51 return coff::executeObjcopyOnBinary(Config.getCommonConfig(), *COFFConfig,
52 *COFFBinary, Out);
53 }
54 if (auto *MachOBinary = dyn_cast<object::MachOObjectFile>(&In)) {
56 if (!MachOConfig)
57 return MachOConfig.takeError();
58
59 return macho::executeObjcopyOnBinary(Config.getCommonConfig(), *MachOConfig,
60 *MachOBinary, Out);
61 }
62 if (auto *MachOUniversalBinary =
63 dyn_cast<object::MachOUniversalBinary>(&In)) {
66 }
67 if (auto *WasmBinary = dyn_cast<object::WasmObjectFile>(&In)) {
69 if (!WasmConfig)
70 return WasmConfig.takeError();
71
72 return objcopy::wasm::executeObjcopyOnBinary(Config.getCommonConfig(),
73 *WasmConfig, *WasmBinary, Out);
74 }
75 if (auto *XCOFFBinary = dyn_cast<object::XCOFFObjectFile>(&In)) {
77 if (!XCOFFConfig)
78 return XCOFFConfig.takeError();
79
80 return xcoff::executeObjcopyOnBinary(Config.getCommonConfig(), *XCOFFConfig,
81 *XCOFFBinary, Out);
82 }
83 return createStringError(object_error::invalid_file_type,
84 "unsupported object file format");
85}
86
87} // end namespace objcopy
88} // 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:481
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:966
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:36
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:1291