summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2019-09-14 01:36:31 +0000
committerFangrui Song <maskray@google.com>2019-09-14 01:36:31 +0000
commit2f519d7072bf48a81985fadc2dc145296d612223 (patch)
tree8d0ca4b9f00f4d5b80e4023592951eeb3da84d39
parentba53030dd0938902dd858f7eac45732295e74120 (diff)
downloadbcm5719-llvm-2f519d7072bf48a81985fadc2dc145296d612223.tar.gz
bcm5719-llvm-2f519d7072bf48a81985fadc2dc145296d612223.zip
[llvm-objcopy] Ignore -B --binary-architecture=
GNU objcopy documents that -B is only useful with architecture-less input (i.e. "binary" or "ihex"). After D67144, -O defaults to -I, and -B is essentially a NOP. * If -O is binary/ihex, GNU objcopy ignores -B. * If -O is elf*, -B provides the e_machine field in GNU objcopy. So to convert a blob to an ELF, `-I binary -B i386:x86-64 -O elf64-x86-64` has to be specified. `-I binary -B i386:x86-64 -O elf64-x86-64` creates an ELF with its e_machine field set to EM_NONE in GNU objcopy, but a regular x86_64 ELF in elftoolchain elfcopy. Follow the elftoolchain approach (ignoring -B) to simplify code. Users that expect their command line portable should specify -B. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D67215 llvm-svn: 371914
-rw-r--r--llvm/docs/CommandGuide/llvm-objcopy.rst21
-rw-r--r--llvm/test/tools/llvm-objcopy/ELF/binary-input-error.test6
-rw-r--r--llvm/tools/llvm-objcopy/CopyConfig.cpp32
-rw-r--r--llvm/tools/llvm-objcopy/CopyConfig.h2
-rw-r--r--llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp6
-rw-r--r--llvm/tools/llvm-objcopy/ELF/Object.cpp4
-rw-r--r--llvm/tools/llvm-objcopy/ELF/Object.h16
-rw-r--r--llvm/tools/llvm-objcopy/ObjcopyOpts.td3
8 files changed, 18 insertions, 72 deletions
diff --git a/llvm/docs/CommandGuide/llvm-objcopy.rst b/llvm/docs/CommandGuide/llvm-objcopy.rst
index 401bc5bd4bd..f3926805c44 100644
--- a/llvm/docs/CommandGuide/llvm-objcopy.rst
+++ b/llvm/docs/CommandGuide/llvm-objcopy.rst
@@ -43,6 +43,10 @@ multiple file formats.
starts with ".note". Otherwise, it will have type `SHT_PROGBITS`. Can be
specified multiple times to add multiple sections.
+.. option:: --binary-architecture <arch>, -B
+
+ Ignored for compatibility.
+
.. option:: --disable-deterministic-archives, -U
Use real values for UIDs, GIDs and timestamps when updating archive member
@@ -181,23 +185,6 @@ them.
Allow llvm-objcopy to remove sections even if it would leave invalid section
references. Any invalid sh_link fields will be set to zero.
-.. option:: --binary-architecture <arch>, -B
-
- Specify the architecture to use, when transforming an architecture-less format
- (e.g. binary) to another format. Valid options are:
-
- - `aarch64`
- - `arm`
- - `i386`
- - `i386:x86-64`
- - `mips`
- - `powerpc:common64`
- - `riscv:rv32`
- - `riscv:rv64`
- - `sparc`
- - `sparcel`
- - `x86-64`
-
.. option:: --build-id-link-dir <dir>
Set the directory used by :option:`--build-id-link-input` and
diff --git a/llvm/test/tools/llvm-objcopy/ELF/binary-input-error.test b/llvm/test/tools/llvm-objcopy/ELF/binary-input-error.test
index d0dd50a4194..40ce3edce01 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/binary-input-error.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/binary-input-error.test
@@ -1,6 +1,4 @@
# RUN: echo abcd > %t.txt
-# RUN: not llvm-objcopy -I binary -B xyz %t.txt %t.o 2>&1 \
-# RUN: | FileCheck %s --check-prefix=BAD-BINARY-ARCH
-
-# BAD-BINARY-ARCH: invalid architecture: 'xyz'
+## -B is ignored.
+# RUN: llvm-objcopy -I binary -B xyz %t.txt %t.o
diff --git a/llvm/tools/llvm-objcopy/CopyConfig.cpp b/llvm/tools/llvm-objcopy/CopyConfig.cpp
index 73e9221a476..a84114eb267 100644
--- a/llvm/tools/llvm-objcopy/CopyConfig.cpp
+++ b/llvm/tools/llvm-objcopy/CopyConfig.cpp
@@ -258,29 +258,6 @@ static Expected<NewSymbolInfo> parseNewSymbolInfo(StringRef FlagValue,
return SI;
}
-static const StringMap<MachineInfo> ArchMap{
- // Name, {EMachine, 64bit, LittleEndian}
- {"aarch64", {ELF::EM_AARCH64, true, true}},
- {"arm", {ELF::EM_ARM, false, true}},
- {"i386", {ELF::EM_386, false, true}},
- {"i386:x86-64", {ELF::EM_X86_64, true, true}},
- {"mips", {ELF::EM_MIPS, false, false}},
- {"powerpc:common64", {ELF::EM_PPC64, true, true}},
- {"riscv:rv32", {ELF::EM_RISCV, false, true}},
- {"riscv:rv64", {ELF::EM_RISCV, true, true}},
- {"sparc", {ELF::EM_SPARC, false, false}},
- {"sparcel", {ELF::EM_SPARC, false, true}},
- {"x86-64", {ELF::EM_X86_64, true, true}},
-};
-
-static Expected<const MachineInfo &> getMachineInfo(StringRef Arch) {
- auto Iter = ArchMap.find(Arch);
- if (Iter == std::end(ArchMap))
- return createStringError(errc::invalid_argument,
- "invalid architecture: '%s'", Arch.str().c_str());
- return Iter->getValue();
-}
-
struct TargetInfo {
FileFormat Format;
MachineInfo Machine;
@@ -489,15 +466,6 @@ Expected<DriverConfig> parseObjcopyOptions(ArrayRef<const char *> ArgsArr) {
.Case("binary", FileFormat::Binary)
.Case("ihex", FileFormat::IHex)
.Default(FileFormat::Unspecified);
- if (Config.InputFormat == FileFormat::Binary) {
- auto BinaryArch = InputArgs.getLastArgValue(OBJCOPY_binary_architecture);
- if (!BinaryArch.empty()) {
- Expected<const MachineInfo &> MI = getMachineInfo(BinaryArch);
- if (!MI)
- return MI.takeError();
- Config.BinaryArch = *MI;
- }
- }
if (opt::Arg *A = InputArgs.getLastArg(OBJCOPY_new_symbol_visibility)) {
const uint8_t Invalid = 0xff;
diff --git a/llvm/tools/llvm-objcopy/CopyConfig.h b/llvm/tools/llvm-objcopy/CopyConfig.h
index e7f293d7fc2..0b68d23a1b7 100644
--- a/llvm/tools/llvm-objcopy/CopyConfig.h
+++ b/llvm/tools/llvm-objcopy/CopyConfig.h
@@ -128,8 +128,6 @@ struct CopyConfig {
StringRef OutputFilename;
FileFormat OutputFormat;
- // Only applicable for --input-format=binary
- MachineInfo BinaryArch;
// Only applicable when --output-format!=binary (e.g. elf64-x86-64).
Optional<MachineInfo> OutputArch;
diff --git a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
index 1b1bc8e12a0..04ff92002f1 100644
--- a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
+++ b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp
@@ -737,7 +737,7 @@ Error executeObjcopyOnIHex(const CopyConfig &Config, MemoryBuffer &In,
IHexReader Reader(&In);
std::unique_ptr<Object> Obj = Reader.create();
const ElfType OutputElfType =
- getOutputElfType(Config.OutputArch.getValueOr(Config.BinaryArch));
+ getOutputElfType(Config.OutputArch.getValueOr(MachineInfo()));
if (Error E = handleArgs(Config, *Obj, Reader, OutputElfType))
return E;
return writeOutput(Config, *Obj, Out, OutputElfType);
@@ -747,13 +747,13 @@ Error executeObjcopyOnRawBinary(const CopyConfig &Config, MemoryBuffer &In,
Buffer &Out) {
uint8_t NewSymbolVisibility =
Config.NewSymbolVisibility.getValueOr((uint8_t)ELF::STV_DEFAULT);
- BinaryReader Reader(Config.BinaryArch, &In, NewSymbolVisibility);
+ BinaryReader Reader(&In, NewSymbolVisibility);
std::unique_ptr<Object> Obj = Reader.create();
// Prefer OutputArch (-O<format>) if set, otherwise fallback to BinaryArch
// (-B<arch>).
const ElfType OutputElfType =
- getOutputElfType(Config.OutputArch.getValueOr(Config.BinaryArch));
+ getOutputElfType(Config.OutputArch.getValueOr(MachineInfo()));
if (Error E = handleArgs(Config, *Obj, Reader, OutputElfType))
return E;
return writeOutput(Config, *Obj, Out, OutputElfType);
diff --git a/llvm/tools/llvm-objcopy/ELF/Object.cpp b/llvm/tools/llvm-objcopy/ELF/Object.cpp
index 3d1527cc2ae..79f10fe0c0b 100644
--- a/llvm/tools/llvm-objcopy/ELF/Object.cpp
+++ b/llvm/tools/llvm-objcopy/ELF/Object.cpp
@@ -1112,7 +1112,7 @@ void BasicELFBuilder::initFileHeader() {
Obj->OSABI = ELFOSABI_NONE;
Obj->ABIVersion = 0;
Obj->Entry = 0x0;
- Obj->Machine = EMachine;
+ Obj->Machine = EM_NONE;
Obj->Version = 1;
}
@@ -1606,7 +1606,7 @@ Writer::~Writer() {}
Reader::~Reader() {}
std::unique_ptr<Object> BinaryReader::create() const {
- return BinaryELFBuilder(MInfo.EMachine, MemBuf, NewSymbolVisibility).build();
+ return BinaryELFBuilder(MemBuf, NewSymbolVisibility).build();
}
Expected<std::vector<IHexRecord>> IHexReader::parse() const {
diff --git a/llvm/tools/llvm-objcopy/ELF/Object.h b/llvm/tools/llvm-objcopy/ELF/Object.h
index 0ff455d540f..d74b5f410af 100644
--- a/llvm/tools/llvm-objcopy/ELF/Object.h
+++ b/llvm/tools/llvm-objcopy/ELF/Object.h
@@ -873,7 +873,6 @@ using object::OwningBinary;
class BasicELFBuilder {
protected:
- uint16_t EMachine;
std::unique_ptr<Object> Obj;
void initFileHeader();
@@ -883,8 +882,7 @@ protected:
void initSections();
public:
- BasicELFBuilder(uint16_t EM)
- : EMachine(EM), Obj(std::make_unique<Object>()) {}
+ BasicELFBuilder() : Obj(std::make_unique<Object>()) {}
};
class BinaryELFBuilder : public BasicELFBuilder {
@@ -893,8 +891,8 @@ class BinaryELFBuilder : public BasicELFBuilder {
void addData(SymbolTableSection *SymTab);
public:
- BinaryELFBuilder(uint16_t EM, MemoryBuffer *MB, uint8_t NewSymbolVisibility)
- : BasicELFBuilder(EM), MemBuf(MB),
+ BinaryELFBuilder(MemoryBuffer *MB, uint8_t NewSymbolVisibility)
+ : BasicELFBuilder(), MemBuf(MB),
NewSymbolVisibility(NewSymbolVisibility) {}
std::unique_ptr<Object> build();
@@ -907,7 +905,7 @@ class IHexELFBuilder : public BasicELFBuilder {
public:
IHexELFBuilder(const std::vector<IHexRecord> &Records)
- : BasicELFBuilder(ELF::EM_386), Records(Records) {}
+ : BasicELFBuilder(), Records(Records) {}
std::unique_ptr<Object> build();
};
@@ -942,14 +940,12 @@ public:
};
class BinaryReader : public Reader {
- const MachineInfo &MInfo;
MemoryBuffer *MemBuf;
uint8_t NewSymbolVisibility;
public:
- BinaryReader(const MachineInfo &MI, MemoryBuffer *MB,
- const uint8_t NewSymbolVisibility)
- : MInfo(MI), MemBuf(MB), NewSymbolVisibility(NewSymbolVisibility) {}
+ BinaryReader(MemoryBuffer *MB, const uint8_t NewSymbolVisibility)
+ : MemBuf(MB), NewSymbolVisibility(NewSymbolVisibility) {}
std::unique_ptr<Object> create() const override;
};
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
index 55e26fc881e..87b678a8b16 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td
+++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
@@ -1,8 +1,7 @@
include "CommonOpts.td"
defm binary_architecture
- : Eq<"binary-architecture", "Used when transforming an architecture-less "
- "format (such as binary) to another format">;
+ : Eq<"binary-architecture", "Ignored for compatibility">;
def B : JoinedOrSeparate<["-"], "B">,
Alias<binary_architecture>,
HelpText<"Alias for --binary-architecture">;
OpenPOWER on IntegriCloud