LLVM  16.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 
9 #include "llvm/ObjCopy/ObjCopy.h"
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 
31 namespace llvm {
32 namespace objcopy {
33 
34 using 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 
46  *ELFBinary, Out);
47  }
48  if (auto *COFFBinary = dyn_cast<object::COFFObjectFile>(&In)) {
50  if (!COFFConfig)
51  return COFFConfig.takeError();
52 
54  *COFFBinary, Out);
55  }
56  if (auto *MachOBinary = dyn_cast<object::MachOObjectFile>(&In)) {
58  if (!MachOConfig)
59  return MachOConfig.takeError();
60 
62  *MachOBinary, Out);
63  }
64  if (auto *MachOUniversalBinary =
65  dyn_cast<object::MachOUniversalBinary>(&In)) {
67  Config, *MachOUniversalBinary, Out);
68  }
69  if (auto *WasmBinary = dyn_cast<object::WasmObjectFile>(&In)) {
71  if (!WasmConfig)
72  return WasmConfig.takeError();
73 
75  *WasmConfig, *WasmBinary, Out);
76  }
77  if (auto *XCOFFBinary = dyn_cast<object::XCOFFObjectFile>(&In)) {
79  if (!XCOFFConfig)
80  return XCOFFConfig.takeError();
81 
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
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::objcopy::wasm::executeObjcopyOnBinary
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.
Definition: WasmObjcopy.cpp:142
MachOConfig.h
llvm::objcopy::MultiFormatConfig::getMachOConfig
virtual Expected< const MachOConfig & > getMachOConfig() const =0
COFFObjcopy.h
llvm::objcopy::coff::executeObjcopyOnBinary
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.
Definition: COFFObjcopy.cpp:292
MultiFormatConfig.h
SmallVectorMemoryBuffer.h
llvm::objcopy::macho::executeObjcopyOnMachOUniversalBinary
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.
Definition: MachOObjcopy.cpp:474
llvm::objcopy::executeObjcopyOnBinary
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
WasmConfig.h
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
MachO.h
llvm::objcopy::MultiFormatConfig::getCommonConfig
virtual const CommonConfig & getCommonConfig() const =0
llvm::objcopy::ELFConfig
Definition: ELFConfig.h:21
llvm::object
Definition: DWARFDebugLoc.h:25
Error.h
MachOUniversal.h
llvm::objcopy::MachOConfig
Definition: MachOConfig.h:21
XCOFFObjectFile.h
WasmObjcopy.h
llvm::objcopy::MultiFormatConfig::getXCOFFConfig
virtual Expected< const XCOFFConfig & > getXCOFFConfig() const =0
llvm::objcopy::COFFConfig
Definition: COFFConfig.h:18
llvm::objcopy::macho::executeObjcopyOnBinary
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.
Definition: MachOObjcopy.cpp:437
llvm::objcopy::elf::executeObjcopyOnBinary
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:803
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::objcopy::MultiFormatConfig
Definition: MultiFormatConfig.h:24
CommonConfig.h
Wasm.h
COFFConfig.h
llvm::tgtok::In
@ In
Definition: TGLexer.h:51
XCOFFConfig.h
llvm::objcopy::xcoff::executeObjcopyOnBinary
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.
Definition: XCOFFObjcopy.cpp:27
llvm::object::Binary
Definition: Binary.h:32
llvm::objcopy::WasmConfig
Definition: WasmConfig.h:16
MachOObjcopy.h
ELFConfig.h
ELFObjectFile.h
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1239
llvm::objcopy::MultiFormatConfig::getCOFFConfig
virtual Expected< const COFFConfig & > getCOFFConfig() const =0
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::objcopy::MultiFormatConfig::getELFConfig
virtual Expected< const ELFConfig & > getELFConfig() const =0
COFF.h
llvm::objcopy::MultiFormatConfig::getWasmConfig
virtual Expected< const WasmConfig & > getWasmConfig() const =0
XCOFFObjcopy.h
llvm::objcopy::XCOFFConfig
Definition: XCOFFConfig.h:16
ObjCopy.h
ELFObjcopy.h
llvm::object::MachOUniversalBinary
Definition: MachOUniversal.h:30