2017-11-01 21:16:06 +00:00
|
|
|
//===- llvm-objcopy.cpp ---------------------------------------------------===//
|
2017-08-01 00:33:58 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// 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
|
2017-08-01 00:33:58 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2017-11-01 21:16:06 +00:00
|
|
|
|
[llvm-objcopy][NFC] Move core implementation of llvm-objcopy into separate library.
This patch moves core implementation of llvm-objcopy into Object library
(http://lists.llvm.org/pipermail/llvm-dev/2020-September/145075.html).
The functionality for parsing input options is left inside tools/llvm-objcopy.
The interface of ObjCopy library:
ObjCopy/ELF/ELFObjcopy.h
```
Error executeObjcopyOnIHex(const CopyConfig &Config, MemoryBuffer &In,
Buffer &Out);
Error executeObjcopyOnRawBinary(const CopyConfig &Config, MemoryBuffer &In,
Buffer &Out);
Error executeObjcopyOnBinary(const CopyConfig &Config,
object::ELFObjectFileBase &In, Buffer &Out);
```
ObjCopy/COFF/COFFObjcopy.h
```
Error executeObjcopyOnBinary(const CopyConfig &Config,
object::COFFObjectFile &In, Buffer &Out);
```
ObjCopy/MachO/MachOObjcopy.h
```
Error executeObjcopyOnBinary(const CopyConfig &Config,
object::MachOObjectFile &In, Buffer &Out);
```
ObjCopy/wasm/WasmObjcopy.h
```
Error executeObjcopyOnBinary(const CopyConfig &Config,
object::WasmObjectFile &In, Buffer &Out);
```
Differential Revision: https://reviews.llvm.org/D88827
2022-02-11 21:42:40 +03:00
|
|
|
#include "ObjcopyOptions.h"
|
2017-11-01 21:16:06 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2018-08-01 16:23:22 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2017-11-01 21:16:06 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
2020-10-24 17:35:55 +03:00
|
|
|
#include "llvm/BinaryFormat/ELF.h"
|
[llvm-objcopy][NFC] Move core implementation of llvm-objcopy into separate library.
This patch moves core implementation of llvm-objcopy into Object library
(http://lists.llvm.org/pipermail/llvm-dev/2020-September/145075.html).
The functionality for parsing input options is left inside tools/llvm-objcopy.
The interface of ObjCopy library:
ObjCopy/ELF/ELFObjcopy.h
```
Error executeObjcopyOnIHex(const CopyConfig &Config, MemoryBuffer &In,
Buffer &Out);
Error executeObjcopyOnRawBinary(const CopyConfig &Config, MemoryBuffer &In,
Buffer &Out);
Error executeObjcopyOnBinary(const CopyConfig &Config,
object::ELFObjectFileBase &In, Buffer &Out);
```
ObjCopy/COFF/COFFObjcopy.h
```
Error executeObjcopyOnBinary(const CopyConfig &Config,
object::COFFObjectFile &In, Buffer &Out);
```
ObjCopy/MachO/MachOObjcopy.h
```
Error executeObjcopyOnBinary(const CopyConfig &Config,
object::MachOObjectFile &In, Buffer &Out);
```
ObjCopy/wasm/WasmObjcopy.h
```
Error executeObjcopyOnBinary(const CopyConfig &Config,
object::WasmObjectFile &In, Buffer &Out);
```
Differential Revision: https://reviews.llvm.org/D88827
2022-02-11 21:42:40 +03:00
|
|
|
#include "llvm/ObjCopy/COFF/COFFConfig.h"
|
|
|
|
#include "llvm/ObjCopy/COFF/COFFObjcopy.h"
|
|
|
|
#include "llvm/ObjCopy/CommonConfig.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/ObjCopy.h"
|
|
|
|
#include "llvm/ObjCopy/wasm/WasmConfig.h"
|
|
|
|
#include "llvm/ObjCopy/wasm/WasmObjcopy.h"
|
2018-07-06 17:51:03 +00:00
|
|
|
#include "llvm/Object/Archive.h"
|
|
|
|
#include "llvm/Object/ArchiveWriter.h"
|
2017-11-01 21:16:06 +00:00
|
|
|
#include "llvm/Object/Binary.h"
|
2018-12-19 07:24:38 +00:00
|
|
|
#include "llvm/Object/COFF.h"
|
2017-11-01 21:16:06 +00:00
|
|
|
#include "llvm/Object/ELFObjectFile.h"
|
|
|
|
#include "llvm/Object/ELFTypes.h"
|
|
|
|
#include "llvm/Object/Error.h"
|
2019-02-02 00:38:07 +00:00
|
|
|
#include "llvm/Object/MachO.h"
|
2020-10-06 03:41:19 -07:00
|
|
|
#include "llvm/Object/MachOUniversal.h"
|
2020-01-29 17:30:57 -08:00
|
|
|
#include "llvm/Object/Wasm.h"
|
2018-04-24 05:43:32 +00:00
|
|
|
#include "llvm/Option/Arg.h"
|
|
|
|
#include "llvm/Option/ArgList.h"
|
|
|
|
#include "llvm/Option/Option.h"
|
2017-11-01 21:16:06 +00:00
|
|
|
#include "llvm/Support/Casting.h"
|
2019-09-14 01:14:43 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2020-10-24 17:35:55 +03:00
|
|
|
#include "llvm/Support/Errc.h"
|
2017-11-01 21:16:06 +00:00
|
|
|
#include "llvm/Support/Error.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/ErrorOr.h"
|
2022-04-13 23:40:27 +03:00
|
|
|
#include "llvm/Support/FileUtilities.h"
|
2020-03-11 15:39:28 -07:00
|
|
|
#include "llvm/Support/Host.h"
|
2018-04-13 18:26:06 +00:00
|
|
|
#include "llvm/Support/InitLLVM.h"
|
[llvm-objcopy] Add support for -I binary -B <arch>.
Summary:
The -I (--input-target) and -B (--binary-architecture) flags exist but are currently silently ignored. This adds support for -I binary for architectures i386, x86-64 (and alias i386:x86-64), arm, aarch64, sparc, and ppc (powerpc:common64). This is largely based on D41687.
This is done by implementing an additional subclass of Reader, BinaryReader, which works by interpreting the input file as contents for .data field, sets up a synthetic header, and adds additional sections/symbols (e.g. _binary__tmp_data_txt_start).
Reviewers: jakehehrlich, alexshap, jhenderson, javed.absar
Reviewed By: jhenderson
Subscribers: jyknight, nemanjai, kbarton, fedor.sergeev, jrtc27, kristof.beyls, paulsemel, llvm-commits
Differential Revision: https://reviews.llvm.org/D50343
llvm-svn: 340070
2018-08-17 18:51:11 +00:00
|
|
|
#include "llvm/Support/Memory.h"
|
2018-05-07 19:32:09 +00:00
|
|
|
#include "llvm/Support/Path.h"
|
2018-08-16 18:29:40 +00:00
|
|
|
#include "llvm/Support/Process.h"
|
2020-10-24 17:35:55 +03:00
|
|
|
#include "llvm/Support/SmallVectorMemoryBuffer.h"
|
2019-09-14 01:14:43 +00:00
|
|
|
#include "llvm/Support/StringSaver.h"
|
2018-08-09 22:52:03 +00:00
|
|
|
#include "llvm/Support/WithColor.h"
|
2017-11-01 21:16:06 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdlib>
|
2017-08-01 00:33:58 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <system_error>
|
2017-11-01 21:16:06 +00:00
|
|
|
#include <utility>
|
2017-08-01 00:33:58 +00:00
|
|
|
|
2021-06-21 23:49:25 -07:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::objcopy;
|
|
|
|
using namespace llvm::object;
|
2018-07-18 00:10:51 +00:00
|
|
|
|
|
|
|
// The name this program was invoked as.
|
2021-06-21 23:49:25 -07:00
|
|
|
static StringRef ToolName;
|
2018-07-18 00:10:51 +00:00
|
|
|
|
2021-06-21 23:49:25 -07:00
|
|
|
static ErrorSuccess reportWarning(Error E) {
|
2019-06-18 00:39:10 +00:00
|
|
|
assert(E);
|
2019-08-20 15:00:07 +00:00
|
|
|
WithColor::warning(errs(), ToolName) << toString(std::move(E)) << '\n';
|
2019-06-18 00:39:10 +00:00
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2020-10-22 23:13:49 -07:00
|
|
|
static Expected<DriverConfig> getDriverConfig(ArrayRef<const char *> Args) {
|
|
|
|
StringRef Stem = sys::path::stem(ToolName);
|
|
|
|
auto Is = [=](StringRef Tool) {
|
|
|
|
// We need to recognize the following filenames:
|
|
|
|
//
|
|
|
|
// llvm-objcopy -> objcopy
|
|
|
|
// strip-10.exe -> strip
|
|
|
|
// powerpc64-unknown-freebsd13-objcopy -> objcopy
|
|
|
|
// llvm-install-name-tool -> install-name-tool
|
2021-06-23 14:52:36 +03:00
|
|
|
auto I = Stem.rfind_insensitive(Tool);
|
2020-10-22 23:13:49 -07:00
|
|
|
return I != StringRef::npos &&
|
|
|
|
(I + Tool.size() == Stem.size() || !isAlnum(Stem[I + Tool.size()]));
|
|
|
|
};
|
|
|
|
|
|
|
|
if (Is("bitcode-strip") || Is("bitcode_strip"))
|
2022-03-04 13:24:37 -08:00
|
|
|
return parseBitcodeStripOptions(Args, reportWarning);
|
2020-10-22 23:13:49 -07:00
|
|
|
else if (Is("strip"))
|
|
|
|
return parseStripOptions(Args, reportWarning);
|
|
|
|
else if (Is("install-name-tool") || Is("install_name_tool"))
|
|
|
|
return parseInstallNameToolOptions(Args);
|
|
|
|
else
|
|
|
|
return parseObjcopyOptions(Args, reportWarning);
|
|
|
|
}
|
|
|
|
|
2019-06-13 09:56:14 +00:00
|
|
|
/// The function executeObjcopyOnIHex does the dispatch based on the format
|
|
|
|
/// of the output specified by the command line options.
|
2021-04-23 14:19:11 +03:00
|
|
|
static Error executeObjcopyOnIHex(ConfigManager &ConfigMgr, MemoryBuffer &In,
|
2020-10-24 17:35:55 +03:00
|
|
|
raw_ostream &Out) {
|
2019-06-13 09:56:14 +00:00
|
|
|
// TODO: support output formats other than ELF.
|
2021-04-23 14:19:11 +03:00
|
|
|
Expected<const ELFConfig &> ELFConfig = ConfigMgr.getELFConfig();
|
|
|
|
if (!ELFConfig)
|
|
|
|
return ELFConfig.takeError();
|
|
|
|
|
|
|
|
return elf::executeObjcopyOnIHex(ConfigMgr.getCommonConfig(), *ELFConfig, In,
|
|
|
|
Out);
|
2019-06-13 09:56:14 +00:00
|
|
|
}
|
|
|
|
|
2018-10-24 22:49:06 +00:00
|
|
|
/// The function executeObjcopyOnRawBinary does the dispatch based on the format
|
|
|
|
/// of the output specified by the command line options.
|
2021-04-23 14:19:11 +03:00
|
|
|
static Error executeObjcopyOnRawBinary(ConfigManager &ConfigMgr,
|
|
|
|
MemoryBuffer &In, raw_ostream &Out) {
|
|
|
|
const CommonConfig &Config = ConfigMgr.getCommonConfig();
|
2019-07-05 05:28:38 +00:00
|
|
|
switch (Config.OutputFormat) {
|
|
|
|
case FileFormat::ELF:
|
|
|
|
// FIXME: Currently, we call elf::executeObjcopyOnRawBinary even if the
|
|
|
|
// output format is binary/ihex or it's not given. This behavior differs from
|
|
|
|
// GNU objcopy. See https://bugs.llvm.org/show_bug.cgi?id=42171 for details.
|
|
|
|
case FileFormat::Binary:
|
|
|
|
case FileFormat::IHex:
|
|
|
|
case FileFormat::Unspecified:
|
2021-04-23 14:19:11 +03:00
|
|
|
Expected<const ELFConfig &> ELFConfig = ConfigMgr.getELFConfig();
|
|
|
|
if (!ELFConfig)
|
|
|
|
return ELFConfig.takeError();
|
|
|
|
|
|
|
|
return elf::executeObjcopyOnRawBinary(Config, *ELFConfig, In, Out);
|
2019-07-05 05:28:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("unsupported output format");
|
2018-10-24 22:49:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// The function executeObjcopy does the higher level dispatch based on the type
|
|
|
|
/// of input (raw binary, archive or single object file) and takes care of the
|
|
|
|
/// format-agnostic modifications, i.e. preserving dates.
|
2021-04-23 14:19:11 +03:00
|
|
|
static Error executeObjcopy(ConfigManager &ConfigMgr) {
|
|
|
|
CommonConfig &Config = ConfigMgr.Common;
|
|
|
|
|
2022-04-26 12:45:28 +03:00
|
|
|
Expected<FilePermissionsApplier> PermsApplierOrErr =
|
2022-04-13 23:40:27 +03:00
|
|
|
FilePermissionsApplier::create(Config.InputFilename);
|
2022-04-26 12:45:28 +03:00
|
|
|
if (!PermsApplierOrErr)
|
|
|
|
return PermsApplierOrErr.takeError();
|
2018-08-16 18:29:40 +00:00
|
|
|
|
2021-03-12 01:31:06 +03:00
|
|
|
std::function<Error(raw_ostream & OutFile)> ObjcopyFunc;
|
2019-06-13 09:56:14 +00:00
|
|
|
|
2021-03-12 01:31:06 +03:00
|
|
|
OwningBinary<llvm::object::Binary> BinaryHolder;
|
|
|
|
std::unique_ptr<MemoryBuffer> MemoryBufferHolder;
|
|
|
|
|
|
|
|
if (Config.InputFormat == FileFormat::Binary ||
|
|
|
|
Config.InputFormat == FileFormat::IHex) {
|
|
|
|
ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr =
|
|
|
|
MemoryBuffer::getFileOrSTDIN(Config.InputFilename);
|
[llvm-objcopy] Add support for -I binary -B <arch>.
Summary:
The -I (--input-target) and -B (--binary-architecture) flags exist but are currently silently ignored. This adds support for -I binary for architectures i386, x86-64 (and alias i386:x86-64), arm, aarch64, sparc, and ppc (powerpc:common64). This is largely based on D41687.
This is done by implementing an additional subclass of Reader, BinaryReader, which works by interpreting the input file as contents for .data field, sets up a synthetic header, and adds additional sections/symbols (e.g. _binary__tmp_data_txt_start).
Reviewers: jakehehrlich, alexshap, jhenderson, javed.absar
Reviewed By: jhenderson
Subscribers: jyknight, nemanjai, kbarton, fedor.sergeev, jrtc27, kristof.beyls, paulsemel, llvm-commits
Differential Revision: https://reviews.llvm.org/D50343
llvm-svn: 340070
2018-08-17 18:51:11 +00:00
|
|
|
if (!BufOrErr)
|
2019-02-21 17:05:19 +00:00
|
|
|
return createFileError(Config.InputFilename, BufOrErr.getError());
|
2021-03-12 01:31:06 +03:00
|
|
|
MemoryBufferHolder = std::move(*BufOrErr);
|
|
|
|
|
|
|
|
if (Config.InputFormat == FileFormat::Binary)
|
|
|
|
ObjcopyFunc = [&](raw_ostream &OutFile) -> Error {
|
|
|
|
// Handle FileFormat::Binary.
|
2021-04-23 14:19:11 +03:00
|
|
|
return executeObjcopyOnRawBinary(ConfigMgr, *MemoryBufferHolder,
|
|
|
|
OutFile);
|
2021-03-12 01:31:06 +03:00
|
|
|
};
|
|
|
|
else
|
|
|
|
ObjcopyFunc = [&](raw_ostream &OutFile) -> Error {
|
|
|
|
// Handle FileFormat::IHex.
|
2021-04-23 14:19:11 +03:00
|
|
|
return executeObjcopyOnIHex(ConfigMgr, *MemoryBufferHolder, OutFile);
|
2021-03-12 01:31:06 +03:00
|
|
|
};
|
[llvm-objcopy] Add support for -I binary -B <arch>.
Summary:
The -I (--input-target) and -B (--binary-architecture) flags exist but are currently silently ignored. This adds support for -I binary for architectures i386, x86-64 (and alias i386:x86-64), arm, aarch64, sparc, and ppc (powerpc:common64). This is largely based on D41687.
This is done by implementing an additional subclass of Reader, BinaryReader, which works by interpreting the input file as contents for .data field, sets up a synthetic header, and adds additional sections/symbols (e.g. _binary__tmp_data_txt_start).
Reviewers: jakehehrlich, alexshap, jhenderson, javed.absar
Reviewed By: jhenderson
Subscribers: jyknight, nemanjai, kbarton, fedor.sergeev, jrtc27, kristof.beyls, paulsemel, llvm-commits
Differential Revision: https://reviews.llvm.org/D50343
llvm-svn: 340070
2018-08-17 18:51:11 +00:00
|
|
|
} else {
|
|
|
|
Expected<OwningBinary<llvm::object::Binary>> BinaryOrErr =
|
|
|
|
createBinary(Config.InputFilename);
|
|
|
|
if (!BinaryOrErr)
|
2019-02-21 17:05:19 +00:00
|
|
|
return createFileError(Config.InputFilename, BinaryOrErr.takeError());
|
2021-03-12 01:31:06 +03:00
|
|
|
BinaryHolder = std::move(*BinaryOrErr);
|
[llvm-objcopy] Add support for -I binary -B <arch>.
Summary:
The -I (--input-target) and -B (--binary-architecture) flags exist but are currently silently ignored. This adds support for -I binary for architectures i386, x86-64 (and alias i386:x86-64), arm, aarch64, sparc, and ppc (powerpc:common64). This is largely based on D41687.
This is done by implementing an additional subclass of Reader, BinaryReader, which works by interpreting the input file as contents for .data field, sets up a synthetic header, and adds additional sections/symbols (e.g. _binary__tmp_data_txt_start).
Reviewers: jakehehrlich, alexshap, jhenderson, javed.absar
Reviewed By: jhenderson
Subscribers: jyknight, nemanjai, kbarton, fedor.sergeev, jrtc27, kristof.beyls, paulsemel, llvm-commits
Differential Revision: https://reviews.llvm.org/D50343
llvm-svn: 340070
2018-08-17 18:51:11 +00:00
|
|
|
|
2021-03-12 01:31:06 +03:00
|
|
|
if (Archive *Ar = dyn_cast<Archive>(BinaryHolder.getBinary())) {
|
|
|
|
// Handle Archive.
|
2021-04-23 14:19:11 +03:00
|
|
|
if (Error E = executeObjcopyOnArchive(ConfigMgr, *Ar))
|
2019-02-21 17:05:19 +00:00
|
|
|
return E;
|
[llvm-objcopy] Add support for -I binary -B <arch>.
Summary:
The -I (--input-target) and -B (--binary-architecture) flags exist but are currently silently ignored. This adds support for -I binary for architectures i386, x86-64 (and alias i386:x86-64), arm, aarch64, sparc, and ppc (powerpc:common64). This is largely based on D41687.
This is done by implementing an additional subclass of Reader, BinaryReader, which works by interpreting the input file as contents for .data field, sets up a synthetic header, and adds additional sections/symbols (e.g. _binary__tmp_data_txt_start).
Reviewers: jakehehrlich, alexshap, jhenderson, javed.absar
Reviewed By: jhenderson
Subscribers: jyknight, nemanjai, kbarton, fedor.sergeev, jrtc27, kristof.beyls, paulsemel, llvm-commits
Differential Revision: https://reviews.llvm.org/D50343
llvm-svn: 340070
2018-08-17 18:51:11 +00:00
|
|
|
} else {
|
2021-03-12 01:31:06 +03:00
|
|
|
// Handle llvm::object::Binary.
|
|
|
|
ObjcopyFunc = [&](raw_ostream &OutFile) -> Error {
|
2021-04-23 14:19:11 +03:00
|
|
|
return executeObjcopyOnBinary(ConfigMgr, *BinaryHolder.getBinary(),
|
2021-03-12 01:31:06 +03:00
|
|
|
OutFile);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ObjcopyFunc) {
|
|
|
|
if (Config.SplitDWO.empty()) {
|
|
|
|
// Apply transformations described by Config and store result into
|
|
|
|
// Config.OutputFilename using specified ObjcopyFunc function.
|
2021-03-04 12:51:30 +03:00
|
|
|
if (Error E = writeToOutput(Config.OutputFilename, ObjcopyFunc))
|
2021-03-12 01:31:06 +03:00
|
|
|
return E;
|
|
|
|
} else {
|
|
|
|
Config.ExtractDWO = true;
|
|
|
|
Config.StripDWO = false;
|
|
|
|
// Copy .dwo tables from the Config.InputFilename into Config.SplitDWO
|
|
|
|
// file using specified ObjcopyFunc function.
|
2021-03-04 12:51:30 +03:00
|
|
|
if (Error E = writeToOutput(Config.SplitDWO, ObjcopyFunc))
|
2021-03-12 01:31:06 +03:00
|
|
|
return E;
|
|
|
|
Config.ExtractDWO = false;
|
|
|
|
Config.StripDWO = true;
|
|
|
|
// Apply transformations described by Config, remove .dwo tables and
|
|
|
|
// store result into Config.OutputFilename using specified ObjcopyFunc
|
|
|
|
// function.
|
2021-03-04 12:51:30 +03:00
|
|
|
if (Error E = writeToOutput(Config.OutputFilename, ObjcopyFunc))
|
2019-02-21 17:05:19 +00:00
|
|
|
return E;
|
[llvm-objcopy] Add support for -I binary -B <arch>.
Summary:
The -I (--input-target) and -B (--binary-architecture) flags exist but are currently silently ignored. This adds support for -I binary for architectures i386, x86-64 (and alias i386:x86-64), arm, aarch64, sparc, and ppc (powerpc:common64). This is largely based on D41687.
This is done by implementing an additional subclass of Reader, BinaryReader, which works by interpreting the input file as contents for .data field, sets up a synthetic header, and adds additional sections/symbols (e.g. _binary__tmp_data_txt_start).
Reviewers: jakehehrlich, alexshap, jhenderson, javed.absar
Reviewed By: jhenderson
Subscribers: jyknight, nemanjai, kbarton, fedor.sergeev, jrtc27, kristof.beyls, paulsemel, llvm-commits
Differential Revision: https://reviews.llvm.org/D50343
llvm-svn: 340070
2018-08-17 18:51:11 +00:00
|
|
|
}
|
2018-08-16 18:29:40 +00:00
|
|
|
}
|
2018-07-06 17:51:03 +00:00
|
|
|
|
2022-04-13 23:40:27 +03:00
|
|
|
if (Error E =
|
2022-04-26 12:45:28 +03:00
|
|
|
PermsApplierOrErr->apply(Config.OutputFilename, Config.PreserveDates))
|
[llvm-objcopy] Change handling of output file permissions
Summary: Address bug [[ https://bugs.llvm.org/show_bug.cgi?id=42082 | 42082 ]] where files were always outputted with 0775 permissions. Now, the output file is given either 0666 or 0777 if the object is executable.
Reviewers: espindola, alexshap, rupprecht, jhenderson, jakehehrlich, MaskRay
Reviewed By: rupprecht, jhenderson, jakehehrlich, MaskRay
Subscribers: emaste, arichardson, jakehehrlich, MaskRay, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D62718
llvm-svn: 365162
2019-07-04 22:45:27 +00:00
|
|
|
return E;
|
|
|
|
|
2022-04-13 23:40:27 +03:00
|
|
|
if (!Config.SplitDWO.empty())
|
2022-04-26 12:45:28 +03:00
|
|
|
if (Error E =
|
|
|
|
PermsApplierOrErr->apply(Config.SplitDWO, Config.PreserveDates,
|
|
|
|
static_cast<sys::fs::perms>(0666)))
|
2019-02-21 17:05:19 +00:00
|
|
|
return E;
|
|
|
|
|
|
|
|
return Error::success();
|
2018-07-06 17:51:03 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 04:25:55 +00:00
|
|
|
int llvm_objcopy_main(int argc, char **argv) {
|
2018-04-13 18:26:06 +00:00
|
|
|
InitLLVM X(argc, argv);
|
2017-08-01 00:33:58 +00:00
|
|
|
ToolName = argv[0];
|
2020-03-21 23:39:01 -07:00
|
|
|
|
2019-09-14 01:14:43 +00:00
|
|
|
// Expand response files.
|
|
|
|
// TODO: Move these lines, which are copied from lib/Support/CommandLine.cpp,
|
|
|
|
// into a separate function in the CommandLine library and call that function
|
|
|
|
// here. This is duplicated code.
|
|
|
|
SmallVector<const char *, 20> NewArgv(argv, argv + argc);
|
|
|
|
BumpPtrAllocator A;
|
|
|
|
StringSaver Saver(A);
|
|
|
|
cl::ExpandResponseFiles(Saver,
|
|
|
|
Triple(sys::getProcessTriple()).isOSWindows()
|
|
|
|
? cl::TokenizeWindowsCommandLine
|
|
|
|
: cl::TokenizeGNUCommandLine,
|
|
|
|
NewArgv);
|
|
|
|
|
2023-01-04 08:28:45 +01:00
|
|
|
auto Args = ArrayRef(NewArgv).drop_front();
|
2020-10-22 23:13:49 -07:00
|
|
|
Expected<DriverConfig> DriverConfig = getDriverConfig(Args);
|
|
|
|
|
2019-02-21 17:05:19 +00:00
|
|
|
if (!DriverConfig) {
|
|
|
|
logAllUnhandledErrors(DriverConfig.takeError(),
|
|
|
|
WithColor::error(errs(), ToolName));
|
|
|
|
return 1;
|
|
|
|
}
|
2021-04-23 14:19:11 +03:00
|
|
|
for (ConfigManager &ConfigMgr : DriverConfig->CopyConfigs) {
|
|
|
|
if (Error E = executeObjcopy(ConfigMgr)) {
|
2019-02-21 17:05:19 +00:00
|
|
|
logAllUnhandledErrors(std::move(E), WithColor::error(errs(), ToolName));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2017-08-01 00:33:58 +00:00
|
|
|
}
|