[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
diff --git a/llvm/test/tools/llvm-objcopy/binary-input-and-output.test b/llvm/test/tools/llvm-objcopy/binary-input-and-output.test
new file mode 100644
index 0000000..0fc2a4bc
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/binary-input-and-output.test
@@ -0,0 +1,15 @@
+# RUN: echo abcd > %t.txt
+
+# Preserve input to verify it is not modified
+# RUN: cp %t.txt %t-copy.txt
+
+# -I binary -O binary preserves payload through in-memory representation
+# RUN: llvm-objcopy -I binary -B i386:x86-64 -O binary %t.txt %t.2.txt
+# RUN: cmp %t.txt %t.2.txt
+# RUN: cmp %t.txt %t-copy.txt
+
+# -I binary -O binary preserves payload through an intermediate object file
+# RUN: llvm-objcopy -I binary -B i386:x86-64 %t.txt %t.o
+# RUN: llvm-objcopy -O binary %t.o %t.3.txt
+# RUN: cmp %t.txt %t.3.txt
+# RUN: cmp %t.txt %t-copy.txt