2017-11-02 05:16:06 +08:00
|
|
|
//===- llvm-objcopy.cpp ---------------------------------------------------===//
|
2017-08-01 08:33:58 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08: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 08:33:58 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2017-11-02 05:16:06 +08:00
|
|
|
|
2017-08-01 08:33:58 +08:00
|
|
|
#include "llvm-objcopy.h"
|
2018-10-16 13:40:18 +08:00
|
|
|
#include "Buffer.h"
|
2018-12-19 15:24:38 +08:00
|
|
|
#include "COFF/COFFObjcopy.h"
|
2018-10-12 06:33:50 +08:00
|
|
|
#include "CopyConfig.h"
|
2018-10-30 05:22:58 +08:00
|
|
|
#include "ELF/ELFObjcopy.h"
|
2019-02-02 08:38:07 +08:00
|
|
|
#include "MachO/MachOObjcopy.h"
|
2018-10-12 06:33:50 +08:00
|
|
|
|
2017-11-02 05:16:06 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2018-08-02 00:23:22 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2017-11-02 05:16:06 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
2018-07-07 01:51:03 +08:00
|
|
|
#include "llvm/Object/Archive.h"
|
|
|
|
#include "llvm/Object/ArchiveWriter.h"
|
2017-11-02 05:16:06 +08:00
|
|
|
#include "llvm/Object/Binary.h"
|
2018-12-19 15:24:38 +08:00
|
|
|
#include "llvm/Object/COFF.h"
|
2017-11-02 05:16:06 +08:00
|
|
|
#include "llvm/Object/ELFObjectFile.h"
|
|
|
|
#include "llvm/Object/ELFTypes.h"
|
|
|
|
#include "llvm/Object/Error.h"
|
2019-02-02 08:38:07 +08:00
|
|
|
#include "llvm/Object/MachO.h"
|
2018-04-24 13:43:32 +08:00
|
|
|
#include "llvm/Option/Arg.h"
|
|
|
|
#include "llvm/Option/ArgList.h"
|
|
|
|
#include "llvm/Option/Option.h"
|
2017-11-02 05:16:06 +08:00
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/Error.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/ErrorOr.h"
|
2018-04-14 02:26:06 +08: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-18 02:51:11 +08:00
|
|
|
#include "llvm/Support/Memory.h"
|
2018-05-08 03:32:09 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2018-08-17 02:29:40 +08:00
|
|
|
#include "llvm/Support/Process.h"
|
2018-08-10 06:52:03 +08:00
|
|
|
#include "llvm/Support/WithColor.h"
|
2017-11-02 05:16:06 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdlib>
|
2017-08-01 08:33:58 +08:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <system_error>
|
2017-11-02 05:16:06 +08:00
|
|
|
#include <utility>
|
2017-08-01 08:33:58 +08:00
|
|
|
|
2018-07-18 08:10:51 +08:00
|
|
|
namespace llvm {
|
|
|
|
namespace objcopy {
|
|
|
|
|
|
|
|
// The name this program was invoked as.
|
|
|
|
StringRef ToolName;
|
|
|
|
|
2019-02-08 18:33:16 +08:00
|
|
|
Error createError(StringRef File, std::error_code EC) {
|
|
|
|
assert(EC);
|
|
|
|
return createFileError(File, make_error<StringError>(EC));
|
|
|
|
}
|
|
|
|
|
2018-07-18 08:10:51 +08:00
|
|
|
LLVM_ATTRIBUTE_NORETURN void error(Twine Message) {
|
2018-08-10 06:52:03 +08:00
|
|
|
WithColor::error(errs(), ToolName) << Message << ".\n";
|
2018-07-18 08:10:51 +08:00
|
|
|
errs().flush();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
[llvm-objcopy] Return Error from Buffer::allocate(), [ELF]Writer::finalize(), and [ELF]Writer::commit()
Summary:
This patch changes a few methods to return Error instead of manually calling error/reportError to abort. This will make it easier to extract into a library.
Note that error() takes just a string (this patch also adds an overload that takes an Error), while reportError() takes string + [error/code]. To help unify things, use FileError to associate a given filename with an error. Note that this takes some special care (for now), e.g. calling reportError(FileName, <something that could be FileError>) will duplicate the filename. The goal is to eventually remove reportError() and have every error associated with a file to be a FileError, and just one error handling block at the tool level.
This change was suggested in D56806. I took it a little further than suggested, but completely fixing llvm-objcopy will take a couple more patches. If this approach looks good, I'll commit this and apply similar patche(s) for the rest.
This change is NFC in terms of non-error related code, although the error message changes in one context.
Reviewers: alexshap, jhenderson, jakehehrlich, mstorsjo, espindola
Reviewed By: alexshap, jhenderson
Subscribers: llvm-commits, emaste, arichardson
Differential Revision: https://reviews.llvm.org/D56930
llvm-svn: 351896
2019-01-23 07:49:16 +08:00
|
|
|
LLVM_ATTRIBUTE_NORETURN void error(Error E) {
|
|
|
|
assert(E);
|
|
|
|
std::string Buf;
|
|
|
|
raw_string_ostream OS(Buf);
|
|
|
|
logAllUnhandledErrors(std::move(E), OS);
|
|
|
|
OS.flush();
|
|
|
|
WithColor::error(errs(), ToolName) << Buf;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2018-07-18 08:10:51 +08:00
|
|
|
LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, std::error_code EC) {
|
2019-02-08 18:33:16 +08:00
|
|
|
error(createError(File, EC));
|
2018-07-18 08:10:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, Error E) {
|
|
|
|
assert(E);
|
|
|
|
std::string Buf;
|
|
|
|
raw_string_ostream OS(Buf);
|
2018-11-11 09:46:03 +08:00
|
|
|
logAllUnhandledErrors(std::move(E), OS);
|
2018-07-18 08:10:51 +08:00
|
|
|
OS.flush();
|
2018-08-10 06:52:03 +08:00
|
|
|
WithColor::error(errs(), ToolName) << "'" << File << "': " << Buf;
|
2018-07-18 08:10:51 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace objcopy
|
2018-10-25 06:49:06 +08:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::object;
|
|
|
|
using namespace llvm::objcopy;
|
|
|
|
|
2018-07-07 01:51:03 +08:00
|
|
|
// For regular archives this function simply calls llvm::writeArchive,
|
|
|
|
// For thin archives it writes the archive file itself as well as its members.
|
2018-07-17 06:17:05 +08:00
|
|
|
static Error deepWriteArchive(StringRef ArcName,
|
|
|
|
ArrayRef<NewArchiveMember> NewMembers,
|
|
|
|
bool WriteSymtab, object::Archive::Kind Kind,
|
|
|
|
bool Deterministic, bool Thin) {
|
2019-02-02 01:08:07 +08:00
|
|
|
if (Error E = writeArchive(ArcName, NewMembers, WriteSymtab, Kind,
|
|
|
|
Deterministic, Thin))
|
|
|
|
return createFileError(ArcName, std::move(E));
|
|
|
|
|
|
|
|
if (!Thin)
|
|
|
|
return Error::success();
|
|
|
|
|
2018-07-07 01:51:03 +08:00
|
|
|
for (const NewArchiveMember &Member : NewMembers) {
|
|
|
|
// Internally, FileBuffer will use the buffer created by
|
|
|
|
// FileOutputBuffer::create, for regular files (that is the case for
|
|
|
|
// deepWriteArchive) FileOutputBuffer::create will return OnDiskBuffer.
|
|
|
|
// OnDiskBuffer uses a temporary file and then renames it. So in reality
|
|
|
|
// there is no inefficiency / duplicated in-memory buffers in this case. For
|
|
|
|
// now in-memory buffers can not be completely avoided since
|
|
|
|
// NewArchiveMember still requires them even though writeArchive does not
|
|
|
|
// write them on disk.
|
|
|
|
FileBuffer FB(Member.MemberName);
|
[llvm-objcopy] Return Error from Buffer::allocate(), [ELF]Writer::finalize(), and [ELF]Writer::commit()
Summary:
This patch changes a few methods to return Error instead of manually calling error/reportError to abort. This will make it easier to extract into a library.
Note that error() takes just a string (this patch also adds an overload that takes an Error), while reportError() takes string + [error/code]. To help unify things, use FileError to associate a given filename with an error. Note that this takes some special care (for now), e.g. calling reportError(FileName, <something that could be FileError>) will duplicate the filename. The goal is to eventually remove reportError() and have every error associated with a file to be a FileError, and just one error handling block at the tool level.
This change was suggested in D56806. I took it a little further than suggested, but completely fixing llvm-objcopy will take a couple more patches. If this approach looks good, I'll commit this and apply similar patche(s) for the rest.
This change is NFC in terms of non-error related code, although the error message changes in one context.
Reviewers: alexshap, jhenderson, jakehehrlich, mstorsjo, espindola
Reviewed By: alexshap, jhenderson
Subscribers: llvm-commits, emaste, arichardson
Differential Revision: https://reviews.llvm.org/D56930
llvm-svn: 351896
2019-01-23 07:49:16 +08:00
|
|
|
if (Error E = FB.allocate(Member.Buf->getBufferSize()))
|
|
|
|
return E;
|
2018-07-07 01:51:03 +08:00
|
|
|
std::copy(Member.Buf->getBufferStart(), Member.Buf->getBufferEnd(),
|
|
|
|
FB.getBufferStart());
|
[llvm-objcopy] Return Error from Buffer::allocate(), [ELF]Writer::finalize(), and [ELF]Writer::commit()
Summary:
This patch changes a few methods to return Error instead of manually calling error/reportError to abort. This will make it easier to extract into a library.
Note that error() takes just a string (this patch also adds an overload that takes an Error), while reportError() takes string + [error/code]. To help unify things, use FileError to associate a given filename with an error. Note that this takes some special care (for now), e.g. calling reportError(FileName, <something that could be FileError>) will duplicate the filename. The goal is to eventually remove reportError() and have every error associated with a file to be a FileError, and just one error handling block at the tool level.
This change was suggested in D56806. I took it a little further than suggested, but completely fixing llvm-objcopy will take a couple more patches. If this approach looks good, I'll commit this and apply similar patche(s) for the rest.
This change is NFC in terms of non-error related code, although the error message changes in one context.
Reviewers: alexshap, jhenderson, jakehehrlich, mstorsjo, espindola
Reviewed By: alexshap, jhenderson
Subscribers: llvm-commits, emaste, arichardson
Differential Revision: https://reviews.llvm.org/D56930
llvm-svn: 351896
2019-01-23 07:49:16 +08:00
|
|
|
if (Error E = FB.commit())
|
2018-07-07 01:51:03 +08:00
|
|
|
return E;
|
|
|
|
}
|
|
|
|
return Error::success();
|
|
|
|
}
|
|
|
|
|
2018-10-25 06:49:06 +08:00
|
|
|
/// The function executeObjcopyOnRawBinary does the dispatch based on the format
|
|
|
|
/// of the output specified by the command line options.
|
2019-01-30 22:36:53 +08:00
|
|
|
static Error executeObjcopyOnRawBinary(const CopyConfig &Config,
|
|
|
|
MemoryBuffer &In, Buffer &Out) {
|
2018-10-25 06:49:06 +08:00
|
|
|
// TODO: llvm-objcopy should parse CopyConfig.OutputFormat to recognize
|
|
|
|
// formats other than ELF / "binary" and invoke
|
|
|
|
// elf::executeObjcopyOnRawBinary, macho::executeObjcopyOnRawBinary or
|
|
|
|
// coff::executeObjcopyOnRawBinary accordingly.
|
|
|
|
return elf::executeObjcopyOnRawBinary(Config, In, Out);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The function executeObjcopyOnBinary does the dispatch based on the format
|
|
|
|
/// of the input binary (ELF, MachO or COFF).
|
2019-01-30 22:36:53 +08:00
|
|
|
static Error executeObjcopyOnBinary(const CopyConfig &Config,
|
|
|
|
object::Binary &In, Buffer &Out) {
|
2018-10-25 06:49:06 +08:00
|
|
|
if (auto *ELFBinary = dyn_cast<object::ELFObjectFileBase>(&In))
|
|
|
|
return elf::executeObjcopyOnBinary(Config, *ELFBinary, Out);
|
2018-12-19 15:24:38 +08:00
|
|
|
else if (auto *COFFBinary = dyn_cast<object::COFFObjectFile>(&In))
|
|
|
|
return coff::executeObjcopyOnBinary(Config, *COFFBinary, Out);
|
2019-02-02 08:38:07 +08:00
|
|
|
else if (auto *MachOBinary = dyn_cast<object::MachOObjectFile>(&In))
|
|
|
|
return macho::executeObjcopyOnBinary(Config, *MachOBinary, Out);
|
2018-10-25 06:49:06 +08:00
|
|
|
else
|
2019-01-30 22:36:53 +08:00
|
|
|
return createStringError(object_error::invalid_file_type,
|
|
|
|
"Unsupported object file format");
|
2018-10-25 06:49:06 +08:00
|
|
|
}
|
|
|
|
|
2019-01-30 22:36:53 +08:00
|
|
|
static Error executeObjcopyOnArchive(const CopyConfig &Config,
|
|
|
|
const Archive &Ar) {
|
2018-07-07 01:51:03 +08:00
|
|
|
std::vector<NewArchiveMember> NewArchiveMembers;
|
|
|
|
Error Err = Error::success();
|
|
|
|
for (const Archive::Child &Child : Ar.children(Err)) {
|
|
|
|
Expected<std::unique_ptr<Binary>> ChildOrErr = Child.getAsBinary();
|
|
|
|
if (!ChildOrErr)
|
2019-02-02 01:08:07 +08:00
|
|
|
return createFileError(Ar.getFileName(), ChildOrErr.takeError());
|
[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-18 02:51:11 +08:00
|
|
|
Binary *Bin = ChildOrErr->get();
|
|
|
|
|
2018-07-07 01:51:03 +08:00
|
|
|
Expected<StringRef> ChildNameOrErr = Child.getName();
|
|
|
|
if (!ChildNameOrErr)
|
2019-02-02 01:08:07 +08:00
|
|
|
return createFileError(Ar.getFileName(), ChildNameOrErr.takeError());
|
2018-07-07 01:51:03 +08:00
|
|
|
|
|
|
|
MemBuffer MB(ChildNameOrErr.get());
|
2019-01-30 22:36:53 +08:00
|
|
|
if (Error E = executeObjcopyOnBinary(Config, *Bin, MB))
|
|
|
|
return E;
|
2018-07-07 01:51:03 +08:00
|
|
|
|
|
|
|
Expected<NewArchiveMember> Member =
|
2018-11-02 01:36:37 +08:00
|
|
|
NewArchiveMember::getOldMember(Child, Config.DeterministicArchives);
|
2018-07-07 01:51:03 +08:00
|
|
|
if (!Member)
|
2019-02-02 01:08:07 +08:00
|
|
|
return createFileError(Ar.getFileName(), Member.takeError());
|
2018-07-07 01:51:03 +08:00
|
|
|
Member->Buf = MB.releaseMemoryBuffer();
|
|
|
|
Member->MemberName = Member->Buf->getBufferIdentifier();
|
|
|
|
NewArchiveMembers.push_back(std::move(*Member));
|
|
|
|
}
|
|
|
|
if (Err)
|
2019-02-02 01:08:07 +08:00
|
|
|
return createFileError(Config.InputFilename, std::move(Err));
|
|
|
|
|
|
|
|
return deepWriteArchive(Config.OutputFilename, NewArchiveMembers,
|
|
|
|
Ar.hasSymbolTable(), Ar.kind(),
|
|
|
|
Config.DeterministicArchives, Ar.isThin());
|
2018-07-07 01:51:03 +08:00
|
|
|
}
|
|
|
|
|
2018-08-17 02:29:40 +08:00
|
|
|
static void restoreDateOnFile(StringRef Filename,
|
|
|
|
const sys::fs::file_status &Stat) {
|
|
|
|
int FD;
|
|
|
|
|
2018-08-30 07:21:56 +08:00
|
|
|
if (auto EC =
|
|
|
|
sys::fs::openFileForWrite(Filename, FD, sys::fs::CD_OpenExisting))
|
2018-08-17 02:29:40 +08:00
|
|
|
reportError(Filename, EC);
|
|
|
|
|
|
|
|
if (auto EC = sys::fs::setLastAccessAndModificationTime(
|
|
|
|
FD, Stat.getLastAccessedTime(), Stat.getLastModificationTime()))
|
|
|
|
reportError(Filename, EC);
|
|
|
|
|
|
|
|
if (auto EC = sys::Process::SafelyCloseFileDescriptor(FD))
|
|
|
|
reportError(Filename, EC);
|
|
|
|
}
|
|
|
|
|
2018-10-25 06:49:06 +08: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.
|
|
|
|
static void executeObjcopy(const CopyConfig &Config) {
|
2018-08-17 02:29:40 +08:00
|
|
|
sys::fs::file_status Stat;
|
|
|
|
if (Config.PreserveDates)
|
|
|
|
if (auto EC = sys::fs::status(Config.InputFilename, Stat))
|
|
|
|
reportError(Config.InputFilename, EC);
|
|
|
|
|
[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-18 02:51:11 +08:00
|
|
|
if (Config.InputFormat == "binary") {
|
|
|
|
auto BufOrErr = MemoryBuffer::getFile(Config.InputFilename);
|
|
|
|
if (!BufOrErr)
|
|
|
|
reportError(Config.InputFilename, BufOrErr.getError());
|
2018-08-17 02:29:40 +08:00
|
|
|
FileBuffer FB(Config.OutputFilename);
|
2019-01-30 22:36:53 +08:00
|
|
|
if (Error E = executeObjcopyOnRawBinary(Config, *BufOrErr->get(), FB))
|
|
|
|
error(std::move(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-18 02:51:11 +08:00
|
|
|
} else {
|
|
|
|
Expected<OwningBinary<llvm::object::Binary>> BinaryOrErr =
|
|
|
|
createBinary(Config.InputFilename);
|
|
|
|
if (!BinaryOrErr)
|
|
|
|
reportError(Config.InputFilename, BinaryOrErr.takeError());
|
|
|
|
|
|
|
|
if (Archive *Ar = dyn_cast<Archive>(BinaryOrErr.get().getBinary())) {
|
2019-01-30 22:36:53 +08:00
|
|
|
if (Error E = executeObjcopyOnArchive(Config, *Ar))
|
|
|
|
error(std::move(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-18 02:51:11 +08:00
|
|
|
} else {
|
|
|
|
FileBuffer FB(Config.OutputFilename);
|
2019-01-30 22:36:53 +08:00
|
|
|
if (Error E = executeObjcopyOnBinary(Config,
|
|
|
|
*BinaryOrErr.get().getBinary(), FB))
|
|
|
|
error(std::move(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-18 02:51:11 +08:00
|
|
|
}
|
2018-08-17 02:29:40 +08:00
|
|
|
}
|
2018-07-07 01:51:03 +08:00
|
|
|
|
2018-08-17 02:29:40 +08:00
|
|
|
if (Config.PreserveDates) {
|
|
|
|
restoreDateOnFile(Config.OutputFilename, Stat);
|
|
|
|
if (!Config.SplitDWO.empty())
|
|
|
|
restoreDateOnFile(Config.SplitDWO, Stat);
|
|
|
|
}
|
2018-07-07 01:51:03 +08:00
|
|
|
}
|
|
|
|
|
2017-08-01 08:33:58 +08:00
|
|
|
int main(int argc, char **argv) {
|
2018-04-14 02:26:06 +08:00
|
|
|
InitLLVM X(argc, argv);
|
2017-08-01 08:33:58 +08:00
|
|
|
ToolName = argv[0];
|
2018-09-05 21:10:03 +08:00
|
|
|
DriverConfig DriverConfig;
|
2018-11-07 11:02:11 +08:00
|
|
|
if (sys::path::stem(ToolName).contains("strip"))
|
2018-09-05 21:10:03 +08:00
|
|
|
DriverConfig = parseStripOptions(makeArrayRef(argv + 1, argc));
|
2018-05-08 03:32:09 +08:00
|
|
|
else
|
2018-09-05 21:10:03 +08:00
|
|
|
DriverConfig = parseObjcopyOptions(makeArrayRef(argv + 1, argc));
|
|
|
|
for (const CopyConfig &CopyConfig : DriverConfig.CopyConfigs)
|
2018-10-25 06:49:06 +08:00
|
|
|
executeObjcopy(CopyConfig);
|
2017-08-01 08:33:58 +08:00
|
|
|
}
|