CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
110 lines
4.4 KiB
C++
110 lines
4.4 KiB
C++
//===- Objcopy.cpp --------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/ObjCopy/ObjCopy.h"
|
|
#include "llvm/ObjCopy/COFF/COFFConfig.h"
|
|
#include "llvm/ObjCopy/COFF/COFFObjcopy.h"
|
|
#include "llvm/ObjCopy/DXContainer/DXContainerConfig.h"
|
|
#include "llvm/ObjCopy/DXContainer/DXContainerObjcopy.h"
|
|
#include "llvm/ObjCopy/ELF/ELFConfig.h"
|
|
#include "llvm/ObjCopy/ELF/ELFObjcopy.h"
|
|
#include "llvm/ObjCopy/MachO/MachOConfig.h"
|
|
#include "llvm/ObjCopy/MachO/MachOObjcopy.h"
|
|
#include "llvm/ObjCopy/MultiFormatConfig.h"
|
|
#include "llvm/ObjCopy/XCOFF/XCOFFConfig.h"
|
|
#include "llvm/ObjCopy/XCOFF/XCOFFObjcopy.h"
|
|
#include "llvm/ObjCopy/wasm/WasmConfig.h"
|
|
#include "llvm/ObjCopy/wasm/WasmObjcopy.h"
|
|
#include "llvm/Object/COFF.h"
|
|
#include "llvm/Object/DXContainer.h"
|
|
#include "llvm/Object/ELFObjectFile.h"
|
|
#include "llvm/Object/Error.h"
|
|
#include "llvm/Object/MachO.h"
|
|
#include "llvm/Object/MachOUniversal.h"
|
|
#include "llvm/Object/Wasm.h"
|
|
#include "llvm/Object/XCOFFObjectFile.h"
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::object;
|
|
|
|
StringRef objcopy::getObjectFormatName(const object::Binary &B) {
|
|
if (const auto *OF = dyn_cast<ObjectFile>(&B))
|
|
return OF->getFileFormatName();
|
|
return {};
|
|
}
|
|
|
|
void objcopy::printCopyMessage(StringRef InPath, StringRef InFormatName,
|
|
StringRef OutPath, StringRef OutFormatName) {
|
|
if (OutFormatName.empty())
|
|
OutFormatName = InFormatName;
|
|
outs() << "copy from '" << InPath << "' [" << InFormatName << "] to '"
|
|
<< OutPath << "' [" << OutFormatName << "]\n";
|
|
}
|
|
|
|
/// The function executeObjcopyOnBinary does the dispatch based on the format
|
|
/// of the input binary (ELF, MachO or COFF).
|
|
Error objcopy::executeObjcopyOnBinary(const MultiFormatConfig &Config,
|
|
object::Binary &In, raw_ostream &Out) {
|
|
if (auto *ELFBinary = dyn_cast<object::ELFObjectFileBase>(&In)) {
|
|
Expected<const ELFConfig &> ELFConfig = Config.getELFConfig();
|
|
if (!ELFConfig)
|
|
return ELFConfig.takeError();
|
|
|
|
return elf::executeObjcopyOnBinary(Config.getCommonConfig(), *ELFConfig,
|
|
*ELFBinary, Out);
|
|
}
|
|
if (auto *COFFBinary = dyn_cast<object::COFFObjectFile>(&In)) {
|
|
Expected<const COFFConfig &> COFFConfig = Config.getCOFFConfig();
|
|
if (!COFFConfig)
|
|
return COFFConfig.takeError();
|
|
|
|
return coff::executeObjcopyOnBinary(Config.getCommonConfig(), *COFFConfig,
|
|
*COFFBinary, Out);
|
|
}
|
|
if (auto *MachOBinary = dyn_cast<object::MachOObjectFile>(&In)) {
|
|
Expected<const MachOConfig &> MachOConfig = Config.getMachOConfig();
|
|
if (!MachOConfig)
|
|
return MachOConfig.takeError();
|
|
|
|
return macho::executeObjcopyOnBinary(Config.getCommonConfig(), *MachOConfig,
|
|
*MachOBinary, Out);
|
|
}
|
|
if (auto *MachOUniversalBinary =
|
|
dyn_cast<object::MachOUniversalBinary>(&In)) {
|
|
return macho::executeObjcopyOnMachOUniversalBinary(
|
|
Config, *MachOUniversalBinary, Out);
|
|
}
|
|
if (auto *WasmBinary = dyn_cast<object::WasmObjectFile>(&In)) {
|
|
Expected<const WasmConfig &> WasmConfig = Config.getWasmConfig();
|
|
if (!WasmConfig)
|
|
return WasmConfig.takeError();
|
|
|
|
return objcopy::wasm::executeObjcopyOnBinary(Config.getCommonConfig(),
|
|
*WasmConfig, *WasmBinary, Out);
|
|
}
|
|
if (auto *XCOFFBinary = dyn_cast<object::XCOFFObjectFile>(&In)) {
|
|
Expected<const XCOFFConfig &> XCOFFConfig = Config.getXCOFFConfig();
|
|
if (!XCOFFConfig)
|
|
return XCOFFConfig.takeError();
|
|
|
|
return xcoff::executeObjcopyOnBinary(Config.getCommonConfig(), *XCOFFConfig,
|
|
*XCOFFBinary, Out);
|
|
}
|
|
if (auto *DXContainerBinary = dyn_cast<object::DXContainerObjectFile>(&In)) {
|
|
Expected<const DXContainerConfig &> DXContainerConfig =
|
|
Config.getDXContainerConfig();
|
|
if (!DXContainerConfig)
|
|
return DXContainerConfig.takeError();
|
|
|
|
return dxbc::executeObjcopyOnBinary(
|
|
Config.getCommonConfig(), *DXContainerConfig, *DXContainerBinary, Out);
|
|
}
|
|
return createStringError(object_error::invalid_file_type,
|
|
"unsupported object file format");
|
|
}
|