[clang-tools-extra] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)

James Henderson via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 25 00:45:40 PDT 2023


================
@@ -738,6 +738,37 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr,
   if (auto Arg = InputArgs.getLastArg(OBJCOPY_extract_partition))
     Config.ExtractPartition = Arg->getValue();
 
+  if (const auto *A = InputArgs.getLastArg(OBJCOPY_gap_fill)) {
+    if (Config.OutputFormat != FileFormat::Binary)
+      return createStringError(
+          errc::invalid_argument,
+          "'--gap-fill' is only supported for binary output");
+    ErrorOr<uint64_t> Val = getAsInteger<uint64_t>(A->getValue());
+    if (!Val)
+      return createStringError(Val.getError(), "--gap-fill: bad number: %s",
+                               A->getValue());
+    uint8_t ByteVal = Val.get();
+    if (ByteVal != Val.get())
+      llvm::errs() << "warning: truncating gap-fill from 0x"
+                   << llvm::utohexstr(Val.get(), true) << " to 0x"
+                   << llvm::utohexstr(ByteVal, true) << '\n';
----------------
jh7370 wrote:

Don't print direct to `llvm::errs`. This won't follow the proper formatting style for warnings produced by tools (see what other tools do). llvm-objcopy.cpp already has a `reportWarning` method. It seems reasonable to declare that in a header file so that you can also use it here.

https://github.com/llvm/llvm-project/pull/65815


More information about the cfe-commits mailing list