[PATCH] D53029: [llvm-objcopy] Add -F|--target compatibility

Jordan Rupprecht via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 11 17:37:52 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL344321: [llvm-objcopy] Add -F|--target compatibility (authored by rupprecht, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D53029

Files:
  llvm/trunk/test/tools/llvm-objcopy/input-output-target.test
  llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp
  llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td


Index: llvm/trunk/test/tools/llvm-objcopy/input-output-target.test
===================================================================
--- llvm/trunk/test/tools/llvm-objcopy/input-output-target.test
+++ llvm/trunk/test/tools/llvm-objcopy/input-output-target.test
@@ -0,0 +1,22 @@
+# RUN: echo abcd > %t.txt
+
+# Preserve input to verify it is not modified
+# RUN: cp %t.txt %t-copy.txt
+
+# -F <target> is equivalent to -I <target> -O <target>
+# RUN: llvm-objcopy -F binary -B i386:x86-64 %t.txt %t.2.txt
+# RUN: cmp %t-copy.txt %t.2.txt
+
+# --target <target> is equivalent to --input-target <target> --output-target <target>
+# RUN: llvm-objcopy --target binary -B i386:x86-64 %t.txt %t.3.txt
+# RUN: cmp %t-copy.txt %t.3.txt
+
+# TODO: check --target and --input-target/--output-target are incompatible
+# RUN: not llvm-objcopy --target binary --input-target binary -B i386:x86-64 \
+# RUN:     %t.txt %t.4.txt 2>&1 \
+# RUN:     | FileCheck %s --check-prefix=BAD-FLAG
+# RUN: not llvm-objcopy --target binary --output-target binary -B i386:x86-64 \
+# RUN:     %t.txt %t.4.txt 2>&1 \
+# RUN:     | FileCheck %s --check-prefix=BAD-FLAG
+
+# BAD-FLAG: --target cannot be used with --input-target or --output-target.
Index: llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td
===================================================================
--- llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td
+++ llvm/trunk/tools/llvm-objcopy/ObjcopyOpts.td
@@ -10,6 +10,10 @@
                            HelpText<"Used when transforming an architecture-less format (such as binary) to another format">;
 def B : JoinedOrSeparate<["-"], "B">,
         Alias<binary_architecture>;
+defm target : Eq<"target">,
+              HelpText<"Format of the input and output file">,
+              Values<"binary">;
+def F : JoinedOrSeparate<[ "-" ], "F">, Alias<target>;
 defm input_target : Eq<"input-target">,
                     HelpText<"Format of the input file">,
                     Values<"binary">;
Index: llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp
===================================================================
--- llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp
+++ llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp
@@ -247,8 +247,18 @@
   CopyConfig Config;
   Config.InputFilename = Positional[0];
   Config.OutputFilename = Positional[Positional.size() == 1 ? 0 : 1];
-  Config.InputFormat = InputArgs.getLastArgValue(OBJCOPY_input_target);
-  Config.OutputFormat = InputArgs.getLastArgValue(OBJCOPY_output_target);
+  if (InputArgs.hasArg(OBJCOPY_target) &&
+      (InputArgs.hasArg(OBJCOPY_input_target) ||
+       InputArgs.hasArg(OBJCOPY_output_target)))
+    error("--target cannot be used with --input-target or --output-target");
+
+  if (InputArgs.hasArg(OBJCOPY_target)) {
+    Config.InputFormat = InputArgs.getLastArgValue(OBJCOPY_target);
+    Config.OutputFormat = InputArgs.getLastArgValue(OBJCOPY_target);
+  } else {
+    Config.InputFormat = InputArgs.getLastArgValue(OBJCOPY_input_target);
+    Config.OutputFormat = InputArgs.getLastArgValue(OBJCOPY_output_target);
+  }
   if (Config.InputFormat == "binary") {
     auto BinaryArch = InputArgs.getLastArgValue(OBJCOPY_binary_architecture);
     if (BinaryArch.empty())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53029.169344.patch
Type: text/x-patch
Size: 3224 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181012/142c323b/attachment.bin>


More information about the llvm-commits mailing list