Index: llvm/trunk/docs/CommandGuide/llvm-objcopy.rst =================================================================== --- llvm/trunk/docs/CommandGuide/llvm-objcopy.rst +++ llvm/trunk/docs/CommandGuide/llvm-objcopy.rst @@ -43,6 +43,10 @@ starts with ".note". Otherwise, it will have type `SHT_PROGBITS`. Can be specified multiple times to add multiple sections. +.. option:: --binary-architecture , -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 @@ 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 , -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 Set the directory used by :option:`--build-id-link-input` and Index: llvm/trunk/test/tools/llvm-objcopy/ELF/binary-input-error.test =================================================================== --- llvm/trunk/test/tools/llvm-objcopy/ELF/binary-input-error.test +++ llvm/trunk/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 Index: llvm/trunk/tools/llvm-objcopy/CopyConfig.h =================================================================== --- llvm/trunk/tools/llvm-objcopy/CopyConfig.h +++ llvm/trunk/tools/llvm-objcopy/CopyConfig.h @@ -128,8 +128,6 @@ StringRef OutputFilename; FileFormat OutputFormat; - // Only applicable for --input-format=binary - MachineInfo BinaryArch; // Only applicable when --output-format!=binary (e.g. elf64-x86-64). Optional OutputArch; Index: llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp =================================================================== --- llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp +++ llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp @@ -258,29 +258,6 @@ return SI; } -static const StringMap 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 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 @@ .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 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; Index: llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp =================================================================== --- llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp +++ llvm/trunk/tools/llvm-objcopy/ELF/ELFObjcopy.cpp @@ -737,7 +737,7 @@ IHexReader Reader(&In); std::unique_ptr 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 @@ 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 Obj = Reader.create(); // Prefer OutputArch (-O) if set, otherwise fallback to BinaryArch // (-B). 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); Index: llvm/trunk/tools/llvm-objcopy/ELF/Object.h =================================================================== --- llvm/trunk/tools/llvm-objcopy/ELF/Object.h +++ llvm/trunk/tools/llvm-objcopy/ELF/Object.h @@ -873,7 +873,6 @@ class BasicELFBuilder { protected: - uint16_t EMachine; std::unique_ptr Obj; void initFileHeader(); @@ -883,8 +882,7 @@ void initSections(); public: - BasicELFBuilder(uint16_t EM) - : EMachine(EM), Obj(std::make_unique()) {} + BasicELFBuilder() : Obj(std::make_unique()) {} }; class BinaryELFBuilder : public BasicELFBuilder { @@ -893,8 +891,8 @@ 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 build(); @@ -907,7 +905,7 @@ public: IHexELFBuilder(const std::vector &Records) - : BasicELFBuilder(ELF::EM_386), Records(Records) {} + : BasicELFBuilder(), Records(Records) {} std::unique_ptr build(); }; @@ -942,14 +940,12 @@ }; 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 create() const override; }; Index: llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp =================================================================== --- llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp +++ llvm/trunk/tools/llvm-objcopy/ELF/Object.cpp @@ -1112,7 +1112,7 @@ Obj->OSABI = ELFOSABI_NONE; Obj->ABIVersion = 0; Obj->Entry = 0x0; - Obj->Machine = EMachine; + Obj->Machine = EM_NONE; Obj->Version = 1; } @@ -1606,7 +1606,7 @@ Reader::~Reader() {} std::unique_ptr BinaryReader::create() const { - return BinaryELFBuilder(MInfo.EMachine, MemBuf, NewSymbolVisibility).build(); + return BinaryELFBuilder(MemBuf, NewSymbolVisibility).build(); } Expected> IHexReader::parse() const { Index: llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td =================================================================== --- llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td +++ llvm/trunk/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, HelpText<"Alias for --binary-architecture">;