[PATCH] D101697: [llvm-objcopy] --dump-section: error if '=' is missing or filename is empty

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat May 1 13:18:35 PDT 2021


MaskRay created this revision.
MaskRay added a reviewer: jhenderson.
Herald added subscribers: abrachet, emaste.
Herald added a reviewer: alexshap.
Herald added a reviewer: rupprecht.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Fix PR45416: the diagnostic when '=' is missing is misleading.
`FileOutputBuffer::create` returns successfully when the filename is empty
(opened `.tmp%%%%%%%`), but the `FileOutputBuffer::commit` will error when
renaming `.tmp%%%%%%%` to the empty name).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101697

Files:
  llvm/test/tools/llvm-objcopy/ELF/dump-section.test
  llvm/tools/llvm-objcopy/CopyConfig.cpp


Index: llvm/tools/llvm-objcopy/CopyConfig.cpp
===================================================================
--- llvm/tools/llvm-objcopy/CopyConfig.cpp
+++ llvm/tools/llvm-objcopy/CopyConfig.cpp
@@ -700,8 +700,14 @@
           "bad format for --add-section: missing file name");
     Config.AddSection.push_back(ArgValue);
   }
-  for (auto Arg : InputArgs.filtered(OBJCOPY_dump_section))
-    Config.DumpSection.push_back(Arg->getValue());
+  for (auto Arg : InputArgs.filtered(OBJCOPY_dump_section)) {
+    StringRef Value(Arg->getValue());
+    if (Value.split('=').second.empty())
+      return createStringError(
+          errc::invalid_argument,
+          "bad format for --dump-section, expected section=file");
+    Config.DumpSection.push_back(Value);
+  }
   Config.StripAll = InputArgs.hasArg(OBJCOPY_strip_all);
   Config.StripAllGNU = InputArgs.hasArg(OBJCOPY_strip_all_gnu);
   Config.StripDebug = InputArgs.hasArg(OBJCOPY_strip_debug);
Index: llvm/test/tools/llvm-objcopy/ELF/dump-section.test
===================================================================
--- llvm/test/tools/llvm-objcopy/ELF/dump-section.test
+++ llvm/test/tools/llvm-objcopy/ELF/dump-section.test
@@ -59,3 +59,8 @@
 # RUN:   FileCheck %s --check-prefix=ERR -DFILE=%t -DSECTION=.missing
 
 # ERR: error: '[[FILE]]': section '[[SECTION]]' not found
+
+# RUN: not llvm-objcopy --dump-section .text %t /dev/null 2>&1 | FileCheck %s --check-prefix=ERR2
+# RUN: not llvm-objcopy --dump-section .text= %t /dev/null 2>&1 | FileCheck %s --check-prefix=ERR2
+
+# ERR2: error: bad format for --dump-section, expected section=file


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101697.342172.patch
Type: text/x-patch
Size: 1616 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210501/c91ef43a/attachment.bin>


More information about the llvm-commits mailing list